Skip to content

Commit

Permalink
Merge pull request #247 from CosmicRaptor/main
Browse files Browse the repository at this point in the history
minor fixes to bug report screen
  • Loading branch information
CosmicRaptor authored Jul 31, 2024
2 parents 07334bd + 10e9113 commit 70cda02
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/models/bugreport_model/bugreport_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Bugreport {
final List<String?> attachments;
bool isResolved;
DateTime reportTime;
String userUid;
Bugreport({required this.title, required this.description, required this.attachments, required this.isResolved, required this.reportTime, required this.userUid});
String? userUid;
Bugreport({required this.title, required this.description, required this.attachments, required this.isResolved, required this.reportTime, this.userUid});

Map<String, dynamic> toJson(){
return {
Expand All @@ -14,7 +14,7 @@ class Bugreport {
'attachments': attachments,
'isResolved': isResolved,
'reportTime': reportTime.toIso8601String(),
'userUid': userUid,
'userUid': userUid ?? 'null',
};
}

Expand All @@ -25,7 +25,7 @@ class Bugreport {
attachments: List<String?>.from(json['attachments']),
isResolved: json['isResolved'],
reportTime: DateTime.parse(json['reportTime']),
userUid: json['userUid'],
userUid: json['userUid'] ?? 'null[',
);
}
}
34 changes: 25 additions & 9 deletions lib/new_ui/screens/bug_report_screen/bug_report_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tsec_app/new_ui/screens/bug_report_screen/widgets/image_card.dart';
import 'package:tsec_app/provider/auth_provider.dart';
import 'package:tsec_app/provider/bug_report_provider.dart';
import 'package:tsec_app/provider/firebase_provider.dart';
import 'package:tsec_app/utils/custom_snackbar.dart';
Expand Down Expand Up @@ -99,12 +100,18 @@ class _BugReportScreenState extends ConsumerState<BugReportScreen> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
OutlinedButton(onPressed: () async{
var selected = await pickMultipleImages();
images.addAll(selected);
setState(() {
//print(images.isEmpty);
});
OutlinedButton(
onPressed: () async{
if(ref.read(userModelProvider) != null) {
var selected = await pickMultipleImages();
images.addAll(selected);
setState(() {
//print(images.isEmpty);
});
}
else {
showSnackBar(context, 'You need to login to attach images.');
}
}, child: Text('Pick images'))
],
),
Expand Down Expand Up @@ -138,20 +145,29 @@ class _BugReportScreenState extends ConsumerState<BugReportScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
MaterialButton(onPressed: ()async{
if(titleController.text.isEmpty || descriptionController.text.isEmpty || images.isEmpty){
if(titleController.text.isEmpty || descriptionController.text.isEmpty){
showSnackBar(context, 'Please fill all fields');
return;
}
else {
showSnackBar(context, 'Submitting...');
String titleText = titleController.text;
String descriptionText = descriptionController.text;
titleController.clear();
descriptionController.clear();
setState(() {
iseEnabled = true;
});
if(ref.read(userModelProvider) != null) {
await ref.read(bugreportNotifierProvider.notifier).addBugreport(titleText, descriptionText, images, ref.read(firebaseAuthProvider).currentUser!.uid);
}
else {
await ref.read(bugreportNotifierProvider.notifier).addBugreport(titleText, descriptionText, images, null);
}
setState(() {
images.clear();

//iseEnabled = false;
});
await ref.read(bugreportNotifierProvider.notifier).addBugreport(titleController.text, descriptionController.text, images, ref.read(firebaseAuthProvider).currentUser!.uid);
showSnackBar(context, 'Submitted successfully'); }
}, color: Colors.green, child: Text('Submit'),),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/bug_report_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BugreportNotifier extends StateNotifier<List<Bugreport>> {
BugreportNotifier(this._reportServices) : super([]);

// Add a new report
Future<void> addBugreport(String title, String description, List<File> imagePaths, String uid) async {
Future<void> addBugreport(String title, String description, List<File> imagePaths, String? uid) async {
try {
List<File> files = imagePaths;
List<String> attachments = await _reportServices.getBugImages(files);
Expand Down

0 comments on commit 70cda02

Please sign in to comment.