dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

[Platform.is*] Using of Platform.isAndroid or Platform.isIOS should either be deprecated or documentation should be clear #50895

Open AbhishekDoshi26 opened 1 year ago

AbhishekDoshi26 commented 1 year ago

We all know that using Platform.isAndroid and Platform.isIOS crashes on web because these constants lie inside dart:io which is not supported for web and many times no one really checks which file was imported due to the usage of something.

But, many less experienced developers keep on using these for multi-platform apps because they are habitual to use it. We already have an alternative i.e. to lay down the if-else such that it checks for web first. Or, we can also use defaultTargetPlatform == TargetPlatform.android as this works on all platforms.

I propose either of the following:

This will really help developers to not make silly mistakes of using Platform.is* in multi-platform projects.

Note: Opened similar issue in dart-lang repo too.

mraleph commented 1 year ago

/cc @lrhn @mit-mit

stuartmorgan commented 1 year ago

See https://github.com/dart-lang/io/issues/93#issuecomment-1371372964 for some issues with the claims here.

(Filing three copies of the same issue in different repositories makes discussion really difficult; please just pick one location in the future.)

mraleph commented 1 year ago

Ping @mit-mit @lrhn. Do we have an issue somewhere which reflects our plans for platform detection improvements? I would like to either label this issue or close it in favor of existing issue.