-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
726 additions
and
525 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
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,29 @@ | ||
import 'package:flutter/src/widgets/framework.dart'; | ||
import 'package:flutter_email_sender/flutter_email_sender.dart'; | ||
|
||
Future<void> sendReportEmail({ | ||
required String selectedIncidentType, | ||
required String location, | ||
required String description, | ||
required String recipientEmail, required BuildContext context, | ||
}) async { | ||
final emailBody = StringBuffer(); | ||
emailBody.write('Incident Type: $selectedIncidentType\n'); | ||
emailBody.write('Location: $location\n'); | ||
emailBody.write('Description: $description\n'); | ||
|
||
final emailRecipient = recipientEmail.isNotEmpty ? recipientEmail : '[email protected]'; | ||
final email = Email( | ||
subject: 'Incident Report', | ||
body: emailBody.toString(), | ||
recipients: [emailRecipient], | ||
); | ||
|
||
try { | ||
await FlutterEmailSender.send(email); | ||
// Return a successful result | ||
} catch (error) { | ||
// Return an error result | ||
rethrow; | ||
} | ||
} |
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,46 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class IncidentTypeDropdown extends StatelessWidget { | ||
final String selectedIncidentType; | ||
final ValueChanged<String?> onChanged; | ||
|
||
const IncidentTypeDropdown({super.key, | ||
required this.selectedIncidentType, | ||
required this.onChanged, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
const Text( | ||
'Select Incident Type *:', | ||
style: TextStyle( | ||
fontSize: 18, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 8), | ||
DropdownButtonFormField<String>( | ||
value: selectedIncidentType, | ||
items: const [ | ||
DropdownMenuItem( | ||
value: 'environmental_safety', | ||
child: Text('Environmental Safety'), | ||
), | ||
DropdownMenuItem( | ||
value: 'online_safety', | ||
child: Text('Online Safety'), | ||
), | ||
], | ||
onChanged: onChanged, | ||
decoration: const InputDecoration( | ||
border: OutlineInputBorder(), | ||
hintText: 'Select Incident Type', | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,104 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:guardiancare/screens/Report/incident_type_dropdown.dart'; | ||
import 'package:guardiancare/screens/Report/text_input_field.dart'; | ||
import 'package:guardiancare/screens/Report/submit_button.dart'; | ||
import 'package:guardiancare/screens/Report/email_utils.dart'; | ||
|
||
class ReportPage extends StatefulWidget { | ||
const ReportPage({super.key}); | ||
|
||
@override | ||
_ReportPageState createState() => _ReportPageState(); | ||
} | ||
|
||
class _ReportPageState extends State<ReportPage> { | ||
late String _selectedIncidentType = 'environmental_safety'; | ||
final TextEditingController _locationController = TextEditingController(); | ||
final TextEditingController _descriptionController = TextEditingController(); | ||
final TextEditingController _recipientEmailController = | ||
TextEditingController(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Report Incident'), | ||
), | ||
body: SingleChildScrollView( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
IncidentTypeDropdown( | ||
selectedIncidentType: _selectedIncidentType, | ||
onChanged: (value) { | ||
setState(() { | ||
_selectedIncidentType = value!; | ||
}); | ||
}, | ||
), | ||
const SizedBox(height: 16), | ||
TextInputField( | ||
controller: _locationController, | ||
labelText: 'Location *', | ||
keyboardType: TextInputType.text, | ||
), | ||
const SizedBox(height: 16), | ||
TextInputField( | ||
controller: _descriptionController, | ||
labelText: 'Description *', | ||
keyboardType: TextInputType.multiline, | ||
maxLines: null, | ||
), | ||
const SizedBox(height: 16), | ||
TextInputField( | ||
controller: _recipientEmailController, | ||
labelText: 'Recipient Email(s) (optional)', | ||
keyboardType: TextInputType.emailAddress, | ||
validator: (value) { | ||
if (value!.isEmpty) { | ||
return null; | ||
} | ||
final emailRegex = RegExp(r"[^@]+@[^@]+\.[^@]+"); | ||
if (!emailRegex.hasMatch(value)) { | ||
return 'Please enter a valid email address.'; | ||
} | ||
return null; | ||
}, | ||
), | ||
const SizedBox(height: 16), | ||
SubmitButton( | ||
onPressed: () { | ||
_submitReport(context); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
bool _validateInput() { | ||
return _locationController.text.isNotEmpty && | ||
_descriptionController.text.isNotEmpty; | ||
} | ||
|
||
Future<void> _submitReport(BuildContext context) async { | ||
if (!_validateInput()) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Location and Description are required.'), | ||
), | ||
); | ||
return; | ||
} | ||
|
||
await sendReportEmail( | ||
selectedIncidentType: _selectedIncidentType, | ||
location: _locationController.text, | ||
description: _descriptionController.text, | ||
recipientEmail: _recipientEmailController.text, | ||
context: context, | ||
); | ||
} | ||
} |
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,15 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class SubmitButton extends StatelessWidget { | ||
final VoidCallback onPressed; | ||
|
||
const SubmitButton({super.key, required this.onPressed}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
onPressed: onPressed, | ||
child: const Text('Submit'), | ||
); | ||
} | ||
} |
Oops, something went wrong.