Skip to content

Instantly share code, notes, and snippets.

@gliheng
Created January 10, 2020 02:18
Show Gist options
  • Save gliheng/042cf477b932e576109310f73d7dc56a to your computer and use it in GitHub Desktop.
Save gliheng/042cf477b932e576109310f73d7dc56a to your computer and use it in GitHub Desktop.
use dom with flutter
@JS()
library vue_app;
import 'package:flutter/material.dart';
import 'dart:ui' as dart_ui_web;
import 'dart:html';
import 'package:js/js.dart';
import 'dart:js';
@JS('console.log')
external log(dynamic n);
void main() {
log('App start up!');
// ignore:undefined_prefixed_name
dart_ui_web.platformViewRegistry.registerViewFactory(
'box',
(int viewId) {
log(viewId);
DivElement elm = DivElement();
DivElement inner = DivElement();
inner.style.height = '40px';
inner.style.backgroundColor = 'orange';
inner.innerHtml = 'hello';
ButtonElement btn = ButtonElement();
btn.innerText = 'click me';
elm.append(inner);
elm.append(btn);
// mount('box', inner);
return elm;
}
);
runApp(MaterialApp(
title: 'Flutter web dom demo',
theme: ThemeData(
),
home: RhinoApp(),
));
}
class RhinoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: HtmlElementView(viewType: 'box'),
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment