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
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.
- google_vision
Integrates Google Vision REST API features for image analysis and OCR.
65Compare
Works with
Packages commonly used together with universal_io: ones it builds on, ones built on it, and its own family.
- typed_datauniversal_io depends on itUtility functions and classes for easier work with dart:typed_data lists.
- flutter_native_splashBuilt on universal_ioAutomatically generates native iOS, Android, and Web splash screens.
- universal_htmlBuilt on universal_ioCross‑platform replacement for dart:html with DOM parsing, XML support, and EventSource.
- very_good_test_runnerBuilt on universal_ioA Dart/Flutter test runner that streams TestEvent objects from dart test or flutter test.
- very_good_cliBuilt on universal_ioCLI for creating and managing Dart/Flutter projects
- icons_launcherBuilt on universal_ioA command-line tool that simplifies updating your Flutter app launcher icon.
- cookie_jarBuilt on universal_ioA Dart cookie manager for HTTP requests with in‑memory and persistent storage.
- country_pickerBuilt on universal_ioA Flutter widget to pick a country from a list with optional phone code and search.