SelectionArea's selection should not be cleared on loss of window focus (#148067)

This change fixes an issue where SelectionArea would clear its selection when the application window lost focus by first checking if the application is running. This is needed because `FocusManager` is aware of the application lifecycle as of https://github.com/flutter/flutter/pull/142930 , and triggers a focus lost if the application is not active.

Also fixes an issue where the `FocusManager` was not being reset on tests at the right time, causing it always to build with `TargetPlatform.android` as its context.
This commit is contained in:
Renzo Olivares
2024-05-20 16:45:08 -07:00
committed by GitHub
parent 722c8d62fd
commit 5890a2fc73
6 changed files with 96 additions and 3 deletions

View File

@@ -254,6 +254,14 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
_testTextInput.register();
}
CustomSemanticsAction.resetForTests(); // ignore: invalid_use_of_visible_for_testing_member
_enableFocusManagerLifecycleAwarenessIfSupported();
}
void _enableFocusManagerLifecycleAwarenessIfSupported() {
if (buildOwner == null) {
return;
}
buildOwner!.focusManager.listenToApplicationLifecycleChangesIfSupported(); // ignore: invalid_use_of_visible_for_testing_member
}
@override

View File

@@ -174,11 +174,11 @@ void testWidgets(
test_package.addTearDown(binding.postTest);
return binding.runTest(
() async {
binding.reset(); // TODO(ianh): the binding should just do this itself in _runTest
debugResetSemanticsIdCounter();
Object? memento;
try {
memento = await variant.setUp(value);
binding.reset(); // TODO(ianh): the binding should just do this itself in _runTest
maybeSetupLeakTrackingForTest(experimentalLeakTesting, combinedDescription);
await callback(tester);
} finally {