Fix handling of AppLifecycleState.hidden (#127987)
## Description This fixes the parsing of `AppLifecycleState` in the services binding so that it knows what it is. ## Related Issues - Fixes https://github.com/flutter/flutter/issues/127974 ## Tests - Added a test that causes parsing of all the different app lifecycle states.
This commit is contained in:
parent
5fd9ef4240
commit
a257efc284
@ -376,6 +376,13 @@ mixin SchedulerBinding on BindingBase {
|
||||
AppLifecycleState? get lifecycleState => _lifecycleState;
|
||||
AppLifecycleState? _lifecycleState;
|
||||
|
||||
/// Allows the test framework to reset the lifecycle state back to its
|
||||
/// initial value.
|
||||
@visibleForTesting
|
||||
void resetLifecycleState() {
|
||||
_lifecycleState = null;
|
||||
}
|
||||
|
||||
/// Called when the application lifecycle state changes.
|
||||
///
|
||||
/// Notifies all the observers using
|
||||
|
@ -285,6 +285,8 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
|
||||
return AppLifecycleState.resumed;
|
||||
case 'AppLifecycleState.inactive':
|
||||
return AppLifecycleState.inactive;
|
||||
case 'AppLifecycleState.hidden':
|
||||
return AppLifecycleState.hidden;
|
||||
case 'AppLifecycleState.paused':
|
||||
return AppLifecycleState.paused;
|
||||
case 'AppLifecycleState.detached':
|
||||
|
@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@ -20,4 +22,13 @@ void main() {
|
||||
// even though no lifecycle event was fired from the platform.
|
||||
expect(ServicesBinding.instance.lifecycleState.toString(), equals('AppLifecycleState.paused'));
|
||||
});
|
||||
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.platformDispatcher.initialLifecycleStateTestValue = state.toString();
|
||||
binding.readTestInitialLifecycleStateFromNativeWindow();
|
||||
expect(ServicesBinding.instance.lifecycleState.toString(), equals(state.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1150,6 +1150,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
keyEventManager.clearState();
|
||||
// ignore: invalid_use_of_visible_for_testing_member
|
||||
RendererBinding.instance.initMouseTracker();
|
||||
// ignore: invalid_use_of_visible_for_testing_member
|
||||
ServicesBinding.instance.resetLifecycleState();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user