diff --git a/lib/Widgets/comments_widget.dart b/lib/Widgets/comments_widget.dart new file mode 100644 index 0000000..06db973 --- /dev/null +++ b/lib/Widgets/comments_widget.dart @@ -0,0 +1,62 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class CommentWidget extends StatefulWidget { + final String commentId; + final String commenterId; + final String commenterName; + final String commentBody; + final String commenterImageUrl; + + const CommentWidget({ + required this.commentId, + required this.commenterId, + required this.commentBody, + required this.commenterImageUrl, + required this.commenterName, + }); + + @override + State createState() => _CommentWidgetState(); +} + +class _CommentWidgetState extends State { + @override + Widget build(BuildContext context) { + return InkWell( + onTap: () {}, + child: Container( + decoration: BoxDecoration( + border: Border.all(color: Colors.grey), + borderRadius: BorderRadius.circular(10.0), + ), + padding: const EdgeInsets.all(10.0), + child: Row( + children: [ + CircleAvatar( + backgroundImage: NetworkImage(widget.commenterImageUrl), + radius: 20.0, + ), + const SizedBox(width: 10.0), + Flexible( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + widget.commenterName, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16.0, + ), + ), + const SizedBox(height: 5.0), + Text(widget.commentBody), + ], + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/jobs/job_details.dart b/lib/jobs/job_details.dart index 1f3d660..3fd98be 100644 --- a/lib/jobs/job_details.dart +++ b/lib/jobs/job_details.dart @@ -1,4 +1,5 @@ import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:cpd_ss23/Widgets/comments_widget.dart'; import 'package:cpd_ss23/jobs/jobs_screen.dart'; import 'package:cpd_ss23/services/global_methods.dart'; import 'package:cpd_ss23/services/global_variables.dart'; @@ -622,8 +623,9 @@ class _JobDetailsScreenState extends State { ), IconButton( onPressed: () { + setState(() { - showComment = false; + showComment = true; }); }, icon: const Icon( @@ -634,6 +636,47 @@ class _JobDetailsScreenState extends State { ), ], )), + showComment == false ? + Container() + : Padding( + padding:EdgeInsets.all(16.0), + child: FutureBuilder( + future: FirebaseFirestore.instance.collection('jobs').doc(widget.jobID).get(), + builder:(context,snapshot){ + if(snapshot.connectionState == ConnectionState.waiting){ + return const Center(child:CircularProgressIndicator(),); + } + else { + if(snapshot.data == null){ + return const Center(child:Text("Keine kommentare"),); + } + + } + return ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return CommentWidget( + commentId: snapshot.data!['jobComments'][index]['commentId'], + commenterId: snapshot.data!['jobComments'][index]['userId'], + commentBody: snapshot.data!['jobComments'][index]['commentBody'], + commenterImageUrl: snapshot.data!['jobComments'][index]['userImage'], + commenterName: snapshot.data!['jobComments'][index]['name'], + ); + }, + separatorBuilder: (context, index) { + return const Divider( + thickness: 1, + color: Colors.grey, + ); + }, + itemCount: snapshot.data!['jobComments'].length, + ); + + + } + ) + ) ], ), ),