You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
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:
The text was updated successfully, but these errors were encountered: