Unverified Commit 3bbb8d8b authored by MH Johnson's avatar MH Johnson Committed by GitHub

[Material] Fix showDialog crasher caused by old contexts (#30754)

* Fix bug, add regression test.

* remove unnecessary space
parent 42d3464d
...@@ -700,11 +700,12 @@ Future<T> showDialog<T>({ ...@@ -700,11 +700,12 @@ Future<T> showDialog<T>({
}) { }) {
assert(child == null || builder == null); assert(child == null || builder == null);
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
return showGeneralDialog( return showGeneralDialog(
context: context, context: context,
pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
final ThemeData theme = Theme.of(context, shadowThemeOnly: true); final Widget pageChild = child ?? Builder(builder: builder);
final Widget pageChild = child ?? Builder(builder: builder);
return SafeArea( return SafeArea(
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
......
...@@ -607,4 +607,42 @@ void main() { ...@@ -607,4 +607,42 @@ void main() {
expect(find.text('0'), findsNothing); expect(find.text('0'), findsNothing);
expect(find.text('1'), findsNothing); expect(find.text('1'), findsNothing);
}); });
// Regression test for https://github.com/flutter/flutter/issues/28505.
testWidgets('showDialog only gets Theme from context on the first call', (WidgetTester tester) async {
Widget buildFrame(Key builderKey) {
return MaterialApp(
home: Center(
child: Builder(
key: builderKey,
builder: (BuildContext outerContext) {
return RaisedButton(
onPressed: () {
showDialog<void>(
context: outerContext,
builder: (BuildContext innerContext) {
return const AlertDialog(title: Text('Title'));
},
);
},
child: const Text('Show Dialog'),
);
},
),
),
);
}
await tester.pumpWidget(buildFrame(UniqueKey()));
// Open the dialog.
await tester.tap(find.byType(RaisedButton));
await tester.pumpAndSettle();
// Force the Builder to be recreated (new key) which causes outerContext to
// be deactivated. If showDialog()'s implementation were to refer to
// outerContext again, it would crash.
await tester.pumpWidget(buildFrame(UniqueKey()));
await tester.pump();
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment