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

Consider eliminating public static references #21

Closed
matthew-carroll opened this issue Jun 16, 2020 · 2 comments · Fixed by #47
Closed

Consider eliminating public static references #21

matthew-carroll opened this issue Jun 16, 2020 · 2 comments · Fixed by #47
Labels
enhancement New feature or request

Comments

@matthew-carroll
Copy link
Contributor

I just submitted a PR with some new functionality for this package. In the process of extending this package and attempting to write tests, I noticed that this package relies on static members to query and notify clients of keyboard changes.

I would like to suggest migrating away from public static members.

Static members often interfere with testing practices. This is especially true for plugins where a connection is expected with the platform side. Such a connection is not easily faked.

In my PR I introduced a pretty ugly hack to facilitate a few simple tests. This was the result of those public static members.

An alternative to public static members is to provide only a singleton reference at the static level. For example:

final KeyboardVisibility keyboardVisibility = KeyboardVisibility.instance;
print('Is visible: ${keyboardVisibility.isVisible}');

With a singleton instance, one can replace the entire instance with a fake instance within tests. This avoids polluting the primary API surface with methods that should only be invoked during tests. It also lowers the likelihood that someone will inadvertently invoke a test method during production.

You can see this practice within Flutter if you look at bindings, for example:

WidgetsBinding.instance;
ServicesBinding.instance;
@tuononh
Copy link

tuononh commented Jun 16, 2020

Does this package even works? I just tried latest version 3.0.0 and it is not working on Android ☹️

@matthew-carroll
Copy link
Contributor Author

@tuononh looks like that issue is discussed here: #19

@MisterJimson MisterJimson added the enhancement New feature or request label Jun 17, 2020
@MisterJimson MisterJimson mentioned this issue Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants