Files
kmobile/lib/features/cheque/screens/stop_single_cheque_screen.dart
2025-12-30 12:45:45 +05:30

165 lines
5.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:kmobile/data/models/user.dart';
class StopSingleChequeScreen extends StatefulWidget {
final User selectedAccount;
final String date;
final String instrType;
final String fromCheque;
final String toCheque;
const StopSingleChequeScreen(
{super.key,
required this.selectedAccount,
required this.date,
required this.instrType,
required this.fromCheque,
required this.toCheque});
@override
State<StopSingleChequeScreen> createState() => _StopSingleChequeScreenState();
}
class _StopSingleChequeScreenState extends State<StopSingleChequeScreen> {
final _formKey = GlobalKey<FormState>();
final _stopFromChequeNoController = TextEditingController();
final _stopIssueDateController = TextEditingController();
final _stopExpiryDateController = TextEditingController();
final _stopAmountController = TextEditingController();
final _stopCommentController = TextEditingController();
String _formatDate(String dateString) {
if (dateString.length != 8) {
return dateString; // Return as is if not in expected ddmmyyyy format
}
try {
final day = dateString.substring(0, 2);
final month = dateString.substring(2, 4);
final year = dateString.substring(4, 8);
return '$day/$month/$year';
} catch (e) {
return dateString; // Return original string on error
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Stop Single Cheque'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: ListView(
children: [
Card(
elevation: 0,
margin: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
leading: Image.asset(
'assets/images/logo.png',
width: 40,
height: 40,
),
title: Text(widget.selectedAccount.accountNo!),
subtitle: const Text("Account Number"),
),
),
const SizedBox(height: 24),
TextFormField(
controller: _stopFromChequeNoController,
decoration: const InputDecoration(
labelText: 'Cheque Number *',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a cheque number';
}
final chequeNumber = int.tryParse(value);
final fromCheque = int.tryParse(widget.fromCheque);
final toCheque = int.tryParse(widget.toCheque);
if (chequeNumber == null ||
fromCheque == null ||
toCheque == null) {
return 'Invalid cheque number format';
}
if (chequeNumber < fromCheque || chequeNumber > toCheque) {
return 'Cheque number must be between ${widget.fromCheque} and ${widget.toCheque}';
}
return null;
},
),
const SizedBox(height: 16),
TextFormField(
initialValue: widget.instrType,
readOnly: true,
decoration: const InputDecoration(
labelText: 'Instrument Type *',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 16),
TextFormField(
controller: _stopIssueDateController,
decoration: const InputDecoration(
labelText: 'Stop Issue Date',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.datetime,
),
const SizedBox(height: 16),
TextFormField(
controller: _stopExpiryDateController,
decoration: const InputDecoration(
labelText: 'Stop Expiry Date',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.datetime,
),
const SizedBox(height: 16),
TextFormField(
controller: _stopAmountController,
decoration: const InputDecoration(
labelText: 'Stop Amount',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
),
const SizedBox(height: 16),
TextFormField(
controller: _stopCommentController,
decoration: const InputDecoration(
labelText: 'Stop Comment',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 16),
TextFormField(
initialValue: _formatDate(widget.date),
readOnly: true,
decoration: const InputDecoration(
labelText: 'Chequebook Issue Date',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
// TODO: Implement stop single cheque logic
}
},
child: const Text('Stop Cheque'),
),
],
),
),
),
);
}
}