Skip to content

Commit 0d30546

Browse files
authored
TestWidgetsFlutterBinding should dispose old RestorationManager on reset. (#133999)
1 parent e08173e commit 0d30546

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/flutter_test/lib/src/binding.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
244244
/// If [registerTestTextInput] returns true when this method is called,
245245
/// the [testTextInput] is configured to simulate the keyboard.
246246
void reset() {
247+
_restorationManager?.dispose();
247248
_restorationManager = null;
248249
resetGestureBinding();
249250
testTextInput.reset();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
void main() {
8+
test('Disposes restoration manager on reset.', () {
9+
final AutomatedTestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding();
10+
int oldCounter = 0;
11+
final TestRestorationManager oldRestorationManager = binding.restorationManager;
12+
oldRestorationManager.addListener(() => oldCounter++);
13+
14+
oldRestorationManager.notifyListeners();
15+
expect(oldCounter, 1);
16+
17+
binding.reset();
18+
expect(oldRestorationManager.notifyListeners, throwsA((Object e) => e.toString().contains('disposed')));
19+
});
20+
}

0 commit comments

Comments
 (0)