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
Add Platform.isWeb #79413
Comments
import 'dart:io';
import 'package:flutter/foundation.dart';
extension PlatformHelpers on Platform {
static bool isWeb => kIsWeb;
} |
Of course, if you make it not constant it won't tree shake |
Maybe we could add a similar extension somewhere in the SDK? Maybe in https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/foundation/platform.dart? extension PlatformHelpers on Platform {
static const bool isWeb = kIsWeb;
} |
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-using-extension But we should totally do this as part of the work for making |
The Platform class getters are not constants, so using them is strictly worse than constants in cases where you do have platform specific code. We don't actually have any built in support for identifiers like |
I think it's probably easier for users to keep using I'm not 100% what the ideal API looks like, as discussed in the doc related to #39998 there are different scenarios where it's best to use |
Not that it is faster, but that it allows tree-shaking to work. |
We should make Platform.isFoo const anyway. FWIW, |
Concerning kIsWeb, I feel like its implementation is a bit of a code smell.
Couldn't conditional imports provide a more robust solution?
|
The kIsWeb constant is the only way to check if the app is running on the web. It would be great if we could recommend something like
Platform.isWeb
(alongsideisLinux
,isIOS
, etc.)If it's not possible to achieve in the framework due to #39998 we could consider adding it to
package:platform
Related issues:
The text was updated successfully, but these errors were encountered: