Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience accessor for primaryFocus #43859

Merged
merged 2 commits into from Nov 1, 2019

Conversation

@gspencergoog
Copy link
Contributor

gspencergoog commented Oct 30, 2019

Description

This adds accessors for WidgetsBinding.instance.focusManager and WidgetsBinding.instance.focusManager.primaryFocus so that they can be more easily found in IDEs and accessed.

This adds a top level getter for WidgetsBinding.instance.focusManager.primaryFocus called primaryFocus, and a static accessor FocusManager.instance that returns WidgetsBinding.instance.focusManager.

Tests

  • Modified tests to use the accessors.

Breaking Change

  • No, this is not a breaking change.
Copy link
Contributor

darrenaustin left a comment

Other than my concern about using the global namespace, this LGTM.

@@ -1418,6 +1424,14 @@ class FocusManager with DiagnosticableTreeMixin {
}
}

/// Provides convenient access to the current [FocusManager] from the
/// [WidgetsBinding] instance.
FocusManager get focusManager => WidgetsBinding.instance.focusManager;

This comment has been minimized.

Copy link
@darrenaustin

darrenaustin Oct 30, 2019

Contributor

Looks good. Did you consider using a static method on FocusManager instead of a top-level getter here? Do we have other top-level globals like this? Is there any concern about name clashing with existing app code for either of these?

This comment has been minimized.

Copy link
@gspencergoog

gspencergoog Oct 31, 2019

Author Contributor

Well, I did consider a static, but it would have had to have a different name (because primaryFocus is taken), and it's pretty useful at the top level. There are other top level globals like these: imageCache, and defaultTargetPlatform to name a couple. Like any new name, It could clash, of course, but I don't think it's very likely to clash.

However, I think I will convert the focusManager one to a static FocusManager.instance so that it appears as the singleton that it is (but still get it internally from the WidgetsBinding.instance.focusManager). That way it's one less thing to clash.

This comment has been minimized.

Copy link
@darrenaustin

darrenaustin Oct 31, 2019

Contributor

If we already have a precedence for top level names, this is probably not a big deal. Pragmatically speaking I doubt there would be much collision. I prefer not using global namespaces, but this case maybe useful enough to do so.

Or given that you already changed it to FocusManager.instance while I was typing this :), never-mind.

@gspencergoog gspencergoog changed the title Add convenience accessors for focusManager, primaryFocus Add convenience accessors for primaryFocus Oct 31, 2019
@gspencergoog gspencergoog changed the title Add convenience accessors for primaryFocus Add convenience accessor for primaryFocus Oct 31, 2019
@gspencergoog gspencergoog merged commit 3a30722 into flutter:master Nov 1, 2019
100 checks passed
100 checks passed
add_to_app_tests-macos Task Summary
Details
WIP Ready for review
Details
add_to_app_tests-macos
Details
analyze-linux Task Summary
Details
analyze-linux
Details
build_tests-linux Task Summary
Details
build_tests-linux
Details
build_tests-macos Task Summary
Details
build_tests-macos
Details
build_tests-windows Task Summary
Details
build_tests-windows
Details
cla/google All necessary CLAs are signed
customer_testing-linux Task Summary
Details
customer_testing-linux
Details
customer_testing-macos Task Summary
Details
customer_testing-macos
Details
customer_testing-windows Task Summary
Details
customer_testing-windows
Details
deploy_gallery-linux Task Summary
Details
deploy_gallery-linux
Details
deploy_gallery-macos Task Summary
Details
deploy_gallery-macos
Details
docs-linux Task Summary
Details
docs-linux
Details
firebase_test_lab_tests-linux Task Summary
Details
firebase_test_lab_tests-linux
Details
flutter-build
Details
framework_tests-libraries-linux Task Summary
Details
framework_tests-libraries-linux
Details
framework_tests-libraries-macos Task Summary
Details
framework_tests-libraries-macos
Details
framework_tests-libraries-windows Task Summary
Details
framework_tests-libraries-windows
Details
framework_tests-misc-linux Task Summary
Details
framework_tests-misc-linux
Details
framework_tests-misc-macos Task Summary
Details
framework_tests-misc-macos
Details
framework_tests-misc-windows Task Summary
Details
framework_tests-misc-windows
Details
framework_tests-widgets-linux Task Summary
Details
framework_tests-widgets-linux
Details
framework_tests-widgets-macos Task Summary
Details
framework_tests-widgets-macos
Details
framework_tests-widgets-windows Task Summary
Details
framework_tests-widgets-windows
Details
hostonly_devicelab_tests-0-linux Task Summary
Details
hostonly_devicelab_tests-0-linux
Details
hostonly_devicelab_tests-0-macos Task Summary
Details
hostonly_devicelab_tests-0-macos
Details
hostonly_devicelab_tests-0-windows Task Summary
Details
hostonly_devicelab_tests-0-windows
Details
hostonly_devicelab_tests-1-linux Task Summary
Details
hostonly_devicelab_tests-1-linux
Details
hostonly_devicelab_tests-1-macos Task Summary
Details
hostonly_devicelab_tests-1-macos
Details
hostonly_devicelab_tests-1-windows Task Summary
Details
hostonly_devicelab_tests-1-windows
Details
hostonly_devicelab_tests-2-linux Task Summary
Details
hostonly_devicelab_tests-2-linux
Details
hostonly_devicelab_tests-2-macos Task Summary
Details
hostonly_devicelab_tests-2-macos
Details
hostonly_devicelab_tests-2-windows Task Summary
Details
hostonly_devicelab_tests-2-windows
Details
hostonly_devicelab_tests-3_last-linux Task Summary
Details
hostonly_devicelab_tests-3_last-linux
Details
hostonly_devicelab_tests-3_last-macos Task Summary
Details
hostonly_devicelab_tests-3_last-macos
Details
hostonly_devicelab_tests-3_last-windows Task Summary
Details
hostonly_devicelab_tests-3_last-windows
Details
tool_tests-commands-linux Task Summary
Details
tool_tests-commands-linux
Details
tool_tests-commands-macos Task Summary
Details
tool_tests-commands-macos
Details
tool_tests-commands-windows Task Summary
Details
tool_tests-commands-windows
Details
tool_tests-general-linux Task Summary
Details
tool_tests-general-linux
Details
tool_tests-general-macos Task Summary
Details
tool_tests-general-macos
Details
tool_tests-general-windows Task Summary
Details
tool_tests-general-windows
Details
tool_tests-integration-linux Task Summary
Details
tool_tests-integration-linux
Details
tool_tests-integration-macos Task Summary
Details
tool_tests-integration-macos
Details
tool_tests-integration-windows Task Summary
Details
tool_tests-integration-windows
Details
web_tests-0-linux Task Summary
Details
web_tests-0-linux
Details
web_tests-1-linux Task Summary
Details
web_tests-1-linux
Details
web_tests-2-linux Task Summary
Details
web_tests-2-linux
Details
web_tests-3-linux Task Summary
Details
web_tests-3-linux
Details
web_tests-4-linux Task Summary
Details
web_tests-4-linux
Details
web_tests-5-linux Task Summary
Details
web_tests-5-linux
Details
web_tests-6-linux Task Summary
Details
@gspencergoog gspencergoog deleted the gspencergoog:primary_focus_getter branch Nov 13, 2019
sahandevs added a commit to sahandevs/flutter that referenced this pull request Nov 15, 2019
This adds accessors for WidgetsBinding.instance.focusManager and WidgetsBinding.instance.focusManager.primaryFocus so that they can be more easily found in IDEs and accessed.

This adds a top level getter for WidgetsBinding.instance.focusManager.primaryFocus called primaryFocus, and a static accessor FocusManager.instance that returns WidgetsBinding.instance.focusManager.
sahandevs added a commit to sahandevs/flutter that referenced this pull request Nov 15, 2019
This adds accessors for WidgetsBinding.instance.focusManager and WidgetsBinding.instance.focusManager.primaryFocus so that they can be more easily found in IDEs and accessed.

This adds a top level getter for WidgetsBinding.instance.focusManager.primaryFocus called primaryFocus, and a static accessor FocusManager.instance that returns WidgetsBinding.instance.focusManager.
sahandevs added a commit to sahandevs/flutter that referenced this pull request Nov 15, 2019
Inconnu08 added a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
This adds accessors for WidgetsBinding.instance.focusManager and WidgetsBinding.instance.focusManager.primaryFocus so that they can be more easily found in IDEs and accessed.

This adds a top level getter for WidgetsBinding.instance.focusManager.primaryFocus called primaryFocus, and a static accessor FocusManager.instance that returns WidgetsBinding.instance.focusManager.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.