Viewing version 0.8.3. Open the latest package page.
universal_io
0.8.3Cross-platform 'dart:io' that works in browsers, Flutter, and VM.
Readme
Introduction
A cross-platform dart:io that works in browsers, Flutter, and VM.
License
Licensed under the Apache License 2.0.
Much of the source code in this project is from Dart SDK (github.com/dart-lang/sdk/tree/master/sdk/lib/io), which was obtained under the BSD-style license of Dart SDK.
Dart SDK 2.5 breaking changes
- Dart SDK 2.5 (currently in the Dart SDK 'dev' channel) has various breaking changes in dart:io. Consequently this package has breaking changes too.
- If you don't use the 2.5.0-dev-2.0 or later, see dependency constraint recommendations below.
Issues
- Found issues? Report them at the Github issue tracker.
- Have a fix? Create a pull request!
Similar packages
- universal_html (cross-platform dart:html)
Getting started
1.Add a dependency
Dart SDK 2.5.0-dev-2.0 and above
In pubspec.yaml:
dependencies:
universal_io: '^0.8.2'
Dart SDK 2.4.x
In pubspec.yaml:
dependencies:
universal_io: '>=0.7.3 <0.8.0'
2. Choose a driver (optional)
VM/Flutter?
- Library "package:universal_io/io.dart" will automatically export dart:io for you.
Browser?
- 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("http://google.com"));
final response = await request.close();
}
Manual
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
URL: http://destination.com
Origin: http://source.com
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: http://source.com
* OR '*'
* Access-Control-Allow-Methods: PUT
HttpServer
- Requires sockets.
Platform
- In browser, variables are determined by browser APIs such as navigator.userAgent.
- Elsewhere (e.g. Node.JS), appears like Linux environment.
Files
- Any attempt to use these APIs will throw UnimplementedError.
Sockets
- 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() {
exampleIODriver.enable();
}
/// Let's change 'Platform' implementation (in browser).
final exampleIODriver = IODriver(
platformDriver: PlatformDriver(localeName:"en-US"),
).fillMissingFeaturesFrom(defaultIODriver);
Changelog
0.8.3
- Replaced IP address parsing with the new Uri.parseIPv4Address / Uri.parseIPv6Address.
- Fixed missing HTTP status codes.
0.8.2
- Fixed problems introduced by Dart SDK 2.5.0-dev-2.0.
0.8.1
- Fixed pubspec.yaml and documented Dart SDK 2.5 breaking changes.
0.8.0
- Updated classes to Dart 2.5. See Dart SDK documentation about the changes.
- Various APIs now return
Uint8Listinstead ofList<int>. Examples:File,Socket,HttpClientResponse. - Various other breaking changes such as
Cookieconstructor.
- Various APIs now return
0.7.3
- Fixed the following error thrown by the Dart build system in some cases: "Unsupported conditional import of dart:io found in universal_io|lib/io.dart".
0.7.2
- Small fixes.
0.7.1
- Fixed various bugs.
- Improved the test suite.
0.7.0
- Improved driver base classes and the test suite.
0.6.0
- Major refactoring of IODriver API.
0.5.1
- Fixed small bugs.
0.5.0
- Fixed various bugs.
- Re-organized source code.
- Eliminated dependencies by doing IP parsing in this package.
- Improved the test suite for drivers.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'universal_io:0.8.3'pubspec.yaml
name: universal_io
version: 0.8.3
description:
Cross-platform 'dart:io' that works in browsers, Flutter, and VM.
homepage: https://github.com/terrier989/universal_io
author: terrier989 <terrier989@gmail.com>
environment:
# This package is not actually 2.4.x compatible!
#
# Unfortunately, if we use 2.5.0-dev-2.1, pub.dev/packages/universal_io would show big red
# warnings to potential users of this package.
sdk: '>=2.4.0 <3.0.0'
dependencies:
meta: ^1.1.0
zone_local: '>=0.1.1 <2.0.0'
dev_dependencies:
async: ^2.3.0
pedantic: ^1.8.0
stream_channel: ^2.0.0
test: ^1.6.0Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | Cached · Upstream SHA-256 matched | Download | a8aa4b4f…6f259b |
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | adeca974…128b76 |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | b4d0cce4…efe2b0 |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | debb79ed…36d4ee |
| 0.3.0 | Cached · Upstream SHA-256 matched | Download | 0b8f764b…a054e5 |
| 0.4.0 | Cached · Upstream SHA-256 matched | Download | 7f879f79…0ee63f |
| 0.5.0 | Cached · Upstream SHA-256 matched | Download | a185c8ca…f5f7c2 |
| 0.5.1 | Cached · Upstream SHA-256 matched | Download | 47881238…a13ab3 |
| 0.6.0 | Cached · Upstream SHA-256 matched | Download | 0465c285…30fb21 |
| 0.7.0 | Cached · Upstream SHA-256 matched | Download | 0b6ff36a…c988ef |
| 0.7.1 | Cached · Upstream SHA-256 matched | Download | 3fd33123…e947d1 |
| 0.7.2 | Cached · Upstream SHA-256 matched | Download | ab916807…e30f36 |
| 0.7.3 | Cached · Upstream SHA-256 matched | Download | 9918c2ae…d6e492 |
| 0.8.0 | Cached · Upstream SHA-256 matched | Download | 9e971384…0ffa98 |
| 0.8.1 | Cached · Upstream SHA-256 matched | Download | 39dd369c…e29abc |
| 0.8.2 | Cached · Upstream SHA-256 matched | Download | 873f9c3e…b5629f |
| 0.8.3 | Cached · Upstream SHA-256 matched | Download | 0da20598…979fb2 |
| 0.8.4 | Cached · Upstream SHA-256 matched | Download | b1c84301…3b7ec0 |
| 0.8.5 | Cached · Upstream SHA-256 matched | Download | 50a660f9…874883 |
| 0.8.6 | Cached · Upstream SHA-256 matched | Download | e700bb7c…986502 |
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | 5da439c3…bddf21 |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | 2c0fa418…f6cb08 |
| 1.0.2 | Cached · Upstream SHA-256 matched | Download | 22c5875f…f9e8db |
| 2.0.0-nullsafety.0 | Cached · Upstream SHA-256 matched | Download | 2fe15fca…c8acd3 |
| 2.0.0-nullsafety.1 | Cached · Upstream SHA-256 matched | Download | 2c94fd97…a42cfa |
| 2.0.0-nullsafety.2 | Cached · Upstream SHA-256 matched | Download | ad7e7015…8099d1 |
| 2.0.0 | Cached · Upstream SHA-256 matched | Download | 6ba43dc8…75397e |
| 2.0.1 | Cached · Upstream SHA-256 matched | Download | ffb7b33e…21e456 |
| 2.0.2 | Cached · Upstream SHA-256 matched | Download | 02437682…2d832b |
| 2.0.3 | Cached · Upstream SHA-256 matched | Download | ee2ecc7c…bc6f23 |
| 2.0.4 | Cached · Upstream SHA-256 matched | Download | 79f78dda…f03cef |
| 2.0.5 | Cached · Upstream SHA-256 matched | Download | 2730b3fc…680b85 |
| 2.1.0 | Cached · Upstream SHA-256 matched | Download | 070d8fcc…745007 |
| 2.2.0 | Cached · Upstream SHA-256 matched | Download | 06866290…48005d |
| 2.2.1 | Cached · Upstream SHA-256 matched | Download | 302df7ff…d51401 |
| 2.2.2 | Cached · Upstream SHA-256 matched | Download | 1722b2dc…ba9aad |
| 2.2.3 | Cached · Upstream SHA-256 matched | Download | ba9dde5f…2edf04 |
| 2.3.0 | Cached · Upstream SHA-256 matched | Download | 6780711d…79530a |
| 2.3.1 | Cached · Upstream SHA-256 matched | Download | f63cbc48…9301e2 |
Dependencies
meta "^1.1.0"
zone_local "\u003e=0.1.1 \u003c2.0.0"