mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-23 22:51:00 -04:00
dialog cleanup
This commit is contained in:
parent
e2d57761e3
commit
1b7ac31085
11 changed files with 320 additions and 72 deletions
276
lib/theme/views/styled_alert.dart
Normal file
276
lib/theme/views/styled_alert.dart
Normal 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;
|
||||
}
|
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue