2021-11-16 19:41:35 +01:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:MeinCantor/networking.dart';
|
2021-09-14 20:55:58 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2021-11-19 20:12:42 +01:00
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
2021-09-14 20:55:58 +02:00
|
|
|
|
2021-11-16 19:41:35 +01:00
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
class SZ extends StatelessWidget {
|
|
|
|
const SZ({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text("Schülerzeitung"),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2021-11-16 19:41:35 +01:00
|
|
|
body: FutureBuilder<http.Response>(
|
|
|
|
future: getArticles(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
int statusCode = snapshot.data!.statusCode;
|
|
|
|
if (statusCode == 200) {
|
|
|
|
String data = utf8.decode(snapshot.data!.bodyBytes);
|
|
|
|
List articles = jsonDecode(data);
|
|
|
|
List<Widget> articleTiles = [];
|
|
|
|
for (var element in articles) {
|
|
|
|
Card card = Card(
|
|
|
|
child: Column(children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
|
|
|
|
child: ListTile(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) => Article.fromData(element["title"], element["content"], element["author"], element["published_at"]).widget),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
title: Text(element["title"],
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
|
|
subtitle: Text(
|
|
|
|
element["summary"])),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
articleTiles.add(card);
|
|
|
|
}
|
|
|
|
return ListView(
|
|
|
|
children: articleTiles.reversed.toList(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return(const Center(
|
|
|
|
child: Text("Uups... Irgendwas ist schief gelaufen")
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return(const Center(
|
|
|
|
child: CircularProgressIndicator()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Article {
|
|
|
|
Widget widget;
|
|
|
|
//const Article({Key? key}) : super(key: key);
|
|
|
|
Article({required this.widget});
|
|
|
|
factory Article.fromData(String title, String content, String author, String publishDate, ) {
|
|
|
|
return Article(widget: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Text(title)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2021-11-06 11:01:44 +01:00
|
|
|
body: ListView(
|
2021-11-16 19:41:35 +01:00
|
|
|
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
|
2021-11-06 11:01:44 +01:00
|
|
|
children: [
|
2021-11-16 19:41:35 +01:00
|
|
|
ListTile(
|
2021-11-19 20:12:42 +01:00
|
|
|
leading: const Icon(MdiIcons.accountOutline),
|
2021-11-16 19:41:35 +01:00
|
|
|
title: Text(author),
|
|
|
|
),
|
|
|
|
ListTile(
|
2021-11-19 20:12:42 +01:00
|
|
|
leading: const Icon(MdiIcons.calendarOutline),
|
2021-11-16 19:41:35 +01:00
|
|
|
title: Text("${DateTime.parse(publishDate).day.toString()}.${DateTime.parse(publishDate).month.toString()}.${DateTime.parse(publishDate).year.toString()}"),
|
|
|
|
),
|
2021-11-19 20:12:42 +01:00
|
|
|
MarkdownBody(data: content)
|
2021-11-06 11:01:44 +01:00
|
|
|
],
|
|
|
|
)
|
2021-11-16 19:41:35 +01:00
|
|
|
)
|
|
|
|
);
|
2021-11-06 11:01:44 +01:00
|
|
|
}
|
2021-09-14 20:55:58 +02:00
|
|
|
}
|