feat: Centralized Error Handling & Crash Fixes
This commit is contained in:
@@ -48,29 +48,14 @@ class BankAccountPage extends StatelessWidget {
|
||||
bloc: cubit,
|
||||
listener: (BuildContext context, BankAccountState state) {
|
||||
if (state.status == BankAccountStatus.accountAdded) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
strings.account_added_success,
|
||||
style: UiTypography.body2r.textPrimary,
|
||||
),
|
||||
backgroundColor: UiColors.tagSuccess,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
} else if (state.status == BankAccountStatus.error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
state.errorMessage != null
|
||||
? translateErrorKey(state.errorMessage!)
|
||||
: 'An error occurred',
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
UiSnackbar.show(
|
||||
context,
|
||||
message: strings.account_added_success,
|
||||
type: UiSnackbarType.success,
|
||||
margin: const EdgeInsets.only(bottom: 120, left: 16, right: 16),
|
||||
);
|
||||
}
|
||||
// Error is already shown on the page itself (lines 73-85), no need for snackbar
|
||||
},
|
||||
builder: (BuildContext context, BankAccountState state) {
|
||||
if (state.status == BankAccountStatus.loading && state.accounts.isEmpty) {
|
||||
|
||||
@@ -19,6 +19,25 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
||||
final TextEditingController _routingController = TextEditingController();
|
||||
final TextEditingController _accountController = TextEditingController();
|
||||
String _selectedType = 'CHECKING';
|
||||
bool _isFormValid = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bankNameController.addListener(_validateForm);
|
||||
_routingController.addListener(_validateForm);
|
||||
_accountController.addListener(_validateForm);
|
||||
}
|
||||
|
||||
void _validateForm() {
|
||||
setState(() {
|
||||
_isFormValid = _bankNameController.text.trim().isNotEmpty &&
|
||||
_routingController.text.trim().isNotEmpty &&
|
||||
_routingController.text.replaceAll(RegExp(r'\D'), '').length == 9 &&
|
||||
_accountController.text.trim().isNotEmpty &&
|
||||
_accountController.text.replaceAll(RegExp(r'\D'), '').length >= 4;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -96,14 +115,16 @@ class _AddAccountFormState extends State<AddAccountForm> {
|
||||
Expanded(
|
||||
child: UiButton.primary(
|
||||
text: widget.strings.save,
|
||||
onPressed: () {
|
||||
widget.onSubmit(
|
||||
_bankNameController.text,
|
||||
_routingController.text,
|
||||
_accountController.text,
|
||||
_selectedType,
|
||||
);
|
||||
},
|
||||
onPressed: _isFormValid
|
||||
? () {
|
||||
widget.onSubmit(
|
||||
_bankNameController.text.trim(),
|
||||
_routingController.text.trim(),
|
||||
_accountController.text.trim(),
|
||||
_selectedType,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -51,13 +51,10 @@ class _TimeCardPageState extends State<TimeCardPage> {
|
||||
body: BlocConsumer<TimeCardBloc, TimeCardState>(
|
||||
listener: (context, state) {
|
||||
if (state is TimeCardError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
translateErrorKey(state.message),
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
UiSnackbar.show(
|
||||
context,
|
||||
message: translateErrorKey(state.message),
|
||||
type: UiSnackbarType.error,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user