Add barrierDismissable argument to showDialog (#8397)
In some situations, dialogs don't want the barrier to be dismissable. Fixes #8354
This commit is contained in:
parent
b592868249
commit
76394630ac
@ -316,9 +316,12 @@ class SimpleDialog extends StatelessWidget {
|
||||
|
||||
class _DialogRoute<T> extends PopupRoute<T> {
|
||||
_DialogRoute({
|
||||
this.child,
|
||||
this.theme,
|
||||
});
|
||||
@required this.theme,
|
||||
bool barrierDismissable: true,
|
||||
@required this.child,
|
||||
}) : _barrierDismissable = barrierDismissable {
|
||||
assert(barrierDismissable != null);
|
||||
}
|
||||
|
||||
final Widget child;
|
||||
final ThemeData theme;
|
||||
@ -327,7 +330,8 @@ class _DialogRoute<T> extends PopupRoute<T> {
|
||||
Duration get transitionDuration => const Duration(milliseconds: 150);
|
||||
|
||||
@override
|
||||
bool get barrierDismissable => true;
|
||||
bool get barrierDismissable => _barrierDismissable;
|
||||
final bool _barrierDismissable;
|
||||
|
||||
@override
|
||||
Color get barrierColor => Colors.black54;
|
||||
@ -364,10 +368,12 @@ class _DialogRoute<T> extends PopupRoute<T> {
|
||||
/// * <https://material.google.com/components/dialogs.html>
|
||||
Future<T> showDialog<T>({
|
||||
@required BuildContext context,
|
||||
@required Widget child
|
||||
bool barrierDismissable: true,
|
||||
@required Widget child,
|
||||
}) {
|
||||
return Navigator.push(context, new _DialogRoute<T>(
|
||||
child: child,
|
||||
theme: Theme.of(context, shadowThemeOnly: true),
|
||||
barrierDismissable: barrierDismissable,
|
||||
));
|
||||
}
|
||||
|
@ -137,4 +137,61 @@ void main() {
|
||||
|
||||
expect(await result, equals(42));
|
||||
});
|
||||
|
||||
testWidgets('Barrier dismissable', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new MaterialApp(
|
||||
home: new Material(
|
||||
child: new Center(
|
||||
child: new RaisedButton(
|
||||
onPressed: null,
|
||||
child: new Text('Go'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
BuildContext context = tester.element(find.text('Go'));
|
||||
|
||||
showDialog<Null>(
|
||||
context: context,
|
||||
child: new Container(
|
||||
width: 100.0,
|
||||
height: 100.0,
|
||||
alignment: FractionalOffset.center,
|
||||
child: new Text('Dialog1'),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1));
|
||||
expect(find.text('Dialog1'), findsOneWidget);
|
||||
|
||||
// Tap on the barrier.
|
||||
await tester.tapAt(const Point(10.0, 10.0));
|
||||
|
||||
await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1));
|
||||
expect(find.text('Dialog1'), findsNothing);
|
||||
|
||||
showDialog<Null>(
|
||||
context: context,
|
||||
barrierDismissable: false,
|
||||
child: new Container(
|
||||
width: 100.0,
|
||||
height: 100.0,
|
||||
alignment: FractionalOffset.center,
|
||||
child: new Text('Dialog2'),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1));
|
||||
expect(find.text('Dialog2'), findsOneWidget);
|
||||
|
||||
// Tap on the barrier, which shouldn't do anything this time.
|
||||
await tester.tapAt(const Point(10.0, 10.0));
|
||||
|
||||
await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1));
|
||||
expect(find.text('Dialog2'), findsOneWidget);
|
||||
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user