-
Notifications
You must be signed in to change notification settings - Fork 1
/
flutter_bootstrap.js
65 lines (56 loc) · 1.63 KB
/
flutter_bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{{flutter_build_config}}
{{flutter_js}}
let viewIds = [];
function resetUi() {
viewIds = [];
grid.replaceChildren();
remover.disabled != true;
adder.disabled = false;
}
let flutterApp = new Promise((resolve, reject) => {
_flutter.loader.load({
onEntrypointLoaded: async function(engineInitializer) {
resetUi();
let engine = await engineInitializer.initializeEngine({
multiViewEnabled: true,
renderer: 'canvaskit',
});
let app = engine.runApp();
resolve(app);
}
});
});
adder.addEventListener('click', async function() {
// Create a new element, and add a flutter view there...
let newElement = document.createElement('div');
newElement.classList.add('cel');
grid.appendChild(newElement);
let viewId = (await flutterApp).addView({
hostElement: newElement,
initialData: {
randomInt: Math.floor(Math.random() * 100),
randomUUID: globalThis.crypto.randomUUID(),
decimals: [Math.PI, Math.E, Math.SQRT2],
},
viewConstraints: {
minWidth: 0,
maxWidth: 320,
minHeight: 0,
maxHeight: 240,
}
});
viewIds.push(viewId);
console.log('Added view ID', viewId);
// Handle enabling/disabling the remove_last button
remover.disabled = viewIds.length == 0;
});
remover.addEventListener('click', async function() {
let viewId = viewIds.pop();
if (viewId) {
let viewConfig = (await flutterApp).removeView(viewId);
console.log('Removing view with ID', viewId, 'and config', viewConfig);
viewConfig.hostElement.remove();
}
// Handle enabling/disabling the remove_last button
remover.disabled = viewIds.length == 0;
});