File tree Expand file tree Collapse file tree 5 files changed +23
-7
lines changed Expand file tree Collapse file tree 5 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -391,11 +391,12 @@ mixin SchedulerBinding on BindingBase {
391391 AppLifecycleState ? get lifecycleState => _lifecycleState;
392392 AppLifecycleState ? _lifecycleState;
393393
394- /// Allows the test framework to reset the lifecycle state back to its
395- /// initial value .
394+ /// Allows the test framework to reset the lifecycle state and framesEnabled
395+ /// back to their initial values .
396396 @visibleForTesting
397- void resetLifecycleState () {
397+ void resetInternalState () {
398398 _lifecycleState = null ;
399+ _framesEnabled = true ;
399400 }
400401
401402 /// Called when the application lifecycle state changes.
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
1010void main () {
1111 testWidgets ('initialLifecycleState is used to init state paused' , (WidgetTester tester) async {
1212 final TestWidgetsFlutterBinding binding = tester.binding;
13- binding.resetLifecycleState ();
13+ binding.resetInternalState ();
1414 // Use paused as the initial state.
1515 binding.platformDispatcher.initialLifecycleStateTestValue = 'AppLifecycleState.paused' ;
1616 binding.readTestInitialLifecycleStateFromNativeWindow (); // Re-attempt the initialization.
@@ -22,7 +22,7 @@ void main() {
2222 testWidgets ('Handles all of the allowed states of AppLifecycleState' , (WidgetTester tester) async {
2323 final TestWidgetsFlutterBinding binding = tester.binding;
2424 for (final AppLifecycleState state in AppLifecycleState .values) {
25- binding.resetLifecycleState ();
25+ binding.resetInternalState ();
2626 binding.platformDispatcher.initialLifecycleStateTestValue = state.toString ();
2727 binding.readTestInitialLifecycleStateFromNativeWindow ();
2828 expect (ServicesBinding .instance.lifecycleState.toString (), equals (state.toString ()));
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ void main() {
4343 listener? .dispose ();
4444 listener = null ;
4545 final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding .instance;
46- binding.resetLifecycleState ();
46+ binding.resetInternalState ();
4747 binding.platformDispatcher.resetInitialLifecycleState ();
4848 assert (TestAppLifecycleListener .registerCount == 0 ,
4949 'There were ${TestAppLifecycleListener .registerCount } listeners that were not disposed of in tests.' );
Original file line number Diff line number Diff line change @@ -397,6 +397,21 @@ void main() {
397397 await tester.pump ();
398398 });
399399
400+ testWidgets ('resetInternalState resets lifecycleState and framesEnabled to initial state' , (WidgetTester tester) async {
401+ // Initial state
402+ expect (tester.binding.lifecycleState, isNull);
403+ expect (tester.binding.framesEnabled, isTrue);
404+
405+ tester.binding.handleAppLifecycleStateChanged (AppLifecycleState .paused);
406+ expect (tester.binding.lifecycleState, AppLifecycleState .paused);
407+ expect (tester.binding.framesEnabled, isFalse);
408+
409+ tester.binding.resetInternalState ();
410+
411+ expect (tester.binding.lifecycleState, isNull);
412+ expect (tester.binding.framesEnabled, isTrue);
413+ });
414+
400415 testWidgets ('scheduleFrameCallback error control test' , (WidgetTester tester) async {
401416 late FlutterError error;
402417 try {
Original file line number Diff line number Diff line change @@ -1177,7 +1177,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
11771177 // ignore: invalid_use_of_visible_for_testing_member
11781178 RendererBinding .instance.initMouseTracker ();
11791179 // ignore: invalid_use_of_visible_for_testing_member
1180- ServicesBinding .instance.resetLifecycleState ();
1180+ ServicesBinding .instance.resetInternalState ();
11811181 }
11821182}
11831183
You can’t perform that action at this time.
0 commit comments