Properly initialize RestorationManager in the TestBinding (#70398)
This commit is contained in:
parent
c7f092515c
commit
cca1215939
@ -301,7 +301,9 @@ class _RootRestorationScopeState extends State<RootRestorationScope> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
if (_rootBucketValid) {
|
||||||
ServicesBinding.instance!.restorationManager.removeListener(_replaceRootBucket);
|
ServicesBinding.instance!.restorationManager.removeListener(_replaceRootBucket);
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,13 +189,16 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
|||||||
final TestWindow _window;
|
final TestWindow _window;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TestRestorationManager get restorationManager => _restorationManager;
|
TestRestorationManager get restorationManager {
|
||||||
late TestRestorationManager _restorationManager;
|
_restorationManager ??= createRestorationManager();
|
||||||
|
return _restorationManager!;
|
||||||
|
}
|
||||||
|
TestRestorationManager? _restorationManager;
|
||||||
|
|
||||||
/// Called by the test framework at the beginning of a widget test to
|
/// Called by the test framework at the beginning of a widget test to
|
||||||
/// prepare the binding for the next test.
|
/// prepare the binding for the next test.
|
||||||
void reset() {
|
void reset() {
|
||||||
_restorationManager = createRestorationManager();
|
_restorationManager = null;
|
||||||
resetGestureBinding();
|
resetGestureBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
packages/flutter_test/test/bindings_restoration_test.dart
Normal file
13
packages/flutter_test/test/bindings_restoration_test.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('Can access restoration manager without crashing', () {
|
||||||
|
final AutomatedTestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding();
|
||||||
|
expect(binding.restorationManager, isA<RestorationManager>());
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user