jobComment implementierung

main
Nadezda Kloos 2023-06-17 13:43:53 +02:00
parent 31f229d122
commit 934c5c147d
1 changed files with 54 additions and 4 deletions

View File

@ -1,9 +1,12 @@
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cpd_ss23/jobs/jobs_screen.dart'; import 'package:cpd_ss23/jobs/jobs_screen.dart';
import 'package:cpd_ss23/services/global_methods.dart'; import 'package:cpd_ss23/services/global_methods.dart';
import 'package:cpd_ss23/services/global_variables.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
import 'package:uuid/uuid.dart';
class JobDetailsScreen extends StatefulWidget { class JobDetailsScreen extends StatefulWidget {
final String uploadedBy; final String uploadedBy;
@ -34,6 +37,7 @@ class _JobDetailsScreenState extends State<JobDetailsScreen> {
String? emailCompany = ""; String? emailCompany = "";
int applicants = 0; int applicants = 0;
bool isDeadlineAvailable = false; bool isDeadlineAvailable = false;
bool showComment = false;
void getJobData() async { void getJobData() async {
final DocumentSnapshot userDoc = await FirebaseFirestore.instance final DocumentSnapshot userDoc = await FirebaseFirestore.instance
@ -535,7 +539,37 @@ class _JobDetailsScreenState extends State<JobDetailsScreen> {
const EdgeInsets.symmetric( const EdgeInsets.symmetric(
horizontal: 8), horizontal: 8),
child: MaterialButton( child: MaterialButton(
onPressed: () {}, onPressed: () async {
if(_commentController.text.length < 7){
GlobalMethod.showErrorDialog(error: "Komment > 7 chars", ctx: context);
}
else{
final _generatedId= Uuid().v4();
await FirebaseFirestore.instance.collection('jobs').doc(widget.jobID).update({
'jobComments':
FieldValue.arrayUnion([
{'userId':FirebaseAuth.instance.currentUser!.uid,
'commentId':_generatedId,
'name': name,
'userImage':userImage,
'commentBody': _commentController.text,
'time': Timestamp.now(),}
])
});
await Fluttertoast.showToast(
msg: 'Kommentaar wurde uploaded',
toastLength: Toast.LENGTH_LONG,
backgroundColor: Colors.grey,
fontSize: 18.0,
);
_commentController.clear();
setState(() {
showComment = true;
});
}
},
color: Colors.blueAccent, color: Colors.blueAccent,
elevation: 0, elevation: 0,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
@ -553,7 +587,14 @@ class _JobDetailsScreenState extends State<JobDetailsScreen> {
), ),
), ),
TextButton( TextButton(
onPressed: () {}, onPressed: () {
setState(() {
_isCommenting=!_isCommenting;
showComment = false;
});
},
child: const Text("Cancel"), child: const Text("Cancel"),
) )
], ],
@ -565,7 +606,12 @@ class _JobDetailsScreenState extends State<JobDetailsScreen> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
IconButton( IconButton(
onPressed: () {}, onPressed: () {
setState(() {
_isCommenting=!_isCommenting;
});
},
icon: const Icon( icon: const Icon(
Icons.add_comment, Icons.add_comment,
color: Colors.blueAccent, color: Colors.blueAccent,
@ -576,7 +622,11 @@ class _JobDetailsScreenState extends State<JobDetailsScreen> {
width: 10, width: 10,
), ),
IconButton( IconButton(
onPressed: () {}, onPressed: () {
setState(() {
showComment = false;
});
},
icon: const Icon( icon: const Icon(
Icons.arrow_drop_down_circle, Icons.arrow_drop_down_circle,
color: Colors.blueAccent, color: Colors.blueAccent,