Overview

This package is a pure Dart implemention of a subset of dart:html. The package works in all platforms (VM, Flutter, and browser).

Licensed under the MIT license.

The project welcomes new contributors:

Use cases

  • Parsing/scraping HTML in the server/Flutter + browser.
  • Generating HTML in the server/Flutter + browser.

Features

DOM APIs

  • Node classes (Node, Element, CheckboxInputElement, etc.)
  • Printing (element.outerHtml, etc.)
  • Parsing (DomParser)
  • Queries (document.querySelector, node.matchesSelector)
  • Event handlers

Other APIs

We have implemented various other APIs such as subsets ofwindow and navigator. Non-implemented APIs either throw UnimplementedError or fail silently when used in non-browser environment.

Correctness

We test that the APIs behave identically to dart:html code running in Chrome. There are some failing tests.

For parsing, we use:

Getting started

In pubspec.yaml:

name: example
dependencies:
  universal_html: ^0.1.0

Now you can replace usage of "dart:html" with "package:universal_html/html.dart":

import "package:universal_html/html.dart";

void main() {
  // Create a DOM tree
  final element = new Element.tag("h1")..appendText("Hello world!");

  // Print outer HTML
  print(element.outerHtml);
}

Libraries

universal_html.html
universal_html.html_driver
universal_html.svg