import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import 'DetailPage.dart'; import 'package:intl/intl.dart'; class UserDefinedItem extends StatelessWidget { final String title; final String datum; final String description; final Image? image; const UserDefinedItem({ Key? key, required this.title, required this.description, required this.datum, this.image, }) : super(key: key); @override Widget build(BuildContext context) { return Card( child: InkWell( onTap: () { // Open a new screen when the user taps on the list item Navigator.push( context, MaterialPageRoute( builder: (context) => DetailPage( title: title, datum: datum, description: description, image: image != null ? image! : null, ), ), ); }, child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( width: 120, height: 120, child: image, ), Flexible( flex: 1, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( child: Text( title, overflow: TextOverflow.ellipsis, style: const TextStyle( fontSize: 20, fontWeight: FontWeight .bold // beliebige Schriftgröße ), ), ), Text( datum, style: const TextStyle( fontSize: 15, // beliebige Schriftgröße ), ), ], ), ), Padding( padding: const EdgeInsets.all(8.0), // feste Höhe für 2 Zeilen child: Text( description, maxLines: 3, overflow: TextOverflow.ellipsis, style: const TextStyle( fontSize: 15, ), ), ), ], ), ), ], ), ), ); } } class NewsList extends StatefulWidget { const NewsList({Key? key}) : super(key: key); @override _NewsListState createState() => _NewsListState(); } class _NewsListState extends State { final FirebaseFirestore firestore = FirebaseFirestore.instance; late Stream newsStream; @override void initState() { super.initState(); // Enable persistence firestore.enablePersistence(); // Enable network firestore.settings = Settings(cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED); // Configure the stream to use the cache first and then the server newsStream = firestore .collection('News') .orderBy('createdDate', descending: true) .snapshots(includeMetadataChanges: true); } @override Widget build(BuildContext context) { return StreamBuilder( stream: newsStream, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } switch (snapshot.connectionState) { case ConnectionState.waiting: return const Text('Loading...'); default: final List documents = snapshot.data!.docs; return ListView.builder( itemCount: documents.length, itemBuilder: (BuildContext context, int index) { final Map data = documents[index].data()! as Map; final DateTime createdDate = data['createdDate'].toDate(); final formattedDate = DateFormat('dd.MM.yyyy').format(createdDate); return UserDefinedItem( title: data['title'] ?? '', datum: formattedDate, description: data['description'] ?? '', image: Image.network((data['imageUrl'])), ); }, ); } }, ); } } class IssueList extends StatefulWidget { const IssueList({Key? key}) : super(key: key); @override _IssueListState createState() => _IssueListState(); } class _IssueListState extends State { final FirebaseFirestore firestore = FirebaseFirestore.instance; late Stream issueStream; @override void initState() { super.initState(); // Enable persistence firestore.enablePersistence(); // Enable network firestore.settings = Settings(cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED); // Configure the stream to use the cache first and then the server issueStream = firestore .collection('Issues') .orderBy('createdDate', descending: true) .snapshots(includeMetadataChanges: true); } @override Widget build(BuildContext context) { return StreamBuilder( stream: issueStream, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } switch (snapshot.connectionState) { case ConnectionState.waiting: return const Text('Loading...'); default: final List documents = snapshot.data!.docs; return ListView.builder( itemCount: documents.length, itemBuilder: (BuildContext context, int index) { final Map data = documents[index].data()! as Map; final DateTime createdDate = data['createdDate'].toDate(); final formattedDate = DateFormat('dd.MM.yyyy').format(createdDate); return UserDefinedItem( title: data['title'] ?? '', datum: formattedDate, description: data['description'] ?? '', image: Image.network((data['imageUrl'])), ); }, ); } }, ); } } class CitizensForum extends StatefulWidget { const CitizensForum({Key? key}) : super(key: key); @override _CitizensForumState createState() => _CitizensForumState(); } class _CitizensForumState extends State { final FirebaseFirestore firestore = FirebaseFirestore.instance; late Stream>> citizenStream; @override void initState() { super.initState(); // Enable persistence firestore.enablePersistence(); // Enable network firestore.settings = Settings(cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED); // Configure the stream to use the cache first and then the server citizenStream = firestore .collection('CitizensForum') .orderBy('createdDate', descending: true) .snapshots(includeMetadataChanges: true); } @override Widget build(BuildContext context) { return StreamBuilder>>( stream: citizenStream, builder: (BuildContext context, AsyncSnapshot>> snapshot) { if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } switch (snapshot.connectionState) { case ConnectionState.waiting: return const Text('Loading...'); default: final List>> documents = snapshot.data!.docs; return ListView.builder( itemCount: documents.length, itemBuilder: (BuildContext context, int index) { final Map data = documents[index].data(); final DateTime createdDate = data['createdDate'].toDate(); final formattedDate = DateFormat('dd.MM.yyyy').format(createdDate); return UserDefinedItem( title: data['title'] ?? '', datum: formattedDate, description: data['description'] ?? '', image: Image.network((data['imageUrl'])), ); }, ); } }, ); } }