A Flutter app that works on Android fails in the browser with Platform._operatingSystem
Fix it fast
Most common cause, 1 of 4Your code reads Platform.isAndroid or a similar getter on web
Test kIsWeb first so the Platform getter is never reached in the browser.
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
// safe on every platform: && stops before Platform is read on web
final bool isAndroidApp = !kIsWeb && Platform.isAndroid;
// no dart:io at all
final bool androidStyle = defaultTargetPlatform == TargetPlatform.android;Short answer
Unsupported operation: Platform._operatingSystem means a Flutter web build (Flutter 3.50, Dart 3.14) read dart:io Platform, which is only a throwing stub in the browser. Check kIsWeb before Platform.isAndroid or isIOS, or use defaultTargetPlatform. For picked files on web, read the XFile bytes and upload them with putData instead of building a dart:io File.
Which cause do you have?
Run the app in Chrome in debug mode so the stack trace is readable, then search lib for every place that imports dart:io. The first frame of the trace that sits in your own code tells you which of those places runs on web.
flutter run -d chrome
grep -rn "dart:io" libThen find the line you see in this list and open its fix:
- 1Your code reads Platform.isAndroid or a similar getter on web
The first frame in the stack trace is in your lib folder, on a line that uses Platform - 2A picked file is wrapped in a dart:io File for upload or display
The failure comes when an image is picked, shown or sent to Firebase Storage, and the stack trace runs through File or putFile - 3Shared code needs real dart:io features on mobile
The same file must keep using File or Directory on Android and iOS, and the kIsWeb checks in it keep multiplying - 4A package you depend on reads Platform without web support
The top frames of the stack trace sit under packages/<name>/ rather than in your lib folder
What does the error look like?
Unsupported operation: Platform._operatingSystemUnsupported operation: Platform._pathSeparatorThe same code runs on Android and iOS without any error
Cause 1 of 4
Your code reads Platform.isAndroid or a similar getter on web
You seeThe first frame in the stack trace is in your lib folder, on a line that uses Platform
Check
Unsupported operation: Platform._operatingSystem is thrown the moment your own code reads Platform.isAndroid, isIOS or operatingSystem in the browser. Every Platform.isX getter compares against Platform.operatingSystem, and the web build of dart:io throws as soon as that value is asked for. A check in main, or in code that builds the first screen, stops the app before anything shows.
grep -rnE "Platform\.(is[A-Za-z]+|operatingSystem)" libFix
Test kIsWeb first so the Platform getter is never reached in the browser. For layout or theme choices, defaultTargetPlatform from package:flutter/foundation.dart needs no dart:io at all; on web it reflects the platform of the browser.
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
// safe on every platform: && stops before Platform is read on web
final bool isAndroidApp = !kIsWeb && Platform.isAndroid;
// no dart:io at all
final bool androidStyle = defaultTargetPlatform == TargetPlatform.android;Verify
Hot restart in Chrome. The app starts, and the Android build still takes the Android branch.
flutter run -d chromeConfirmed by api.flutter.dev
Cause 2 of 4
A picked file is wrapped in a dart:io File for upload or display
You seeThe failure comes when an image is picked, shown or sent to Firebase Storage, and the stack trace runs through File or putFile
Check
Uploads and previews break on web when a picked image is wrapped in a dart:io File, because dart:io is not available to browser apps. On web, image_picker returns an XFile whose path is a blob URL inside the browser, not a file on disk. Look for File(...) built from a picked path.
grep -rn "File(" lib | grep -i "path"Fix
Keep the XFile and read its bytes, which works on every platform. Upload the bytes with putData, and show the image with Image.memory.
final XFile? picked = await ImagePicker().pickImage(source: ImageSource.gallery);
if (picked != null) {
final Uint8List bytes = await picked.readAsBytes();
await storageRef.putData(bytes); // storageRef: a Reference from FirebaseStorage
// preview: Image.memory(bytes)
}Verify
Pick and upload an image in Chrome, then confirm the object appears in the Storage bucket in the Firebase console.
flutter run -d chromeConfirmed by firebase.google.com
Cause 3 of 4
Shared code needs real dart:io features on mobile
You seeThe same file must keep using File or Directory on Android and iOS, and the kIsWeb checks in it keep multiplying
Check
Platform errors keep coming back in shared code that needs the file system on mobile, because runtime checks leave dart:io calls in code the browser also loads. List the files that import dart:io and see which of them web screens use.
grep -rln "dart:io" libFix
Split the code into two files with the same API and let Dart pick one at compile time with a conditional export. The dart.library.io branch is chosen where dart:io exists, the dart.library.js_interop branch on web.
// lib/storage/local_store.dart
export 'local_store_stub.dart'
if (dart.library.io) 'local_store_io.dart'
if (dart.library.js_interop) 'local_store_web.dart';Verify
Build for both targets; each build compiles and uses its own implementation.
flutter build web
flutter build apkConfirmed by dart.dev
Cause 4 of 4
A package you depend on reads Platform without web support
You seeThe top frames of the stack trace sit under packages/<name>/ rather than in your lib folder
Check
Unsupported operation: Platform._operatingSystem with its top stack frames under packages/<name>/ means a dependency reads Platform and does not support web. pub.dev lists the platforms each package supports, detected on publish or declared in the package's pubspec. Open the package page and look for Web among them.
flutter pub deps | grep <package-name>Fix
Upgrade to a version that lists web, switch to a package that does, or call that package only behind a kIsWeb check so the browser build never runs it.
# raise the package version in pubspec.yaml, then
flutter pub upgrade
# or keep the call off the web build
if (!kIsWeb) { /* call the mobile-only package here */ }Verify
Run in Chrome again and confirm the stack trace no longer points into that package.
flutter run -d chromeConfirmed by dart.dev
How do I stop it coming back?
- Click through the main flows with flutter run -d chrome before each release when web is a target.
- Keep dart:io imports in a few files behind one conditional export, so other code never touches Platform.
- Check for the Web tag on a package's pub.dev page before adding it to an app that ships on web.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: SessionBird, Workforce, Spotless Laundry.