108 lines
2.7 KiB
Dart
108 lines
2.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:please_pay_me/ui/atoms/app_text.dart';
|
|
|
|
/// Native iOS alert.
|
|
class AppAlert extends StatelessWidget {
|
|
const AppAlert({
|
|
super.key,
|
|
required this.title,
|
|
this.message,
|
|
this.confirmLabel = 'OK',
|
|
this.cancelLabel,
|
|
this.destructive = false,
|
|
});
|
|
|
|
final String title;
|
|
final String? message;
|
|
final String confirmLabel;
|
|
final String? cancelLabel;
|
|
final bool destructive;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoAlertDialog(
|
|
title: AppText.headline(title),
|
|
content: message == null
|
|
? null
|
|
: Padding(
|
|
padding: const EdgeInsets.only(top: 6),
|
|
child: AppText.subhead(message!, textAlign: TextAlign.center),
|
|
),
|
|
actions: [
|
|
if (cancelLabel != null)
|
|
CupertinoDialogAction(
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
child: Text(cancelLabel!),
|
|
),
|
|
CupertinoDialogAction(
|
|
isDefaultAction: !destructive,
|
|
isDestructiveAction: destructive,
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
child: Text(confirmLabel),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<bool?> showAppAlert({
|
|
required BuildContext context,
|
|
required String title,
|
|
String? message,
|
|
String confirmLabel = 'OK',
|
|
String? cancelLabel,
|
|
bool destructive = false,
|
|
}) {
|
|
return showCupertinoDialog<bool>(
|
|
context: context,
|
|
builder: (_) => AppAlert(
|
|
title: title,
|
|
message: message,
|
|
confirmLabel: confirmLabel,
|
|
cancelLabel: cancelLabel,
|
|
destructive: destructive,
|
|
),
|
|
);
|
|
}
|
|
|
|
class AppActionSheetAction {
|
|
const AppActionSheetAction({
|
|
required this.label,
|
|
this.destructive = false,
|
|
this.isDefault = false,
|
|
});
|
|
|
|
final String label;
|
|
final bool destructive;
|
|
final bool isDefault;
|
|
}
|
|
|
|
Future<int?> showAppActionSheet({
|
|
required BuildContext context,
|
|
String? title,
|
|
String? message,
|
|
required List<AppActionSheetAction> actions,
|
|
String cancelLabel = 'Отмена',
|
|
}) {
|
|
return showCupertinoModalPopup<int>(
|
|
context: context,
|
|
builder: (ctx) => CupertinoActionSheet(
|
|
title: title == null ? null : Text(title),
|
|
message: message == null ? null : Text(message),
|
|
actions: [
|
|
for (var i = 0; i < actions.length; i++)
|
|
CupertinoActionSheetAction(
|
|
isDestructiveAction: actions[i].destructive,
|
|
isDefaultAction: actions[i].isDefault,
|
|
onPressed: () => Navigator.of(ctx).pop(i),
|
|
child: Text(actions[i].label),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.of(ctx).pop(),
|
|
child: Text(cancelLabel),
|
|
),
|
|
),
|
|
);
|
|
}
|