-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathcustom_dialog.dart
180 lines (169 loc) · 5.74 KB
/
custom_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter_paystack/src/widgets/common/extensions.dart';
/// This is a modification of [AlertDialog]. A lot of modifications was made. The goal is
/// to retain the dialog feel and look while adding the close IconButton
class CustomAlertDialog extends StatelessWidget {
const CustomAlertDialog({
Key? key,
this.title,
this.titlePadding,
this.onCancelPress,
this.contentPadding = const EdgeInsets.symmetric(vertical: 10.0),
this.expanded = false,
this.fullscreen = false,
required this.content,
}) : super(key: key);
final Widget? title;
final EdgeInsetsGeometry? titlePadding;
final Widget content;
final EdgeInsetsGeometry contentPadding;
final VoidCallback? onCancelPress;
final bool expanded;
final bool fullscreen;
@override
Widget build(BuildContext context) {
final List<Widget> children = <Widget>[];
if (title != null && titlePadding != null) {
children.add(new Padding(
padding: titlePadding!,
child: new DefaultTextStyle(
style: context.textTheme().titleLarge!,
child: new Semantics(child: title, namesRoute: true),
),
));
}
children.add(new Flexible(
child: new Padding(
padding: contentPadding,
child: new DefaultTextStyle(
style: context.textTheme().titleMedium!,
child: content,
),
),
));
return buildContent(context, children);
}
Widget buildContent(context, List<Widget> children) {
Widget widget;
if (fullscreen) {
widget = new Material(
child: new Container(
child: onCancelPress == null
? new Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 20.0,
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children),
)
: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.topRight,
child: new IconButton(
icon: new Icon(Icons.close),
onPressed: onCancelPress,
color: Colors.black54,
padding: const EdgeInsets.all(15.0),
iconSize: 30.0,
),
),
new Expanded(
child: new Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: new Column(
children: children,
),
))
],
)),
);
} else {
var body = new Material(
type: MaterialType.card,
borderRadius: new BorderRadius.circular(10.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
),
);
var child = new IntrinsicWidth(
child: onCancelPress == null
? body
: new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
new Container(
margin: const EdgeInsets.all(10.0),
child: new IconButton(
highlightColor: Colors.white54,
splashColor: Colors.white54,
color: Colors.white,
iconSize: 30.0,
padding: const EdgeInsets.all(3.0),
icon: const Icon(
Icons.cancel,
),
onPressed: onCancelPress),
),
new Flexible(child: body),
],
),
);
widget = new CustomDialog(child: child, expanded: expanded);
}
return widget;
}
}
/// This is a modification of [Dialog]. The only modification is increasing the
/// elevation and changing the Material type.
class CustomDialog extends StatelessWidget {
const CustomDialog({
Key? key,
required this.child,
required this.expanded,
this.insetAnimationDuration = const Duration(milliseconds: 100),
this.insetAnimationCurve = Curves.decelerate,
}) : super(key: key);
final Widget child;
final Duration insetAnimationDuration;
final Curve insetAnimationCurve;
final bool expanded;
@override
Widget build(BuildContext context) {
return new AnimatedPadding(
padding: MediaQuery.of(context).viewInsets +
const EdgeInsets.symmetric(horizontal: 20.0, vertical: 24.0),
duration: insetAnimationDuration,
curve: insetAnimationCurve,
child: new MediaQuery.removeViewInsets(
removeLeft: true,
removeTop: true,
removeRight: true,
removeBottom: true,
context: context,
child: new Center(
child: new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: expanded
? math.min(
(MediaQuery.of(context).size.width - 40.0), 332.0)
: 280.0),
child: new Material(
elevation: 50.0,
type: MaterialType.transparency,
child: child,
),
),
),
),
);
}
}