-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Flutter Web throws on Platform.is* #36126
Comments
We definitely need some better documentation describing this issue, but the gist is that |
Well, but could it don't crash at least? Or always return false? Or at least throw exception that could be caught with try/catch? Also, is there are anyway to detect running on web? |
Always returning false would be wrong though, you could very well be on an Android phone. |
See #36135 for a technique to detect running on the web |
Need to be VERY careful here. Do we want to introduce an orthogonal concept of Worth a discussion doc at the least. |
I'd vote for introducing I believe this is what we discussed WRT platform-specific code, right @jonahwilliams ? |
Note, we'd prefer disallowing importing We should be able to prevent imports for Flutter Web at least by editing Flutter's version of |
Upstream issue: |
is there any workaround for the same ? still facing the same problem. Caught error: Unsupported operation: Platform._operatingSystem |
Just want to add that this is thrown by https://pub.dev/packages/google_sign_in as well if attempted to use with the flutter web beta version 1.13.1-pre.99 |
Dupe of #50843. This adds more information to the table, but its title doesn't follow the template notation regarding web bugs, so it might get overlooked. |
Is this really a dupe? The other bug is asking about package_info, this is just about the Platform.is booleans. It's pretty crazy that our builds are blowing up just because we're trying to check a static boolean. Why can't this just be set at build time? Currently there's literally no way to check what platform you are on without blowing up on web. Which is kinda crazy for a platform aiming to be universal. |
Precisely why I think this is strange problem to have. In my very effort to support web, my stuff crashes. It might even build. I'm using janky work-arounds that depend on context instead. Very annoying to have to pass context to a static tool I built for detection that would otherwise just call this instead. In other words, I'm not using this because it breaks web support. |
fwiw, either of these packages can be used to workaround the platform detection: |
Seems strange to depend on another project for something like this. Maybe when Flutter for web is officially supported it won't be necessary. One can hope. |
use kIsWeb import 'package:flutter/foundation.dart'; if (!kIsWeb) FlutterStatusbarcolor.setStatusBarColor(Color(redLong)); //code that runs for mobile |
The issue is going the other way... if MacOS do something, or if Windows do something, you then can no longer run the codebase in the browser.
Agreed it is extremely odd to throw exceptions on a bunch of static bools, and to not simply figure out a practical solution for 2 yrs. Then again, I wrote UniversalPlatform and it works pretty good :) |
This code should help in situation when you use windows size plugin for desktop size and on web throw error "Error: Unsupported operation: Platform._operatingSystem..." in main.dart file you have to check if it is not a web mode, then check if Platform.is..:
|
We just had our web app explode because we added a EDIT: we did this with |
Any update on that? I have a web app that I need to check if I'm running it on and mobile or desktop browser |
Just ran into this myself. Indeed this should not crash. |
And actually I'm not able to create a web version of my app because some dependencies are checking Platform.isAndroid and Platform.isIOS without check kIsWeb. I think this would be important when launching flutter 2.0 with web at "stable" channel. I only have to wait for this to work on web to launch the web version. |
@FernandoUFS You can contribute to the dependencies :) |
That's why I wrote this: https://pub.dev/packages/universal_platform |
The beginner's codelab uses Platform.is* and crashes with the same error https://codelabs.developers.google.com/codelabs/flutter-boring-to-beautiful#2 It would be nice to have bug-free codelabs :) PR added at flutter/codelabs#1053 |
Reproducible on the latest versions of flutter. Updating labels flutter doctor -v
|
We did what we could on the Flutter side (#36126 (comment)). The remaining work, if any, is in the Dart SDK (see details in this closed issue: dart-lang/sdk#35969). Closing as fixed. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Using master branch
Sample code:
The text was updated successfully, but these errors were encountered: