Commit 63b034e6 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Showing the material grid shouldn't lose app state (#4857)

Previously adding the GridPaper caused us to lose all the state in our app. Now
we use a global key to keep our state.

Fixes #4648
parent b2576dc0
......@@ -175,6 +175,7 @@ class _MaterialAppState extends State<MaterialApp> {
Widget result = new AnimatedTheme(
data: theme,
child: new WidgetsApp(
key: new GlobalObjectKey(this),
title: config.title,
textStyle: _errorTextStyle,
color: theme?.primaryColor ?? Colors.blue[500], // blue[500] is the primary color of the default theme
......
......@@ -5,6 +5,26 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
class StateMarker extends StatefulWidget {
StateMarker({ Key key, this.child }) : super(key: key);
final Widget child;
@override
StateMarkerState createState() => new StateMarkerState();
}
class StateMarkerState extends State<StateMarker> {
String marker;
@override
Widget build(BuildContext context) {
if (config.child != null)
return config.child;
return new Container();
}
}
void main() {
testWidgets('Can nest apps', (WidgetTester tester) async {
await tester.pumpWidget(
......@@ -30,4 +50,26 @@ void main() {
expect(Focus.at(inputKey.currentContext), isTrue);
});
testWidgets('Can show grid without losing sync', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new StateMarker()
)
);
StateMarkerState state1 = tester.state(find.byType(StateMarker));
state1.marker = 'original';
await tester.pumpWidget(
new MaterialApp(
debugShowMaterialGrid: true,
home: new StateMarker()
)
);
StateMarkerState state2 = tester.state(find.byType(StateMarker));
expect(state1, equals(state2));
expect(state2.marker, equals('original'));
});
}
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