diff --git a/packages/flutter/lib/src/scheduler/binding.dart b/packages/flutter/lib/src/scheduler/binding.dart index 6bad5b1c6f..7d4af952a8 100644 --- a/packages/flutter/lib/src/scheduler/binding.dart +++ b/packages/flutter/lib/src/scheduler/binding.dart @@ -391,11 +391,12 @@ mixin SchedulerBinding on BindingBase { AppLifecycleState? get lifecycleState => _lifecycleState; AppLifecycleState? _lifecycleState; - /// Allows the test framework to reset the lifecycle state back to its - /// initial value. + /// Allows the test framework to reset the lifecycle state and framesEnabled + /// back to their initial values. @visibleForTesting - void resetLifecycleState() { + void resetInternalState() { _lifecycleState = null; + _framesEnabled = true; } /// Called when the application lifecycle state changes. diff --git a/packages/flutter/test/services/lifecycle_test.dart b/packages/flutter/test/services/lifecycle_test.dart index 588cfd42c1..af25e93e24 100644 --- a/packages/flutter/test/services/lifecycle_test.dart +++ b/packages/flutter/test/services/lifecycle_test.dart @@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('initialLifecycleState is used to init state paused', (WidgetTester tester) async { final TestWidgetsFlutterBinding binding = tester.binding; - binding.resetLifecycleState(); + binding.resetInternalState(); // Use paused as the initial state. binding.platformDispatcher.initialLifecycleStateTestValue = 'AppLifecycleState.paused'; binding.readTestInitialLifecycleStateFromNativeWindow(); // Re-attempt the initialization. @@ -22,7 +22,7 @@ void main() { testWidgets('Handles all of the allowed states of AppLifecycleState', (WidgetTester tester) async { final TestWidgetsFlutterBinding binding = tester.binding; for (final AppLifecycleState state in AppLifecycleState.values) { - binding.resetLifecycleState(); + binding.resetInternalState(); binding.platformDispatcher.initialLifecycleStateTestValue = state.toString(); binding.readTestInitialLifecycleStateFromNativeWindow(); expect(ServicesBinding.instance.lifecycleState.toString(), equals(state.toString())); diff --git a/packages/flutter/test/widgets/app_lifecycle_listener_test.dart b/packages/flutter/test/widgets/app_lifecycle_listener_test.dart index b9dfc79829..9e0ec66795 100644 --- a/packages/flutter/test/widgets/app_lifecycle_listener_test.dart +++ b/packages/flutter/test/widgets/app_lifecycle_listener_test.dart @@ -43,7 +43,7 @@ void main() { listener?.dispose(); listener = null; final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.instance; - binding.resetLifecycleState(); + binding.resetInternalState(); binding.platformDispatcher.resetInitialLifecycleState(); assert(TestAppLifecycleListener.registerCount == 0, 'There were ${TestAppLifecycleListener.registerCount} listeners that were not disposed of in tests.'); diff --git a/packages/flutter/test/widgets/binding_test.dart b/packages/flutter/test/widgets/binding_test.dart index b42df5fe09..d7f7147861 100644 --- a/packages/flutter/test/widgets/binding_test.dart +++ b/packages/flutter/test/widgets/binding_test.dart @@ -397,6 +397,21 @@ void main() { await tester.pump(); }); + testWidgets('resetInternalState resets lifecycleState and framesEnabled to initial state', (WidgetTester tester) async { + // Initial state + expect(tester.binding.lifecycleState, isNull); + expect(tester.binding.framesEnabled, isTrue); + + tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused); + expect(tester.binding.lifecycleState, AppLifecycleState.paused); + expect(tester.binding.framesEnabled, isFalse); + + tester.binding.resetInternalState(); + + expect(tester.binding.lifecycleState, isNull); + expect(tester.binding.framesEnabled, isTrue); + }); + testWidgets('scheduleFrameCallback error control test', (WidgetTester tester) async { late FlutterError error; try { diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 9e77db4085..87db72f48d 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -1177,7 +1177,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase // ignore: invalid_use_of_visible_for_testing_member RendererBinding.instance.initMouseTracker(); // ignore: invalid_use_of_visible_for_testing_member - ServicesBinding.instance.resetLifecycleState(); + ServicesBinding.instance.resetInternalState(); } }