Pub Package


A cross-platform dart:io that works in VM/Flutter, browsers, and elsewhere.

Licensed under the Apache License 2.0. Much of the source code was adopted from the original 'dart:io' in Dart SDK, which was licensed under a BSD-style license (license terms of Dart SDK can be found in the source code files that were derived from Dart SDK).

Dart SDK 2.5

  • Upcoming Dart SDK 2.5 has major breaking changes in dart:io. Supporting them means that we had to introduce breaking changes in this package.
  • If you use Dart SDK 2.4 or less, you should use version constraint ^0.7.3.


Similar packages

Getting started

1.Add a dependency

Dart SDK 2.5.0-dev-1.0 and above

In pubspec.yaml:

  universal_io: ^0.8.1

Dart SDK 2.4.x and above

In pubspec.yaml:

  universal_io: ^0.7.3

2. Choose a driver (optional)


  • Library "package:universal_io/io.dart" will automatically export dart:io for you.


  • BrowserIODriver is automatically used when you use Dart2js / devc. This is possible with "conditional imports" feature of Dart.
  • The driver implements HttpClient (with restrictions) and a few other features. If you need features such as sockets or unrestricted HTTP connections, choose one of the options below.

Chrome OS App?

3. Use

import 'package:universal_io/io.dart';

void main() async {
  // Use 'dart:io' HttpClient API.
  final httpClient = new HttpClient();
  final request = await httpClient.getUrl(Uri.parse(""));
  final response = await request.close();


Default driver behavior

HTTP client

In browser, HTTP client is implemented using dart:html HttpRequest, which uses XmlHttpRequest.

Unlike HTTP client in the standard dart:io, the browser implementation sends HTTP request only after httpRequest.close() has been called.

If a cross-origin request fails, error message contains a detailed description how to fix possible issues like missing cross-origin headers. The error messages look like:

BrowserHttpClient received an error from XMLHttpRequest (which doesn't tell
reason for the error).

HTTP method:   PUT

Cross-origin request!
CORS 'credentials' mode is disabled (the browser will not send authentication like cookies).
You can enable 'credentials' mode with: request.headers.set('Authorization', "someValue")

Did the server send the following mandatory headers?
  * Access-Control-Allow-Origin:
    * OR '*'
  * Access-Control-Allow-Methods: PUT


  • Requires sockets.


  • In browser, variables are determined by browser APIs such as navigator.userAgent.
  • Elsewhere (e.g. Node.JS), appears like Linux environment.


  • Any attempt to use these APIs will throw UnimplementedError.


  • Any attempt to use these APIs will throw UnimplementedError.

Writing your own driver?

import 'package:universal_io/io.dart';
import 'package:universal_io/driver.dart';
import 'package:universal_io/driver_base.dart';

void main() {

/// Let's change 'Platform' implementation (in browser).
final exampleIODriver = IODriver(
  platformDriver: PlatformDriver(localeName:"en-US"),


Cross-platform implementation of 'dart:io'.
API for dart:io drivers.
Useful classes and functions for implementing dart:io drivers.