Cheque Functionality Stop Cheque done

This commit is contained in:
2025-12-30 13:12:40 +05:30
parent 537a4faa62
commit 9d8c8dc8bd
3 changed files with 252 additions and 18 deletions

View File

@@ -1,5 +1,9 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:kmobile/api/services/cheque_service.dart';
import 'package:kmobile/data/models/user.dart';
import 'package:kmobile/di/injection.dart';
class StopSingleChequeScreen extends StatefulWidget {
final User selectedAccount;
@@ -27,6 +31,7 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
final _stopExpiryDateController = TextEditingController();
final _stopAmountController = TextEditingController();
final _stopCommentController = TextEditingController();
final _chequeService = getIt<ChequeService>();
String _formatDate(String dateString) {
if (dateString.length != 8) {
@@ -42,6 +47,33 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
}
}
Future<void> _showResponseDialog(String title, String message) async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(message),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -148,9 +180,32 @@ class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: () {
onPressed: () async {
if (_formKey.currentState!.validate()) {
// TODO: Implement stop single cheque logic
try {
final response = await _chequeService.stopCheque(
accountno: widget.selectedAccount.accountNo!,
stopFromChequeNo: _stopFromChequeNoController.text,
instrType: widget.instrType,
stopToChequeNo: _stopFromChequeNoController.text,
stopIssueDate: _stopIssueDateController.text,
stopExpiryDate: _stopExpiryDateController.text,
stopAmount: _stopAmountController.text,
stopComment: _stopCommentController.text,
chequeIssueDate: widget.date,
);
if (!mounted) return;
final decodedResponse = jsonDecode(response);
final status = decodedResponse['status'];
final message = decodedResponse['message'];
if (status == 'SUCCESS') {
_showResponseDialog('Success', message);
} else {
_showResponseDialog('Error', message);
}
} catch (e) {
_showResponseDialog('Error', e.toString());
}
}
},
child: const Text('Stop Cheque'),