Gracefully handle toast messages error on desktop platforms
OmarHatem committed
Apr 28, 2025 at 15:12 UTC
e527083871fda2f90da12d98ebf9c7003ada08f8
4 files changed
+31
-23
cw_zano/lib/zano_formatter.dart
+3
-2
@@ -1,7 +1,6 @@
1
import 'dart:math';
2
3
import 'package:cw_core/utils/print_verbose.dart';
4
-import 'package:cw_zano/zano_wallet_api.dart';
4
import 'package:decimal/decimal.dart';
5
import 'package:decimal/intl.dart';
6
import 'package:fluttertoast/fluttertoast.dart';
@@ -57,7 +56,9 @@ class ZanoFormatter {
56
static int parseAmount(String amount, [int decimalPoint = defaultDecimalPoint]) {
57
final resultBigInt = (Decimal.parse(amount) * Decimal.fromBigInt(BigInt.from(10).pow(decimalPoint))).toBigInt();
58
if (!resultBigInt.isValidInt) {
60
- Fluttertoast.showToast(msg: 'Cannot transfer $amount. Maximum is ${intAmountToString(resultBigInt.toInt(), decimalPoint)}.');
59
+ try {
60
+ Fluttertoast.showToast(msg: 'Cannot transfer $amount. Maximum is ${intAmountToString(resultBigInt.toInt(), decimalPoint)}.');
61
+ } catch (_) {}
62
}
63
return resultBigInt.toInt();
64
}
lib/src/screens/dashboard/pages/balance/balance_row_widget.dart
+11
-8
@@ -87,10 +87,7 @@ class BalanceRowWidget extends StatelessWidget {
87
// ],
88
),
89
child: TextButton(
90
- onPressed: () => Fluttertoast.showToast(
91
- msg: S.current.show_balance_toast,
92
- backgroundColor: Color.fromRGBO(0, 0, 0, 0.85),
93
- ),
90
+ onPressed: _showToast,
91
onLongPress: () => dashboardViewModel.balanceViewModel.switchBalanceValue(),
92
style: TextButton.styleFrom(
93
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
@@ -366,10 +363,7 @@ class BalanceRowWidget extends StatelessWidget {
363
// ],
364
),
365
child: TextButton(
369
- onPressed: () => Fluttertoast.showToast(
370
- msg: S.current.show_balance_toast,
371
- backgroundColor: Color.fromRGBO(0, 0, 0, 0.85),
372
- ),
366
+ onPressed: _showToast,
367
onLongPress: () => dashboardViewModel.balanceViewModel.switchBalanceValue(),
368
style: TextButton.styleFrom(
369
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
@@ -709,4 +703,13 @@ class BalanceRowWidget extends StatelessWidget {
703
void _showBalanceDescription(BuildContext context, String content) {
704
showPopUp<void>(context: context, builder: (_) => InformationPage(information: content));
705
}
706
+
707
+ void _showToast() async {
708
+ try {
709
+ await Fluttertoast.showToast(
710
+ msg: S.current.show_balance_toast,
711
+ backgroundColor: Color.fromRGBO(0, 0, 0, 0.85),
712
+ );
713
+ } catch (_) {}
714
+ }
715
}
lib/view_model/link_view_model.dart
+10
-8
@@ -81,14 +81,16 @@ class LinkViewModel {
81
}
82
83
Future<void> _errorToast(String message, {double fontSize = 16}) async {
84
- Fluttertoast.showToast(
85
- msg: message,
86
- toastLength: Toast.LENGTH_LONG,
87
- gravity: ToastGravity.SNACKBAR,
88
- backgroundColor: Colors.black,
89
- textColor: Colors.white,
90
- fontSize: fontSize,
91
- );
84
+ try {
85
+ await Fluttertoast.showToast(
86
+ msg: message,
87
+ toastLength: Toast.LENGTH_LONG,
88
+ gravity: ToastGravity.SNACKBAR,
89
+ backgroundColor: Colors.black,
90
+ textColor: Colors.white,
91
+ fontSize: fontSize,
92
+ );
93
+ } catch (_) {}
94
}
95
96
Future<void> handleLink() async {
macos/Podfile.lock
+7
-5
@@ -1,7 +1,6 @@
1
PODS:
2
- connectivity_plus (0.0.1):
3
- FlutterMacOS
4
- - ReachabilitySwift
4
- cw_mweb (0.0.1):
5
- FlutterMacOS
6
- device_info_plus (0.0.1):
@@ -15,6 +14,8 @@ PODS:
14
- OrderedSet (~> 6.0.3)
15
- flutter_local_authentication (1.2.0):
16
- FlutterMacOS
17
+ - flutter_local_notifications (0.0.1):
18
+ - FlutterMacOS
19
- flutter_secure_storage_macos (6.1.1):
20
- FlutterMacOS
21
- FlutterMacOS (1.0.0)
@@ -26,7 +27,6 @@ PODS:
27
- path_provider_foundation (0.0.1):
28
- Flutter
29
- FlutterMacOS
29
- - ReachabilitySwift (5.2.4)
30
- share_plus (0.0.1):
31
- FlutterMacOS
32
- shared_preferences_foundation (0.0.1):
@@ -50,6 +50,7 @@ DEPENDENCIES:
50
- fast_scanner (from `Flutter/ephemeral/.symlinks/plugins/fast_scanner/macos`)
51
- flutter_inappwebview_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos`)
52
- flutter_local_authentication (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_authentication/macos`)
53
+ - flutter_local_notifications (from `Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos`)
54
- flutter_secure_storage_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos`)
55
- FlutterMacOS (from `Flutter/ephemeral`)
56
- in_app_review (from `Flutter/ephemeral/.symlinks/plugins/in_app_review/macos`)
@@ -65,7 +66,6 @@ DEPENDENCIES:
66
SPEC REPOS:
67
trunk:
68
- OrderedSet
68
- - ReachabilitySwift
69
70
EXTERNAL SOURCES:
71
connectivity_plus:
@@ -82,6 +82,8 @@ EXTERNAL SOURCES:
82
:path: Flutter/ephemeral/.symlinks/plugins/flutter_inappwebview_macos/macos
83
flutter_local_authentication:
84
:path: Flutter/ephemeral/.symlinks/plugins/flutter_local_authentication/macos
85
+ flutter_local_notifications:
86
+ :path: Flutter/ephemeral/.symlinks/plugins/flutter_local_notifications/macos
87
flutter_secure_storage_macos:
88
:path: Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos
89
FlutterMacOS:
@@ -106,20 +108,20 @@ EXTERNAL SOURCES:
108
:path: Flutter/ephemeral/.symlinks/plugins/wakelock_plus/macos
109
110
SPEC CHECKSUMS:
109
- connectivity_plus: 18d3c32514c886e046de60e9c13895109866c747
111
+ connectivity_plus: 0a976dfd033b59192912fa3c6c7b54aab5093802
112
cw_mweb: 7440b12ead811dda972a9918442ea2a458e8742c
113
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
114
devicelocale: 9f0f36ac651cabae2c33f32dcff4f32b61c38225
115
fast_scanner: d31bae07e2653403a69dac99fb710c1722b16a97
116
flutter_inappwebview_macos: bdf207b8f4ebd58e86ae06cd96b147de99a67c9b
117
flutter_local_authentication: 85674893931e1c9cfa7c9e4f5973cb8c56b018b0
118
+ flutter_local_notifications: 4ccab5b7a22835214a6672e3f9c5e8ae207dab36
119
flutter_secure_storage_macos: d56e2d218c1130b262bef8b4a7d64f88d7f9c9ea
120
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
121
in_app_review: a6a031b9acd03c7d103e341aa334adf2c493fb93
122
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
123
package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b
124
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
122
- ReachabilitySwift: 32793e867593cfc1177f5d16491e3a197d2fccda
125
share_plus: 1fa619de8392a4398bfaf176d441853922614e89
126
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
127
sp_scanner: 269d96e0ec3173e69156be7239b95182be3b8303