Repository navigation
Expand file tree
/
Copy pathhello_bundle.dart
More file actions
116 lines (113 loc) · 3.47 KB
/
Copy pathhello_bundle.dart
File metadata and controls
116 lines (113 loc) · 3.47 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// A publish bundle written by hand: one screen with a bound text, a screen
// variable, and a button whose reaction changes the variable and calls a
// function of the app. Publishes from the Codelessly Editor have this same
// shape (`"schema": 3`); see the codelessly_api package for the model.
import 'package:codelessly_sdk/codelessly_sdk.dart';
/// The id of the bundle's only layout.
const String helloLayoutId = 'hello';
/// The bundle, decoded. Decoding never throws: unknown keys are kept and
/// bad values fall back to their defaults.
PublishBundle helloBundle() => PublishBundle.fromJson(_json);
const Map<String, Object?> _json = {
'model': {
'schema': 3,
'projectId': 'hello-project',
'entryLayoutId': helloLayoutId,
'layouts': {
helloLayoutId: {
'canvases': [
{'id': 'home', 'name': 'Home'},
],
},
},
},
'layouts': {
helloLayoutId: {
'schema': 3,
'id': helloLayoutId,
'roots': ['home'],
// The screen's variables, by canvas.
'variables': {
'home': [
{'id': 'v_count', 'name': 'count', 'type': 'integer', 'value': 0},
],
},
'nodes': {
// A canvas is a screen; its content is its `body` slot. This one
// hugs its content's height, so it can sit inside a host's column.
'home': {
'type': 'canvas',
'name': 'Home',
'slots': {'body': 'column'},
'layout': {
'width': 390,
'height': {'hug': 200},
},
'decoration': {
'fills': [
{'color': '#FFFFFFFF'},
],
},
},
'column': {
'type': 'column',
'children': ['title', 'counter', 'button'],
'layout': {
'width': {'fill': 390},
'height': {'hug': 200},
'padding': 24,
},
'props': {'crossAxisAlignment': 'start', 'spacing': 12},
},
'title': {
'type': 'text',
'layout': {
'width': {'fill': 342},
'height': {'hug': 32},
},
'props': {
// `data.name` is what the app passes as `data: {'name': ...}`.
'text': r'Hello, ${data.name}!',
'style': {'fontSize': 24, 'fontWeight': 700, 'color': '#FF111111'},
},
},
'counter': {
'type': 'text',
'layout': {
'width': {'fill': 342},
'height': {'hug': 20},
},
'props': {
// `count` is the screen's variable; `route.source` a param the
// screen was opened with.
'text': r'Taps: ${count} (opened from ${route.source})',
'style': {'fontSize': 14, 'color': '#FF555555'},
},
},
'button': {
'type': 'filledButton',
'layout': {
'width': {'hug': 120},
'height': 44,
},
'props': {'label': 'Tap me'},
'actions': [
{
'id': 'r1',
'trigger': {'type': 'click'},
'actions': [
{'type': 'setVariable', 'variable': 'count', 'op': 'add', 'value': '1'},
// Calls `CodelesslyConfig.functions['onTap']`.
{
'type': 'callFunction',
'name': 'onTap',
'params': {'count': r'${count}'},
},
],
},
],
},
},
},
},
};