Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Flutter and app store releases

A Flutter app that works on Android fails in the browser with Platform._operatingSystem

Your error

Unsupported operation: Platform._operatingSystem2 more lines it can show

Fix it fast

Most common cause, 1 of 4

Your code reads Platform.isAndroid or a similar getter on web

Test kIsWeb first so the Platform getter is never reached in the browser.

Fix
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;
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to Flutter 3.50 stable, Dart 3.14, image_picker 1.2, firebase_storage 14
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
flutter run -d chrome
grep -rn "dart:io" lib

Then find the line you see in this list and open its fix:

  1. 1Your code reads Platform.isAndroid or a similar getter on webThe first frame in the stack trace is in your lib folder, on a line that uses Platform
  2. 2A picked file is wrapped in a dart:io File for upload or displayThe failure comes when an image is picked, shown or sent to Firebase Storage, and the stack trace runs through File or putFile
  3. 3Shared code needs real dart:io features on mobileThe same file must keep using File or Directory on Android and iOS, and the kIsWeb checks in it keep multiplying
  4. 4A package you depend on reads Platform without web supportThe 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._operatingSystem
  • Unsupported operation: Platform._pathSeparator
  • The 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.

Check
grep -rnE "Platform\.(is[A-Za-z]+|operatingSystem)" lib

Fix

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.

Fix
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.

Verify
flutter run -d chrome

Confirmed by api.flutter.dev

Did this fix it?

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.

Check
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.

Fix
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.

Verify
flutter run -d chrome

Confirmed by firebase.google.com

Did this fix it?

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.

Check
grep -rln "dart:io" lib

Fix

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.

Fix
// 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.

Verify
flutter build web
flutter build apk

Confirmed by dart.dev

Did this fix it?

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.

Check
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.

Fix
# 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.

Verify
flutter run -d chrome

Confirmed by dart.dev

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.