From 1b7ac31085d4ad6117c4a28e28e150a0bfe114ea Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 2 Aug 2024 23:18:39 -0500 Subject: [PATCH] dialog cleanup --- assets/i18n/en.json | 1 + .../views/edit_account_page.dart | 12 +- .../views/new_account_page.dart | 6 +- lib/layout/home/home_screen.dart | 24 +- lib/theme/views/styled_alert.dart | 276 ++++++++++++++++++ lib/theme/views/views.dart | 1 + lib/theme/views/widget_helpers.dart | 14 - lib/veilid_processor/views/developer.dart | 30 +- .../views/signal_strength_meter.dart | 8 +- pubspec.lock | 18 +- pubspec.yaml | 2 +- 11 files changed, 320 insertions(+), 72 deletions(-) create mode 100644 lib/theme/views/styled_alert.dart diff --git a/assets/i18n/en.json b/assets/i18n/en.json index b2e6907..cb95eaf 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -94,6 +94,7 @@ "waiting_for_network": "Waiting For Network" }, "toast": { + "confirm": "Confirm", "error": "Error", "info": "Info" }, diff --git a/lib/account_manager/views/edit_account_page.dart b/lib/account_manager/views/edit_account_page.dart index e49b48a..eaa0e37 100644 --- a/lib/account_manager/views/edit_account_page.dart +++ b/lib/account_manager/views/edit_account_page.dart @@ -137,10 +137,10 @@ class _EditAccountPageState extends WindowSetupState { }); } } - } on Exception catch (e) { + } on Exception catch (e, st) { if (mounted) { - await showErrorModal( - context, translate('new_account_page.error'), 'Exception: $e'); + await showErrorStacktraceModal( + context: context, error: e, stackTrace: st); } } } @@ -205,10 +205,10 @@ class _EditAccountPageState extends WindowSetupState { }); } } - } on Exception catch (e) { + } on Exception catch (e, st) { if (mounted) { - await showErrorModal( - context, translate('new_account_page.error'), 'Exception: $e'); + await showErrorStacktraceModal( + context: context, error: e, stackTrace: st); } } } diff --git a/lib/account_manager/views/new_account_page.dart b/lib/account_manager/views/new_account_page.dart index ee2f62c..69c75ae 100644 --- a/lib/account_manager/views/new_account_page.dart +++ b/lib/account_manager/views/new_account_page.dart @@ -102,10 +102,10 @@ class _NewAccountPageState extends WindowSetupState { }); } } - } on Exception catch (e) { + } on Exception catch (e, st) { if (mounted) { - await showErrorModal( - context, translate('new_account_page.error'), 'Exception: $e'); + await showErrorStacktraceModal( + context: context, error: e, stackTrace: st); } } } diff --git a/lib/layout/home/home_screen.dart b/lib/layout/home/home_screen.dart index 893ca97..a90e110 100644 --- a/lib/layout/home/home_screen.dart +++ b/lib/layout/home/home_screen.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_translate/flutter_translate.dart'; import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart'; import 'package:provider/provider.dart'; -import 'package:quickalert/quickalert.dart'; import 'package:transitioned_indexed_stack/transitioned_indexed_stack.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:veilid_support/veilid_support.dart'; @@ -63,25 +62,26 @@ class HomeScreenState extends State Future _doBetaDialog(BuildContext context) async { var displayBetaWarning = true; + final theme = Theme.of(context); + final scale = theme.extension()!; - await QuickAlert.show( + await showWarningWidgetModal( context: context, title: translate('splash.beta_title'), - widget: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ + child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ RichText( textAlign: TextAlign.center, text: TextSpan( children: [ TextSpan( text: translate('splash.beta_text'), - style: const TextStyle( - color: Colors.black87, - ), + style: theme.textTheme.bodyMedium! + .copyWith(color: scale.primaryScale.appText), ), TextSpan( text: 'https://veilid.com/chat/beta', - style: const TextStyle( - color: Colors.blue, + style: theme.textTheme.bodyMedium!.copyWith( + color: scale.primaryScale.primary, decoration: TextDecoration.underline, ), recognizer: TapGestureRecognizer() @@ -101,11 +101,13 @@ class HomeScreenState extends State }); }, )), - Text(translate('settings_page.display_beta_warning'), - style: const TextStyle(color: Colors.black)), + Text( + translate('settings_page.display_beta_warning'), + style: theme.textTheme.bodyMedium! + .copyWith(color: scale.primaryScale.appText), + ), ]), ]), - type: QuickAlertType.warning, ); final preferencesInstance = PreferencesRepository.instance; diff --git a/lib/theme/views/styled_alert.dart b/lib/theme/views/styled_alert.dart new file mode 100644 index 0000000..2104fa1 --- /dev/null +++ b/lib/theme/views/styled_alert.dart @@ -0,0 +1,276 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_translate/flutter_translate.dart'; +import 'package:rflutter_alert/rflutter_alert.dart'; + +import '../theme.dart'; + +AlertStyle _alertStyle(BuildContext context) { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + return AlertStyle( + animationType: AnimationType.grow, + //animationDuration: const Duration(milliseconds: 200), + alertBorder: RoundedRectangleBorder( + side: !scaleConfig.useVisualIndicators + ? BorderSide.none + : BorderSide( + strokeAlign: BorderSide.strokeAlignCenter, + color: scale.primaryScale.border, + width: 2), + borderRadius: BorderRadius.all( + Radius.circular(12 * scaleConfig.borderRadiusScale))), + // isButtonVisible: true, + // isCloseButton: true, + // isOverlayTapDismiss: true, + backgroundColor: scale.primaryScale.subtleBackground, + // overlayColor: Colors.black87, + titleStyle: theme.textTheme.titleMedium! + .copyWith(color: scale.primaryScale.appText), + // titleTextAlign: TextAlign.center, + descStyle: + theme.textTheme.bodyMedium!.copyWith(color: scale.primaryScale.appText), + // descTextAlign: TextAlign.center, + // buttonAreaPadding: const EdgeInsets.all(20.0), + // constraints: null, + // buttonsDirection: ButtonsDirection.row, + // alertElevation: null, + // alertPadding: defaultAlertPadding, + // alertAlignment: Alignment.center, + // isTitleSelectable: false, + // isDescSelectable: false, + // titlePadding: null, + //descPadding: const EdgeInsets.all(0.0), + ); +} + +Color _buttonColor(BuildContext context, bool highlight) { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + if (scaleConfig.useVisualIndicators && !scaleConfig.preferBorders) { + return scale.secondaryScale.border; + } + + return highlight + ? scale.secondaryScale.elementBackground + : scale.secondaryScale.hoverElementBackground; +} + +TextStyle _buttonTextStyle(BuildContext context) { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + if (scaleConfig.useVisualIndicators && !scaleConfig.preferBorders) { + return theme.textTheme.bodyMedium! + .copyWith(color: scale.secondaryScale.borderText); + } + + return theme.textTheme.bodyMedium! + .copyWith(color: scale.secondaryScale.appText); +} + +BoxBorder _buttonBorder(BuildContext context) { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + return Border.fromBorderSide(BorderSide( + color: scale.secondaryScale.border, + width: scaleConfig.preferBorders ? 2 : 0)); +} + +BorderRadius _buttonRadius(BuildContext context) { + final theme = Theme.of(context); + final scaleConfig = theme.extension()!; + + return BorderRadius.circular(8 * scaleConfig.borderRadiusScale); +} + +Future showErrorModal( + {required BuildContext context, + required String title, + required String text}) async { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + await Alert( + context: context, + style: _alertStyle(context), + useRootNavigator: false, + type: AlertType.error, + //style: AlertStyle(), + title: title, + desc: text, + buttons: [ + DialogButton( + color: _buttonColor(context, false), + highlightColor: _buttonColor(context, true), + border: _buttonBorder(context), + radius: _buttonRadius(context), + width: 120, + onPressed: () { + Navigator.pop(context); + }, + child: Text( + translate('button.ok'), + style: _buttonTextStyle(context), + ), + ) + ], + + //backgroundColor: Colors.black, + //titleColor: Colors.white, + //textColor: Colors.white, + ).show(); +} + +Future showErrorStacktraceModal( + {required BuildContext context, + required Object error, + StackTrace? stackTrace}) async { + await showErrorModal( + context: context, + title: translate('toast.error'), + text: 'Error: {e}\n StackTrace: {st}', + ); +} + +Future showWarningModal( + {required BuildContext context, + required String title, + required String text}) async { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + await Alert( + context: context, + style: _alertStyle(context), + useRootNavigator: false, + type: AlertType.warning, + //style: AlertStyle(), + title: title, + desc: text, + buttons: [ + DialogButton( + color: _buttonColor(context, false), + highlightColor: _buttonColor(context, true), + border: _buttonBorder(context), + radius: _buttonRadius(context), + width: 120, + onPressed: () { + Navigator.pop(context); + }, + child: Text( + translate('button.ok'), + style: _buttonTextStyle(context), + ), + ) + ], + + //backgroundColor: Colors.black, + //titleColor: Colors.white, + //textColor: Colors.white, + ).show(); +} + +Future showWarningWidgetModal( + {required BuildContext context, + required String title, + required Widget child}) async { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + await Alert( + context: context, + style: _alertStyle(context), + useRootNavigator: false, + type: AlertType.warning, + //style: AlertStyle(), + title: title, + content: child, + buttons: [ + DialogButton( + color: _buttonColor(context, false), + highlightColor: _buttonColor(context, true), + border: _buttonBorder(context), + radius: _buttonRadius(context), + width: 120, + onPressed: () { + Navigator.pop(context); + }, + child: Text( + translate('button.ok'), + style: _buttonTextStyle(context), + ), + ) + ], + + //backgroundColor: Colors.black, + //titleColor: Colors.white, + //textColor: Colors.white, + ).show(); +} + +Future showConfirmModal( + {required BuildContext context, + required String title, + required String text}) async { + final theme = Theme.of(context); + final scale = theme.extension()!; + final scaleConfig = theme.extension()!; + + var confirm = false; + + await Alert( + context: context, + style: _alertStyle(context), + useRootNavigator: false, + type: AlertType.none, + title: title, + desc: text, + buttons: [ + DialogButton( + color: _buttonColor(context, false), + highlightColor: _buttonColor(context, true), + border: _buttonBorder(context), + radius: _buttonRadius(context), + width: 120, + onPressed: () { + Navigator.pop(context); + }, + child: Text( + translate('button.no_cancel'), + style: _buttonTextStyle(context), + ), + ), + DialogButton( + color: _buttonColor(context, false), + highlightColor: _buttonColor(context, true), + border: _buttonBorder(context), + radius: _buttonRadius(context), + width: 120, + onPressed: () { + confirm = true; + Navigator.pop(context); + }, + child: Text( + translate('button.yes_proceed'), + style: _buttonTextStyle(context), + ), + ) + ], + + //backgroundColor: Colors.black, + //titleColor: Colors.white, + //textColor: Colors.white, + ).show(); + + return confirm; +} diff --git a/lib/theme/views/views.dart b/lib/theme/views/views.dart index b81f184..e8aa1d8 100644 --- a/lib/theme/views/views.dart +++ b/lib/theme/views/views.dart @@ -8,6 +8,7 @@ export 'pop_control.dart'; export 'recovery_key_widget.dart'; export 'responsive.dart'; export 'scanner_error_widget.dart'; +export 'styled_alert.dart'; export 'styled_dialog.dart'; export 'styled_scaffold.dart'; export 'widget_helpers.dart'; diff --git a/lib/theme/views/widget_helpers.dart b/lib/theme/views/widget_helpers.dart index b079d2b..51cb7b6 100644 --- a/lib/theme/views/widget_helpers.dart +++ b/lib/theme/views/widget_helpers.dart @@ -8,7 +8,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_sticky_header/flutter_sticky_header.dart'; -import 'package:quickalert/quickalert.dart'; import 'package:sliver_expandable/sliver_expandable.dart'; import '../theme.dart'; @@ -196,19 +195,6 @@ class AsyncBlocBuilder>, S> data: (d) => builder(context, d))); } -Future showErrorModal( - BuildContext context, String title, String text) async { - await QuickAlert.show( - context: context, - type: QuickAlertType.error, - title: title, - text: text, - //backgroundColor: Colors.black, - //titleColor: Colors.white, - //textColor: Colors.white, - ); -} - SliverAppBar styledSliverAppBar( {required BuildContext context, required String title, Color? titleColor}) { final theme = Theme.of(context); diff --git a/lib/veilid_processor/views/developer.dart b/lib/veilid_processor/views/developer.dart index f4fe836..549d228 100644 --- a/lib/veilid_processor/views/developer.dart +++ b/lib/veilid_processor/views/developer.dart @@ -12,7 +12,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_translate/flutter_translate.dart'; import 'package:go_router/go_router.dart'; import 'package:loggy/loggy.dart'; -import 'package:quickalert/quickalert.dart'; import 'package:veilid_support/veilid_support.dart'; import 'package:xterm/xterm.dart'; @@ -208,27 +207,14 @@ class _DeveloperPageState extends State { color: scale.primaryScale.primaryText, disabledColor: scale.primaryScale.primaryText.withAlpha(0x3F), onPressed: () async { - await QuickAlert.show( - context: context, - type: QuickAlertType.confirm, - title: translate('developer.are_you_sure_clear'), - titleColor: scale.primaryScale.appText, - textColor: scale.primaryScale.subtleText, - confirmBtnColor: scale.primaryScale.primary, - cancelBtnTextStyle: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 18, - color: scale.primaryScale.appText), - backgroundColor: scale.primaryScale.appBackground, - headerBackgroundColor: scale.primaryScale.primary, - confirmBtnText: translate('button.ok'), - cancelBtnText: translate('button.cancel'), - onConfirmBtnTap: () async { - Navigator.pop(context); - if (context.mounted) { - await clear(context); - } - }); + final confirm = await showConfirmModal( + context: context, + title: translate('toast.confirm'), + text: translate('developer.are_you_sure_clear'), + ); + if (confirm && context.mounted) { + await clear(context); + } }), CoolDropdown( controller: _logLevelController, diff --git a/lib/veilid_processor/views/signal_strength_meter.dart b/lib/veilid_processor/views/signal_strength_meter.dart index 73842f1..74230ed 100644 --- a/lib/veilid_processor/views/signal_strength_meter.dart +++ b/lib/veilid_processor/views/signal_strength_meter.dart @@ -4,7 +4,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; -import 'package:quickalert/quickalert.dart'; import 'package:signal_strength_indicator/signal_strength_indicator.dart'; import 'package:veilid_support/veilid_support.dart'; @@ -75,11 +74,8 @@ class SignalStrengthMeterWidget extends StatelessWidget { loading: () => {iconWidget = const Icon(Icons.warning)}, error: (e, st) => { iconWidget = const Icon(Icons.error).onTap( - () async => QuickAlert.show( - type: QuickAlertType.error, - context: context, - title: 'Error', - text: 'Error: {e}\n StackTrace: {st}'), + () async => showErrorStacktraceModal( + context: context, error: e, stackTrace: st), ) }); diff --git a/pubspec.lock b/pubspec.lock index 2e8947c..d4f1ce7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1193,14 +1193,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" - quickalert: - dependency: "direct main" - description: - name: quickalert - sha256: b5d62b1e20b08cc0ff5f40b6da519bdc7a5de6082f13d90572cf4e72eea56c5e - url: "https://pub.dev" - source: hosted - version: "1.1.0" quiver: dependency: transitive description: @@ -1225,6 +1217,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.10" + rflutter_alert: + dependency: "direct main" + description: + name: rflutter_alert + sha256: "8ff35e3f9712ba24c746499cfa95bf320385edf38901a1a4eab0fe555867f66c" + url: "https://pub.dev" + source: hosted + version: "2.0.7" rxdart: dependency: transitive description: @@ -1702,7 +1702,7 @@ packages: path: "../veilid/veilid-flutter" relative: true source: path - version: "0.3.3" + version: "0.3.4" veilid_support: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 653396f..fe464ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -76,9 +76,9 @@ dependencies: provider: ^6.1.2 qr_code_dart_scan: ^0.8.0 qr_flutter: ^4.1.0 - quickalert: ^1.1.0 radix_colors: ^1.0.4 reorderable_grid: ^1.0.10 + rflutter_alert: ^2.0.7 screenshot: ^3.0.0 scroll_to_index: ^3.0.1 searchable_listview: