dialog cleanup

This commit is contained in:
Christien Rioux 2024-08-02 23:18:39 -05:00
parent e2d57761e3
commit 1b7ac31085
11 changed files with 320 additions and 72 deletions

View File

@ -94,6 +94,7 @@
"waiting_for_network": "Waiting For Network"
},
"toast": {
"confirm": "Confirm",
"error": "Error",
"info": "Info"
},

View File

@ -137,10 +137,10 @@ class _EditAccountPageState extends WindowSetupState<EditAccountPage> {
});
}
}
} 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<EditAccountPage> {
});
}
}
} 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);
}
}
}

View File

@ -102,10 +102,10 @@ class _NewAccountPageState extends WindowSetupState<NewAccountPage> {
});
}
}
} 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);
}
}
}

View File

@ -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<HomeScreen>
Future<void> _doBetaDialog(BuildContext context) async {
var displayBetaWarning = true;
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
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>[
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<HomeScreen>
});
},
)),
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;

View File

@ -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<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<ScaleConfig>()!;
return BorderRadius.circular(8 * scaleConfig.borderRadiusScale);
}
Future<void> showErrorModal(
{required BuildContext context,
required String title,
required String text}) async {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<void> 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<void> showWarningModal(
{required BuildContext context,
required String title,
required String text}) async {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<void> showWarningWidgetModal(
{required BuildContext context,
required String title,
required Widget child}) async {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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<bool> showConfirmModal(
{required BuildContext context,
required String title,
required String text}) async {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
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;
}

View File

@ -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';

View File

@ -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<B extends StateStreamable<AsyncValue<S>>, S>
data: (d) => builder(context, d)));
}
Future<void> 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);

View File

@ -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<DeveloperPage> {
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<LogLevel>(
controller: _logLevelController,

View File

@ -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),
)
});

View File

@ -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:

View File

@ -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: