fix a MaterialApp NNBD issue (#81529)
This commit is contained in:
parent
9cc8d78ec7
commit
562b6f76b3
@ -815,7 +815,7 @@ class _MaterialAppState extends State<MaterialApp> {
|
||||
return widget.builder!(context, child);
|
||||
},
|
||||
)
|
||||
: child!,
|
||||
: child ?? const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1170,7 +1170,7 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
|
||||
assert(!_usesRouter);
|
||||
_defaultRouteInformationProvider?.dispose();
|
||||
_defaultRouteInformationProvider = null;
|
||||
if (oldWidget == null || widget.navigatorKey != oldWidget.navigatorKey) {
|
||||
if (_navigator == null || widget.navigatorKey != oldWidget!.navigatorKey) {
|
||||
_navigator = widget.navigatorKey ?? GlobalObjectKey<NavigatorState>(this);
|
||||
}
|
||||
assert(_navigator != null);
|
||||
|
@ -64,6 +64,20 @@ class ElevationColor {
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/81504
|
||||
testWidgets('MaterialApp.home nullable and update test', (WidgetTester tester) async {
|
||||
// _WidgetsAppState._usesNavigator == true
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox.shrink()));
|
||||
|
||||
// _WidgetsAppState._usesNavigator == false
|
||||
await tester.pumpWidget(const MaterialApp()); // Do not crash!
|
||||
|
||||
// _WidgetsAppState._usesNavigator == true
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox.shrink())); // Do not crash!
|
||||
|
||||
expect(tester.takeException(), null);
|
||||
});
|
||||
|
||||
testWidgets('default Material debugFillProperties', (WidgetTester tester) async {
|
||||
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
|
||||
const Material().debugFillProperties(builder);
|
||||
|
Loading…
x
Reference in New Issue
Block a user