Skip to content
pubscout

universal_io

2.3.1, released a year ago by dint.dev

Cross-platform dart:io implementation with browser support for HttpClient and other APIs

$ flutter pub add universal_io
Source repository

What it does

Provides a drop-in replacement for 'dart:io' that works across all platforms including web browsers. It implements a WASM-compatible BrowserHttpClient using XMLHttpRequest on the web, and adds cross-platform support for Platform, InternetAddress, and BytesBuilder.

AI-written summary of version 2.3.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need a shared codebase using 'dart:io' APIs that must compile and run on both native platforms and the web
  • You need to make HTTP requests using HttpClient inside a web browser environment

Skip it when

  • You are writing a native-only application where standard 'dart:io' is fully sufficient
  • You prefer dedicated HTTP abstraction libraries like 'http' or 'dio

Strengths

  • Enables seamless sharing of code depending on 'dart:io' with web targets
  • Provides helpful error messages and troubleshooting hints for browser XHR errors and CORS issues
  • WASM-compatible using dart:js_interop

Weaknesses

  • Subject to browser limitations such as same-origin policy and CORS restrictions
  • Behavior of underlying network requests differs slightly on the web due to XMLHttpRequest limitations

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
3

Simply replace 'dart:io' imports with 'package:universal_io/universal_io.dart'.

import 'package:universal_io/universal_io.dart';

Future<void> main() async {
  final httpClient = newUniversalHttpClient();
  final request = await httpClient.getUrl(Uri.parse("https://dart.dev/"));
  final response = await request.close();
}

Alternatives

Packages that do the same job and could replace universal_io.

Works with

Packages commonly used together with universal_io: ones it builds on, ones built on it, and its own family.