tree: 75533061f02e6d414fcc4b2b778a755d55e04f81
  1. example/
  2. lib/
  3. test/
  4. test_fixes/
  5. analysis_options.yaml
  6. CHANGELOG.md
  7. LICENSE
  8. pubspec.yaml
  9. README.md
  10. renames.md
web/README.md

pub package package publisher

Lightweight browser API bindings built around JS interop.

What's this?

This package exposes browser APIs. It's generated from the Web IDL definitions and uses recent Dart language features for zero-overhead bindings.

This package is intended to replace dart:html and similar Dart SDK libraries. It will support access to browser APIs from Dart code compiled to either JavaScript or WebAssembly.

Usage

import 'package:web/web.dart';

void main() {
  final div = document.querySelector('div')!;
  div.text = 'Text set at ${DateTime.now()}';
}

Migrating to package:web

package:web is replacing dart:html and other web libraries as Dart's long-term web interop solution. To learn how to migrate from dart:html APIs to package:web, see our migration guide.

Specific APIs

document.cookie

When migrating from dart:html to package:web, note that document.cookie is now non-nullable and always returns a String.

In dart:html, this getter was nullable to support very old browser versions where Document.cookie was not available. package:web follows the Web IDL specification and does not include this legacy compatibility.

If no cookies are present, document.cookie returns an empty string (""), not null.

Generation

This package is generated by web_generator. See the README for more details on the conventions used to generate this package and how to run the different tools to generate bindings and update various package dependencies.