chnages was made

This commit is contained in:
Daniah Ayad Al-sultani
2025-12-07 12:01:23 +03:00
parent d789bcdc88
commit dbf76b2d30
7 changed files with 672 additions and 11 deletions

View File

@@ -3,6 +3,8 @@ import 'package:flutter_svg/flutter_svg.dart';
import '../widgets/app_background.dart';
import '../widgets/settings_bar.dart';
import '../widgets/onboarding_button.dart';
import '../models/advance_request.dart';
import '../services/request_service.dart';
class RequestAdvanceScreen extends StatefulWidget {
const RequestAdvanceScreen({super.key});
@@ -18,6 +20,56 @@ class _RequestAdvanceScreenState extends State<RequestAdvanceScreen> {
// Text controller for reason
final TextEditingController reasonController = TextEditingController();
final RequestService _requestService = RequestService();
// Method to save the advance request
Future<void> _saveAdvanceRequest() async {
if (amountController.text.isEmpty || reasonController.text.isEmpty) {
// Show an error message if fields are empty
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('الرجاء إدخال جميع الحقول'),
backgroundColor: Colors.red,
),
);
return;
}
// Parse the amount to double
final amount = double.tryParse(amountController.text);
if (amount == null || amount <= 0) {
// Show an error message if amount is invalid
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('الرجاء إدخال مبلغ صحيح'),
backgroundColor: Colors.red,
),
);
return;
}
// Create a new advance request
final advanceRequest = AdvanceRequest(
id: DateTime.now().millisecondsSinceEpoch.toString(),
amount: amount,
reason: reasonController.text,
);
// Save the advance request
await _requestService.addAdvanceRequest(advanceRequest);
// Show a success message
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('تم إرسال طلب السلفة بنجاح'),
backgroundColor: Colors.green,
),
);
// Navigate back to the previous screen
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -155,7 +207,8 @@ class _RequestAdvanceScreenState extends State<RequestAdvanceScreen> {
controller: reasonController,
maxLines: 5,
textAlign:
TextAlign.right, // Added this to align text to the right
TextAlign
.right, // Added this to align text to the right
decoration: const InputDecoration(
border: InputBorder.none,
hintText:
@@ -175,7 +228,7 @@ class _RequestAdvanceScreenState extends State<RequestAdvanceScreen> {
text: "تأكيد الطلب",
backgroundColor: const Color(0xFFD1FEF0),
textColor: Colors.black,
onPressed: () {},
onPressed: _saveAdvanceRequest, // Call the save method
),
),
@@ -190,4 +243,4 @@ class _RequestAdvanceScreenState extends State<RequestAdvanceScreen> {
),
);
}
}
}