universal_html 0.0.1 copy "universal_html: ^0.0.1" to clipboard
universal_html: ^0.0.1 copied to clipboard

outdated

Supports a subset of 'dart:html' in all platforms (browser, VM, and Flutter).

Overview #

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

Typical use cases are:

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

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

For parsing, we use:

Features #

  • DOM
    • Node classes (Node, Element, CheckboxInputElement, etc.)
    • Printing (element.outerHtml, etc.)
    • Parsing (DomParser)
    • Queries (document.querySelector, node.matchesSelector)
    • Event handlers
  • Some window, navigator and other APIs.
  • We declare other APIs of dart:html, but they either throw UnimplementedError or fail silently when used in non-browser environment.

Example: Hello world #

In pubspec.yaml:

name: hello
dependencies:
  universal_html: ^0.0.1

Run pub get.

In bin/hello.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);
}

Run the program with pub run hello.

431
likes
0
pub points
99%
popularity

Publisher

verified publisherdint.dev

Supports a subset of 'dart:html' in all platforms (browser, VM, and Flutter).

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

charcode, csslib, html, meta

More

Packages that depend on universal_html