Did you know?
If your code checks the current platform with Platform.isIOS
, you’ll get a runtime exception when you run on Flutter web. 💥
As an alternative, consider using the Universal Platform package, which works on all platforms and offers a unified syntax. 👍
Note that the UniversalPlatform
class has two drawbacks:
- It doesn't (yet) support tree-shaking of the conditional code (see issue #29 for details)
- The platform can't be overridden during testing (see issue #15 for details)
If you don't want to rely on a 3rd party package to perform platform checks, see my next tip about defaultTargetPlatform
and kIsWeb
.
Happy coding!