|
|
@@ -5,7 +5,9 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
+import 'package:dio/dio.dart';
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
+import '../../core/network/api_exception.dart';
|
|
|
import '../../core/utils/responsive.dart';
|
|
|
import '../../shared/widgets/form_section.dart';
|
|
|
import '../../shared/widgets/form_field_row.dart';
|
|
|
@@ -1097,16 +1099,38 @@ class _ExpenseCreatePageState extends ConsumerState<ExpenseCreatePage> {
|
|
|
);
|
|
|
GoRouter.of(context).go('/expense/list');
|
|
|
}
|
|
|
- } catch (_) {
|
|
|
+ } catch (e) {
|
|
|
if (mounted) {
|
|
|
LoadingDialog.hide(context);
|
|
|
- TDToast.showFail(l10n.get('submitFailedRetry'), context: context);
|
|
|
+ WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
+ if (mounted) _showSubmitError(e, l10n);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ void _showSubmitError(Object e, AppLocalizations l10n) {
|
|
|
+ final message = _extractErrorMessage(e) ?? l10n.get('submitFailedRetry');
|
|
|
+ showGeneralDialog(
|
|
|
+ context: context,
|
|
|
+ pageBuilder: (ctx, animation, secondaryAnimation) => TDConfirmDialog(
|
|
|
+ title: l10n.get('submitFailed'),
|
|
|
+ content: message,
|
|
|
+ buttonStyle: TDDialogButtonStyle.text,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ String? _extractErrorMessage(Object e) {
|
|
|
+ if (e is DioException) {
|
|
|
+ if (e.error is ApiException) return (e.error as ApiException).message;
|
|
|
+ if (e.error is NetworkException) return (e.error as NetworkException).message;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
Future<void> _showAddDetailDialog(
|
|
|
ExpenseCreateController controller, {
|
|
|
int? editIndex,
|