web_node 0.1.0 web_node: ^0.1.0 copied to clipboard
A cross-platform widget for displaying DOM nodes (iframes, etc.) in Flutter applications. Uses real DOM nodes in browsers and webview_flutter in Android/iOS.
Overview #
A cross-platform package for displaying DOM trees in Flutter applications.
Licensed under the Apache License 2.0.
Links #
Behavior #
In browsers #
- Uses real DOM nodes.
- For details, you can study the source code:
In Android and iOS #
- Serializes the DOM tree to HTML source code. Passes some of the surrounding style (background color, font family, etc.) DOM tree.
- Uses webview_flutter, a package maintained by Google, for showing the serialized DOM tree.
- For details, you can study the source code:
Known issues #
- Flutter for Web suffers from flickering in browsers (Flutter issue #51865)
Getting started #
1.Setup #
In pubspec.yaml:
dependencies:
universal_html: ^1.2.3
web_node: ^0.1.0
2.Display DOM nodes #
import 'package:flutter/material.dart';
import 'package:universal_html/html.dart' show html;
import 'package:web_node/web_node.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: SafeArea(
child: WebNode(node: exampleDomTree()),
),
),
));
}
// Constructs:
// <div>
// <h1>Dart website</h1>
// <iframe src="https://dart.dev">
// </div>
html.Node exampleDomTree() {
final h1 = html.HeadingElement.h1();
h1.appendText('Dart website');
final iframe = html.IFrameElement();
iframe.src = 'https://dart.dev/';
final div = html.DivElement()
..append(h1);
..append(iframe);
return div;
}