From 0d30546c74afb2fdb648aa6dce5ad2ae1a28f43b Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Thu, 7 Sep 2023 17:49:33 -0700 Subject: [PATCH] TestWidgetsFlutterBinding should dispose old RestorationManager on reset. (#133999) --- packages/flutter_test/lib/src/binding.dart | 1 + .../test/bindings_reset_test.dart | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/flutter_test/test/bindings_reset_test.dart 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'))); + }); +}