dvStudioLeafTypes top-level property
Implementation
final List<DVStudioLeafType> dvStudioLeafTypes = <DVStudioLeafType>[
DVStudioLeafType(
type: 'text',
label: 'Text',
create: () => DVPageNode.text('Text'),
build: (node) => DVText('${node.properties['text'] ?? ''}'),
source: (node, escape) =>
"const DVText('${escape('${node.properties['text'] ?? ''}')}')",
),
DVStudioLeafType(
type: 'image',
label: 'Image',
create: () => DVPageNode.image('https://example.com/image.png'),
// Where the image comes from is the node's to say. It could only ever be
// a URL, which left assets, files and stored bytes unreachable from a
// page -- and an imported design permanently dependent on somebody
// else's address staying up. Read through DVImage's own reader, so a
// page and a model field cannot disagree about what a source name means.
build: (node) => DVImageRender(
dvStudioImageOf(node.properties),
fit: dvStudioImageFitOf(node.properties['fit']),
),
// The image is part of the box's one modifier chain. Returning a
// pre-modified box here would let the style modifier appended by the
// exporter replace it, silently leaving a styled but empty box.
source: (_, _) => 'const DVBox()',
),
// A button is a text node that announces itself as one. The tap itself is
// the node's action, the same mechanism any node uses, so this adds the
// semantics and the tap target rather than a second way to handle presses.
// Both are added where the styles are ([dvStudioStyled] and the export's
// modifier), because a modifier replaces the one before it.
//
// Dropped from the palette it is drawn as a button, with the look as
// ordinary properties the inspector shows and can change.
DVStudioLeafType(
type: 'button',
label: 'Button',
create: () => DVPageNode(
type: 'button',
properties: <String, Object?>{
'text': 'Button',
...dvStudioButtonDefaults,
},
),
build: (node) => DVText('${node.properties['text'] ?? ''}'),
source: (node, escape) =>
"DVText('${escape('${node.properties['text'] ?? ''}')}')",
),
DVStudioLeafType(
type: 'spacer',
label: 'Spacer',
create: () => DVPageNode.text('').withType('spacer').withProperty('size', 16),
build: (node) => SizedBox(height: _size(node, 'size', 16)),
source: (node, escape) =>
'const SizedBox(height: ${_size(node, 'size', 16)})',
),
DVStudioLeafType(
type: 'divider',
label: 'Divider',
create: () =>
DVPageNode.text('').withType('divider').withProperty('thickness', 1),
build: (node) => SizedBox(
height: _size(node, 'thickness', 1),
child: const ColoredBox(color: Color(0x33000000)),
),
source: (node, escape) =>
'const SizedBox(height: ${_size(node, 'thickness', 1)}, '
'child: ColoredBox(color: Color(0x33000000)))',
),
];