From 527111c1de3a9270f27891e7605b1881e2a15b8b Mon Sep 17 00:00:00 2001 From: Nilanjan Chakrabarti Date: Fri, 31 Oct 2025 13:17:31 +0530 Subject: [PATCH] Limit loaded and less that 2 lakhs --- .../profile/daily_transaction_limit.dart | 120 ++++++++++-------- 1 file changed, 65 insertions(+), 55 deletions(-) diff --git a/lib/features/profile/daily_transaction_limit.dart b/lib/features/profile/daily_transaction_limit.dart index ba8e334..9e56d6d 100644 --- a/lib/features/profile/daily_transaction_limit.dart +++ b/lib/features/profile/daily_transaction_limit.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:kmobile/api/services/limit_service.dart'; -import 'package:kmobile/app.dart'; import 'package:kmobile/di/injection.dart'; import 'package:kmobile/l10n/app_localizations.dart'; import 'package:intl/intl.dart'; @@ -43,63 +42,74 @@ class _DailyLimitScreenState extends State { super.dispose(); } - Future _showAddOrEditLimitDialog() async { - _limitController.text = _currentLimit?.toStringAsFixed(0) ?? ''; - final newLimit = await showDialog( - context: context, - builder: (context) { - final localizations = AppLocalizations.of(context); - return AlertDialog( - title: Text( - _currentLimit == null - ? localizations.addLimit - : localizations.editLimit, - ), - content: TextField( - controller: _limitController, - autofocus: true, - keyboardType: TextInputType.number, - inputFormatters: [ - FilteringTextInputFormatter.allow(RegExp(r'^\d+')), - ], - decoration: InputDecoration( - labelText: localizations.limitAmount, - prefixText: '₹', - border: const OutlineInputBorder(), - ), - ), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: Text(localizations.cancel), - ), - ElevatedButton( - onPressed: () async { - final value = double.tryParse(_limitController.text); - if (value != null && value > 0) { - setState(() { - service.editLimit(value); - }); - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const NavigationScaffold(), - ), - ); - } - }, - child: Text(localizations.save), - ), +Future _showAddOrEditLimitDialog() async { + _limitController.text = _currentLimit?.toStringAsFixed(0) ?? ''; + final newLimit = await showDialog( + context: context, + builder: (dialogContext) { + final localizations = AppLocalizations.of(dialogContext); + final theme = Theme.of(dialogContext); + return AlertDialog( + title: Text( + _currentLimit == null + ? localizations.addLimit + : localizations.editLimit, + ), + content: TextField( + controller: _limitController, + autofocus: true, + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.allow(RegExp(r'^\d+')), ], - ); - }, + decoration: InputDecoration( + labelText: localizations.limitAmount, + prefixText: '₹', + border: const OutlineInputBorder(), + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.of(dialogContext).pop(), + child: Text(localizations.cancel), + ), + ElevatedButton( + onPressed: () { + final value = double.tryParse(_limitController.text); + if (value == null || value <= 0) return; + + if (value > 200000) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text("Limit To be Set must be less than 200000"), + behavior: SnackBarBehavior.floating, + backgroundColor: theme.colorScheme.error, + ), + ); + } else { + service.editLimit(value); + Navigator.of(dialogContext).pop(value); + } + }, + child: Text(localizations.save), + ), + ], + ); + }, + ); + + if (newLimit != null) { + _loadlimits(); + if (!mounted) return; + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text("Limit Updated"), + behavior: SnackBarBehavior.floating, + ), ); - if (newLimit != null) { - setState(() { - _currentLimit = newLimit; - }); - } } +} + void _removeLimit() { setState(() {