-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Update advice for platform detection #5929
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
Conversation
The general tone of this advice is good, but it unnecessarily complicates things, since it adds a dependency on a third-party package that doesn't have a stable null-safe version, when all that is needed is to flip the order so that Dart can short-circuit execution. I've also removed the macOS example, because the use of RTL to reorder buttons seems dangerous. I've not tested this, but I suspect this may have other side-effects. For example, this code assumes that the default platform is LTR, so may have opposite results on an Arabic or Hebrew workstation.
/cc @esDotDev, who I think was the original page author? |
Hey Tim, From our experience, it tends to be much nicer/simpler to just remove this sharp edge from the equation and have nice safe API you can call in any order. Which is why we recommended just using the plugin, saves the users some pain that they will almost surely experience if they have to rely on comparison order to prevent RTE's. I am the original author of Button Order We could run some tests to try and confirm this if you like. I'd be more in favor of adding a caveat to this effect, than removing the discussion entirely, as this is one of the key differences between OS's that will immediately make an app feel weird if it's wrong. With all that said, happy to proceed as you wish, just wanted to flesh out the rationale behind some of these sections. |
Thanks Shawn! Appreciate the fast feedback.
|
Hey Tim,
fwiw, you can see basically the entire package here, and how simple it really is: https://github.com/gskinnerTeam/flutter-universal-platform/blob/master/lib/universal_platform.dart Regarding the short circuit is brittle thing:
Maybe best approach is to just recommend a little static class/package, with methods similar to what you have there, and then recommend developers use a utility class rather than reference Platform directly? But flesh it out with all the API you may want to use, in a safe way:
The nice thing about a package here though, is it really is pretty annoying to have to copy and paste these little snippet classes from project to project. Ideally the "best" approach would be to remove this rough edge from the SDK somehow, but not sure if there are any plans for that: flutter/flutter#36126
|
I should confess, when I wrote this lib 16mths ago, I had no idea that short-circuiting like this would work, so I wrote it with conditional imports, which I guess I didn't need at all :p |
I really like your idea -- include a slightly broader list of properties that folk can cut and paste directly into the code, and then reference a package that adds a nice bow on the top for those who just want to rely on a module. That way we both educate people (which fundamentally is the point of documentation) as well as giving them practical options. Thanks for checking on the button thing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The general tone of this advice is good, but it unnecessarily complicates things, since it adds a dependency on a third-party package that doesn't have a stable null-safe version, when all that is needed is to flip the order so that Dart can short-circuit execution.
I've also removed the macOS example, because the use of RTL to reorder buttons seems dangerous. I've not tested this, but I suspect this may have other side-effects. For example, this code assumes that the default platform is LTR, so may have opposite results on an Arabic or Hebrew workstation.