Line data Source code
1 : part of 'foss_dialog.dart';
2 :
3 : /// {@category Overlays}
4 : /// {@template foss.alert-dialog.preview}
5 : /// <img src="https://fossui.org/components/alert-dialog/overview/light.png"
6 : /// alt="FossAlertDialog, light theme" width="480"
7 : /// style="max-width:100%;height:auto" />
8 : /// <img src="https://fossui.org/components/alert-dialog/overview/dark.png"
9 : /// alt="FossAlertDialog, dark theme" width="480"
10 : /// style="max-width:100%;height:auto" />
11 : ///
12 : /// See the [alert dialog documentation ↗](https://fossui.org/docs/components/alert-dialog) or
13 : /// try it live in the
14 : /// [playground ↗](https://play.fossui.org/components/#/?path=components/dialog/fossalertdialog/playground).
15 : /// {@endtemplate}
16 : ///
17 : /// A non-dismissible modal that interrupts to require a decision.
18 : ///
19 : /// The dialog's stricter sibling: it composes a [FossDialog] with the alert
20 : /// configuration locked (no close affordance and a required, non-empty
21 : /// [actions] footer). Show it with [showFossAlertDialog].
22 : /// Colors, type, radius, and shadow come from `context.fossTheme`.
23 : ///
24 : /// {@macro foss.customize}
25 : ///
26 : /// See also [FossDialog] for a dismissible modal with the same slots.
27 : ///
28 : /// ```dart
29 : /// showFossAlertDialog<void>(
30 : /// context: context,
31 : /// builder: (context) => FossAlertDialog(
32 : /// title: const Text('Session expired'),
33 : /// actions: [
34 : /// FossButton(
35 : /// onPressed: () => Navigator.pop(context),
36 : /// child: const Text('Sign in'),
37 : /// ),
38 : /// ],
39 : /// ),
40 : /// );
41 : /// ```
42 : class FossAlertDialog extends StatelessWidget {
43 : /// {@macro foss.alert-dialog.preview}
44 : ///
45 : /// Creates an alert dialog. [actions] must be non-empty: a non-dismissible
46 : /// dialog needs a way out.
47 1 : const FossAlertDialog({
48 : required this.actions,
49 : this.title,
50 : this.description,
51 : this.content,
52 : this.footerVariant = FossDialogFooterVariant.filled,
53 : this.semanticLabel,
54 : this.style,
55 : super.key,
56 : // isNotEmpty is not const-evaluable in a const constructor; length works.
57 3 : }) : assert(actions.length > 0, 'An alert dialog needs at least one action.');
58 :
59 : /// The footer actions; at least one is required.
60 : final List<Widget> actions;
61 :
62 : /// The title, at the top of the header.
63 : final Widget? title;
64 :
65 : /// The description, below the title.
66 : final Widget? description;
67 :
68 : /// An optional scrollable body between the header and the footer.
69 : final Widget? content;
70 :
71 : /// The footer treatment. Defaults to [FossDialogFooterVariant.filled].
72 : final FossDialogFooterVariant footerVariant;
73 :
74 : /// Names the modal route for assistive technology. Defaults to the [title]
75 : /// text when it is a [Text].
76 : final String? semanticLabel;
77 :
78 : /// Per-instance visual overrides.
79 : final FossAlertDialogStyle? style;
80 :
81 1 : @override
82 : Widget build(BuildContext context) {
83 1 : return _buildDialogSurface(
84 : context,
85 1 : title: title,
86 1 : description: description,
87 1 : content: content,
88 1 : actions: actions,
89 1 : footerVariant: footerVariant,
90 1 : presentation: _DialogPresentationScope.of(context),
91 1 : semanticLabel: semanticLabel,
92 1 : style: style,
93 : closeButton: null,
94 : );
95 : }
96 : }
|