comments show on the job detail page

main
Nadezda Kloos 2023-06-18 15:24:44 +02:00
parent d956efe95a
commit 729bc426ea
2 changed files with 106 additions and 1 deletions

View File

@ -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<CommentWidget> createState() => _CommentWidgetState();
}
class _CommentWidgetState extends State<CommentWidget> {
@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),
],
),
),
],
),
),
);
}
}

View File

@ -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<JobDetailsScreen> {
),
IconButton(
onPressed: () {
setState(() {
showComment = false;
showComment = true;
});
},
icon: const Icon(
@ -634,6 +636,47 @@ class _JobDetailsScreenState extends State<JobDetailsScreen> {
),
],
)),
showComment == false ?
Container()
: Padding(
padding:EdgeInsets.all(16.0),
child: FutureBuilder<DocumentSnapshot>(
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,
);
}
)
)
],
),
),