universal_io 0.2.0 universal_io: ^0.2.0 copied to clipboard
Cross-platform version of 'dart:io'. Supports browser, Node.JS, and other targets.
Introduction #
A Dart package that supports a subset of dart:io
In the Dart VM and Flutter, "package:universal_io/io.dart" exports the standard "dart:io". This is accomplished with conditional imports, which is an undocumented feature of Dart.
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.
Issues #
- Found issues? Report them at the Github issue tracker.
- Have a fix? Create a pull request!
Getting started #
1.Add dependency #
In pubspec.yaml
:
dependencies:
universal_io: ^1.0.0
2.Choose driver #
- VM/Flutter?
- Library "package:universal_io/io.dart" will automatically export dart:io for you.
- Browser?
- BrowserIODriver is automatically used when compiling with Dart2js / devc. Most importantly, it implements HttpClient (with restrictions imposed by browsers).
- If you need things like sockets or unrestricted HttpClient, choose one of the options below.
- Chrome OS App?
- Node.JS? Google Cloud Functions?
- A backend + GRPC messaging?
Default driver behavior #
- Platform
- In browser, variables are determined by browser APIs such as navigator.userAgent.
- Elsewhere (e.g. Node.JS), appears like Linux environment.
- Files
- Access to all directories and files is denied.
- InternetAddress
- Implemented using package:ip.
InternetAddress.lookup
uses Google's DNS-over-HTTP servers.
- HTTP client
- In browser, HTTP client is implemented using dart:html HttpRequest (XmlHttpRequest).
- If a cross-origin request fails, error message contains a detailed description how to fix possible issues like missing cross-origin headers.
- Sockets and HTTP server
- Connecting/binding throws UnimplementedError.