💄 Alert max width

This commit is contained in:
2025-11-24 23:01:29 +08:00
parent 98b27bed0e
commit b20d8350a8

View File

@@ -218,6 +218,8 @@ Future<T?> showOverlayDialog<T>({
return completer.future; return completer.future;
} }
const kDialogMaxWidth = 480.0;
void showErrorAlert(dynamic err) { void showErrorAlert(dynamic err) {
if (err is Error) { if (err is Error) {
talker.error('Something went wrong...', err, err.stackTrace); talker.error('Something went wrong...', err, err.stackTrace);
@@ -231,7 +233,9 @@ void showErrorAlert(dynamic err) {
showOverlayDialog<void>( showOverlayDialog<void>(
builder: builder:
(context, close) => AlertDialog( (context, close) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: kDialogMaxWidth),
child: AlertDialog(
title: Text('somethingWentWrong'.tr()), title: Text('somethingWentWrong'.tr()),
content: Text(text), content: Text(text),
actions: [ actions: [
@@ -241,13 +245,16 @@ void showErrorAlert(dynamic err) {
), ),
], ],
), ),
),
); );
} }
void showInfoAlert(String message, String title) { void showInfoAlert(String message, String title) {
showOverlayDialog<void>( showOverlayDialog<void>(
builder: builder:
(context, close) => AlertDialog( (context, close) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: kDialogMaxWidth),
child: AlertDialog(
title: Text(title), title: Text(title),
content: Text(message), content: Text(message),
actions: [ actions: [
@@ -257,19 +264,24 @@ void showInfoAlert(String message, String title) {
), ),
], ],
), ),
),
); );
} }
Future<bool> showConfirmAlert(String message, String title) async { Future<bool> showConfirmAlert(String message, String title) async {
final result = await showOverlayDialog<bool>( final result = await showOverlayDialog<bool>(
builder: builder:
(context, close) => AlertDialog( (context, close) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: kDialogMaxWidth),
child: AlertDialog(
title: Text(title), title: Text(title),
content: Text(message), content: Text(message),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => close(false), onPressed: () => close(false),
child: Text(MaterialLocalizations.of(context).cancelButtonLabel), child: Text(
MaterialLocalizations.of(context).cancelButtonLabel,
),
), ),
TextButton( TextButton(
onPressed: () => close(true), onPressed: () => close(true),
@@ -277,6 +289,7 @@ Future<bool> showConfirmAlert(String message, String title) async {
), ),
], ],
), ),
),
); );
return result ?? false; return result ?? false;
} }