diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 545490b836..b871056808 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -244,6 +244,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase /// If [registerTestTextInput] returns true when this method is called, /// the [testTextInput] is configured to simulate the keyboard. void reset() { + _restorationManager?.dispose(); _restorationManager = null; resetGestureBinding(); testTextInput.reset(); diff --git a/packages/flutter_test/test/bindings_reset_test.dart b/packages/flutter_test/test/bindings_reset_test.dart new file mode 100644 index 0000000000..57dee32204 --- /dev/null +++ b/packages/flutter_test/test/bindings_reset_test.dart @@ -0,0 +1,20 @@ +// 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_test/flutter_test.dart'; + +void main() { + test('Disposes restoration manager on reset.', () { + final AutomatedTestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding(); + int oldCounter = 0; + final TestRestorationManager oldRestorationManager = binding.restorationManager; + oldRestorationManager.addListener(() => oldCounter++); + + oldRestorationManager.notifyListeners(); + expect(oldCounter, 1); + + binding.reset(); + expect(oldRestorationManager.notifyListeners, throwsA((Object e) => e.toString().contains('disposed'))); + }); +}