universal_html は、モバイル、デスクトップ、サーバーサイド環境における Flutter を含むすべてのプラットフォームで動作する統一された 'dart:html' API を提供します。実行時環境にかかわらず、一貫した HTML および XML 処理を可能にし、クロスプラットフォーム開発を簡素化します。このパッケージは、DOM 操作、HTTP リクエスト、構造化コンテンツの解析に対して互換性のあるインターフェースを提供することで、Web と非 Web コンテキストのギャップを埋めます。Web とバックエンドサービス間でロジックを共有する場合に最適であり、コードの重複を減らし、開発ワークフローをスムーズにします。
A cross-platform replacement for dart:html (or package:web):
Eases cross-platform development
You can use this package in browsers, mobile, desktop, and server-side VM, and Node.JS.
Just replace dart:html / package:web imports with package:universal_html/universal_html.dart. Normal
dart:html will continue to be used when application run in browsers.
Extensive support for processing HTML and XML documents
The project is licensed under the Apache License 2.0. Some of the source code was adopted
from the original dart:html in Dart SDK,
which is documented in the relevant files.
EventSource requests from real browsers are typically authenticated using cookies.
If you want to add cookies or customize other HTTP headers, you need to use
EventSourceOutsideBrowser:
import'package:universal_html/universal_html.dart';
import'dart:io'showCookie;
Future<void> main() async {
final eventSource = EventSource('http://example.com/events');
// The following block will NOT be executed in browsers.// Because compiler can infer instances of EventSourceOutsideBrowser are never constructed,// it will not appear in Javascript either.if (eventSource isEventSourceOutsideBrowser) {
eventSource.onHttpClientRequest = (eventSource, request) {
request.headers.set('Authorization', 'example');
request.cookies.add(Cookie('name', 'value'));
};
eventSource.onHttpClientResponse = (eventSource, request, response) {
// ...
};
}
awaitfor (var message in eventSource.onMessage) {
print('Event:');
print(' type: ${message.type}');
print(' data: ${message.data}');
}
}