universal_io 0.7.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 73

Introduction #

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).

Issues #

Similar packages #

Getting started #

1.Add a dependency #

In pubspec.yaml:

dependencies:
  universal_io: '>=0.7.2 <2.0.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);

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.

example/example.dart

import 'package:universal_io/io.dart';

void main() async {
  // Use 'dart:io' HttpClient API.
  final httpClient = HttpClient();
  final request = await httpClient.getUrl(Uri.parse("http://google.com"));
  final response = await request.close();
  print(response.toString());
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  universal_io: ^0.7.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:universal_io/driver.dart';
import 'package:universal_io/driver_base.dart';
import 'package:universal_io/io.dart';
import 'package:universal_io/utils.dart';
  
Version Uploaded Documentation Archive
0.7.2 Jun 11, 2019 Go to the documentation of universal_io 0.7.2 Download universal_io 0.7.2 archive
0.7.1 Jun 11, 2019 Go to the documentation of universal_io 0.7.1 Download universal_io 0.7.1 archive
0.7.0 Jun 10, 2019 Go to the documentation of universal_io 0.7.0 Download universal_io 0.7.0 archive
0.6.0 Jun 9, 2019 Go to the documentation of universal_io 0.6.0 Download universal_io 0.6.0 archive
0.5.1 Jun 8, 2019 Go to the documentation of universal_io 0.5.1 Download universal_io 0.5.1 archive
0.5.0 Jun 8, 2019 Go to the documentation of universal_io 0.5.0 Download universal_io 0.5.0 archive
0.4.0 May 31, 2019 Go to the documentation of universal_io 0.4.0 Download universal_io 0.4.0 archive
0.3.0 May 31, 2019 Go to the documentation of universal_io 0.3.0 Download universal_io 0.3.0 archive
0.2.0 May 31, 2019 Go to the documentation of universal_io 0.2.0 Download universal_io 0.2.0 archive
0.1.1 Feb 18, 2019 Go to the documentation of universal_io 0.1.1 Download universal_io 0.1.1 archive

All 12 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Jun 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.17

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Health suggestions

Format lib/src/driver/drivers_in_vm.dart.

Run dartfmt to format lib/src/driver/drivers_in_vm.dart.

Format lib/src/driver_for_browser/browser_http_client_response.dart.

Run dartfmt to format lib/src/driver_for_browser/browser_http_client_response.dart.

Format lib/src/io/http/http_impl.dart.

Run dartfmt to format lib/src/io/http/http_impl.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/io/io/internet_address.dart (Run dartfmt to format lib/src/io/io/internet_address.dart.)
  • lib/src/io/io/process.dart (Run dartfmt to format lib/src/io/io/process.dart.)
  • lib/src/io/io/secure_socket_impl.dart (Run dartfmt to format lib/src/io/io/secure_socket_impl.dart.)
  • lib/utils.dart (Run dartfmt to format lib/utils.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
meta ^1.1.7 1.1.7
zone_local >=0.1.0 <2.0.0 0.1.1
Dev dependencies
async ^2.2.0
pedantic ^1.7.0
stream_channel ^2.0.0
test ^1.6.3