-
Notifications
You must be signed in to change notification settings - Fork 32
/
yaru_alert_dialog.dart
80 lines (68 loc) · 2.41 KB
/
yaru_alert_dialog.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'package:flutter/material.dart';
import '../constants.dart';
import 'yaru_dialog_title.dart';
class YaruAlertDialog extends StatelessWidget {
const YaruAlertDialog({
super.key,
required this.title,
required this.child,
this.closeIconData,
this.alignment,
this.width,
this.height,
this.titleTextAlign,
this.actions,
this.contentPadding = EdgeInsets.zero,
this.scrollable = false,
});
/// The title of the dialog, displayed in a large font at the top of the [YaruDialogTitle].
final String title;
/// The icon used inside the close button
final IconData? closeIconData;
/// The child displayed underneath the title. It comes without any padding
/// or [ScrollView] so one has the full freedom to put anything inside.
final Widget child;
/// How to align the [Dialog] on the Screen.
///
/// If null, then [DialogTheme.alignment] is used. If that is also null, the
/// default is [Alignment.center].
final AlignmentGeometry? alignment;
/// The width of the dialog which can be provided and constraints all children with the same width.
///
/// Default is [kYaruPageWidth]
final double? width;
/// The optional height of the dialog which can be provided to limit the height
/// of the [SingleChildScrollView] where the [children] are placed.
final double? height;
/// Optional [TextAlign] used for the [YaruDialogTitle]
final TextAlign? titleTextAlign;
/// A [List] of [Widget] - typically [OutlinedButton], [ElevatedButton] or [TextButton]
final List<Widget>? actions;
/// Padding around the [content]
///
/// Defaults to [EdgeInsets.zero]
final EdgeInsetsGeometry contentPadding;
/// Forwards the [scrollable] flag to the [AlertDialog]
final bool? scrollable;
@override
Widget build(BuildContext context) {
return SizedBox(
width: width ?? kYaruPageWidth,
child: AlertDialog(
actionsPadding: const EdgeInsets.all(kYaruPagePadding / 2),
contentPadding: contentPadding,
scrollable: scrollable ?? false,
titlePadding: EdgeInsets.zero,
title: YaruDialogTitle(
mainAxisAlignment: MainAxisAlignment.start,
textAlign: titleTextAlign,
title: title,
closeIconData: closeIconData ?? Icons.close,
),
content: SizedBox(height: height, width: width, child: child),
actions: actions,
alignment: alignment,
),
);
}
}