universal_html
2.3.0, released a year ago by dint.dev
Cross‑platform replacement for dart:html with DOM parsing, XML support, and EventSource.
What it does
Provides a unified API for manipulating HTML and XML documents on browsers, mobile, desktop, server, and Node.js. It also offers a WindowController for HTTP requests and an EventSource implementation that works outside browsers.
AI-written summary of version 2.3.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need to parse or manipulate HTML/XML in a non‑browser Dart environment
- Building a web scraper or crawler that runs on server or desktop
- Using EventSource streams in Flutter or server apps
Skip it when
- Building a full Flutter UI that relies on real browser widgets
- Performance‑critical DOM manipulation where native dart:html is required
Strengths
- Cross‑platform API, no need to switch imports
- Built‑in EventSource support with customizable headers
- Comprehensive DOM query and manipulation methods
Weaknesses
- No Flutter widgets, only core DOM helpers
- Not a UI framework, so not useful for building UIs
- Requires manual handling of HTTP client for some features
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 9
Add dependency in pubspec: universal_html: ^2.3.0
import "package:universal_html/universal_html.dart";
void main() {
final div = DivElement();
div.append(Element.tag("h1")..appendText("Hello world!"));
print(div.outerHtml); // <div><h1>Hello world!</h1></div>
}Alternatives
Packages that do the same job and could replace universal_html.
Works with
Packages commonly used together with universal_html: ones it builds on, ones built on it, and its own family.
- asyncuniversal_html depends on itUtility classes and helpers that extend Dart's async library.
- source_spanuniversal_html depends on itStandard representation for source code locations, spans, and human-friendly error messages.
- htmluniversal_html depends on itA Dart implementation of an HTML5 parser for strings and bytes.
- typed_datauniversal_html depends on itUtility functions and classes for easier work with dart:typed_data lists.
- csslibuniversal_html depends on itA Dart library that parses CSS strings or byte lists into an AST.
- charcodeuniversal_html depends on itProvides named integer constants for ASCII and HTML character codes.
- universal_iouniversal_html depends on itCross-platform dart:io implementation with browser support for HttpClient and other APIs
- mqtt5_clientBuilt on universal_htmlA server and browser based MQTT Version 5 client for Dart supporting TCP and WebSockets.