-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bug report screen + provider + model
- Loading branch information
1 parent
d3e257e
commit c88e1f8
Showing
8 changed files
with
317 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Bugreport { | ||
final String title; | ||
final String description; | ||
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}); | ||
|
||
Map<String, dynamic> toJson(){ | ||
return { | ||
'title': title, | ||
'description': description, | ||
'attachments': attachments, | ||
'isResolved': isResolved, | ||
'reportTime': reportTime.toIso8601String(), | ||
'userUid': userUid, | ||
}; | ||
} | ||
|
||
factory Bugreport.fromjson(Map<String, dynamic> json){ | ||
return Bugreport( | ||
title: json['title'], | ||
description: json['description'], | ||
attachments: List<String?>.from(json['attachments']), | ||
isResolved: json['isResolved'], | ||
reportTime: DateTime.parse(json['reportTime']), | ||
userUid: json['userUid'], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:tsec_app/new_ui/screens/main_screen/widgets/common_basic_appbar.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'; | ||
import 'package:tsec_app/utils/image_pick.dart'; | ||
|
||
class BugReportScreen extends ConsumerWidget { | ||
BugReportScreen({Key? key}) : super(key: key); | ||
|
||
final titleController = TextEditingController(); | ||
final descriptionController = TextEditingController(); | ||
List<File> images = []; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: AppBar(shadowColor: Colors.transparent, | ||
backgroundColor: Colors.transparent, | ||
toolbarHeight: 80, | ||
title: Text('Bug Report', | ||
style: Theme.of(context) | ||
.textTheme | ||
.headlineLarge! | ||
.copyWith(fontSize: 15, color: Colors.white), | ||
maxLines: 1, | ||
overflow: TextOverflow.fade,), | ||
centerTitle: true, | ||
iconTheme: IconThemeData(color: Colors.white),), | ||
body: SingleChildScrollView( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const SizedBox(height: 20), | ||
const Text( | ||
"Please provide a title for the bug report. This will help us identify the issue faster.", | ||
style: TextStyle( | ||
fontSize: 16, | ||
color: Colors.white | ||
), | ||
), | ||
const SizedBox(height: 20), | ||
// Add the form here | ||
TextFormField( | ||
//maxLines: 3, | ||
minLines: 1, | ||
decoration: const InputDecoration( | ||
hintText: 'Bug title', | ||
hintStyle: TextStyle(color: Colors.grey, fontSize: 16), | ||
border: OutlineInputBorder(borderSide: BorderSide(color: Colors.blue), borderRadius: BorderRadius.all(Radius.circular(10))), | ||
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), | ||
isDense: true), | ||
controller: titleController, | ||
style: Theme.of(context).textTheme.headlineSmall, | ||
), | ||
const SizedBox(height: 20), | ||
const Text( | ||
"Please provide a detailed description of the bug. This will help us understand the issue better. Provide steps to reproduce the bug if possible.", | ||
style: TextStyle( | ||
fontSize: 16, | ||
color: Colors.grey | ||
), | ||
), | ||
const SizedBox(height: 20), | ||
TextFormField( | ||
maxLines: null, | ||
minLines: 1, | ||
decoration: const InputDecoration( | ||
hintText: 'Bug description', | ||
hintStyle: TextStyle(color: Colors.grey, fontSize: 16), | ||
border: OutlineInputBorder(borderSide: BorderSide(color: Colors.blue), borderRadius: BorderRadius.all(Radius.circular(10))), | ||
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), | ||
isDense: true), | ||
controller: descriptionController, | ||
style: Theme.of(context).textTheme.bodySmall, | ||
), | ||
const SizedBox(height: 20), | ||
// Add the image picker here | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
OutlinedButton(onPressed: () async{ | ||
images = await pickMultipleImages(); | ||
print(images); | ||
}, child: Text('Pick images')), | ||
], | ||
), | ||
const SizedBox(height: 20), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
MaterialButton(onPressed: ()async{ | ||
await ref.read(bugreportNotifierProvider.notifier).addBugreport(titleController.text, descriptionController.text, images, ref.read(firebaseAuthProvider).currentUser!.uid); | ||
titleController.clear(); | ||
descriptionController.clear(); | ||
showSnackBar(context, 'Submitted successfully'); | ||
}, color: Colors.green, child: Text('Submit'),), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:tsec_app/models/bugreport_model/bugreport_model.dart'; | ||
import 'package:tsec_app/services/bug_report_service.dart'; | ||
|
||
final reportServicesProvider = Provider<ReportServices>((ref) { | ||
return ReportServices(); | ||
}); | ||
|
||
class BugreportNotifier extends StateNotifier<List<Bugreport>> { | ||
final ReportServices _reportServices; | ||
|
||
BugreportNotifier(this._reportServices) : super([]); | ||
|
||
// Add a new report | ||
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); | ||
|
||
Bugreport newReport = Bugreport( | ||
title: title, | ||
description: description, | ||
attachments: attachments, | ||
isResolved: false, | ||
reportTime: DateTime.now(), | ||
userUid: uid, | ||
); | ||
|
||
await _reportServices.addReport(newReport); | ||
state = [...state, newReport]; | ||
} catch (e) { | ||
print('Error adding bug report: $e'); | ||
} | ||
} | ||
|
||
} | ||
|
||
final bugreportNotifierProvider = StateNotifierProvider<BugreportNotifier, List<Bugreport>>((ref) { | ||
final reportServices = ref.watch(reportServicesProvider); | ||
return BugreportNotifier(reportServices); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'dart:io'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:firebase_storage/firebase_storage.dart'; | ||
import 'package:tsec_app/models/bugreport_model/bugreport_model.dart'; | ||
|
||
class ReportServices { | ||
static final reportsCollection = FirebaseFirestore.instance.collection("Reports"); | ||
static final reportStorage = FirebaseStorage.instance.ref("Reports"); | ||
final FirebaseAuth _auth = FirebaseAuth.instance; | ||
|
||
// Function to update Firestore by adding the new report | ||
Future<void> addReport(Bugreport report) async { | ||
final doc = reportsCollection.doc("Reports"); | ||
final get = await doc.get(); | ||
List allReports = get.data()?['allReports'] ?? []; | ||
|
||
final newReport = report.toJson(); | ||
|
||
allReports.add(newReport); | ||
await doc.set({"allReports": allReports}); | ||
} | ||
|
||
// Function to upload image files to storage and return download URLs | ||
Future<List<String>> getBugImages(List<File> fileImages) async { | ||
List<String> bugImages = []; | ||
for (File image in fileImages) { | ||
final uploadTask = await reportStorage | ||
.child(_auth.currentUser!.uid) | ||
.child(DateTime.now().millisecondsSinceEpoch.toString()) | ||
.putFile(image); | ||
final String downloadUrl = await uploadTask.ref.getDownloadURL(); | ||
bugImages.add(downloadUrl); | ||
} | ||
return bugImages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.