dvStudioProperties top-level property
Every styling control the page builder offers.
Implementation
final List<DVStudioProperty> dvStudioProperties = <DVStudioProperty>[
DVStudioProperty('fontSize', DVStudioPropertyKind.number,
(m, v, p) => _number(m, v, (m, v) => m.fontSize(v)),
source: (v, p) => _numberSource('fontSize', v)),
DVStudioProperty('letterSpacing', DVStudioPropertyKind.number,
(m, v, p) => _number(m, v, (m, v) => m.letterSpacing(v)),
source: (v, p) => _numberSource('letterSpacing', v)),
// The two a designer sets on nearly every text layer and the document had
// nowhere to put: an import wrote the family and nothing read it, so every
// screen came out in the default font, and paragraphs came out at the
// font's own leading rather than the design's.
DVStudioProperty('fontFamily', DVStudioPropertyKind.text,
(m, v, p) => v is String && v.isNotEmpty ? m.fontFamily(v) : null,
source: (v, p) =>
v is String && v.isNotEmpty ? ".fontFamily('${_escapeSource(v)}')" : null),
DVStudioProperty('lineHeight', DVStudioPropertyKind.number,
(m, v, p) => _number(m, v, (m, v) => m.lineHeight(v)),
source: (v, p) => _numberSource('lineHeight', v)),
// How many lines the text gets, and what happens to the rest. A design
// says both, and a page that said neither pushed everything below a long
// title down the screen.
DVStudioProperty('maxLines', DVStudioPropertyKind.number,
(m, v, p) => v is num && v >= 1 ? m.maxLines(v.toInt()) : null,
source: (v, p) =>
v is num && v >= 1 ? '.maxLines(${v.toInt()})' : null),
DVStudioProperty(
'overflow',
DVStudioPropertyKind.choice,
(m, v, p) {
final TextOverflow? overflow = _overflows[v];
return overflow == null ? null : m.overflow(overflow);
},
choices: _overflows.keys.toList(growable: false),
source: (v, p) =>
_overflows.containsKey(v) ? '.overflow(TextOverflow.$v)' : null,
),
DVStudioProperty('padding', DVStudioPropertyKind.number,
(m, v, p) => _padding(m, p),
source: (v, p) => _hasEdgePadding(p) ? null : _numberSource('padding', v)),
// Four sides, because a design almost never has one number: 24 across
// against 8 down is the shape of a card, and a document that could say
// only one of them left the import to keep the largest.
//
// Each side applies the whole EdgeInsets rather than its own edge: a
// modifier replaces the padding it is given, so four modifiers would leave
// only the last one applied.
for (final String side in _paddingEdges)
DVStudioProperty(side, DVStudioPropertyKind.number,
(m, v, p) => _padding(m, p),
source: (v, p) => _paddingEdgeSource(side, p)),
DVStudioProperty(
'margin',
DVStudioPropertyKind.number,
(m, v, p) => _margin(m, p),
source: (v, p) => _hasEdgeMargin(p) ? null : _numberSource('margin', v),
),
for (final String side in _marginEdges)
DVStudioProperty(
side,
DVStudioPropertyKind.number,
(m, v, p) => _margin(m, p),
source: (v, p) => _marginEdgeSource(side, p),
),
DVStudioProperty('width', DVStudioPropertyKind.number,
(m, v, p) => _number(m, v, (m, v) => m.width(v)),
source: (v, p) => _numberSource('width', v)),
DVStudioProperty('height', DVStudioPropertyKind.number,
(m, v, p) => _number(m, v, (m, v) => m.height(v)),
source: (v, p) => _numberSource('height', v)),
DVStudioProperty('rounded', DVStudioPropertyKind.number,
(m, v, p) => _corners(m, p),
source: (v, p) => _hasCorner(p) ? null : _numberSource('rounded', v)),
// Four corners, because a sheet rounded at the top and square at the
// bottom is in every design system and a document that could say one
// number turned one into a floating rounded rectangle.
for (final String corner in _cornerNames)
DVStudioProperty(corner, DVStudioPropertyKind.number,
(m, v, p) => _corners(m, p),
source: (v, p) => _cornerSource(corner, p)),
// A shadow is one decision made of five values, so the colour owns it and
// the rest are its companions: applied separately, whichever ran last
// would hold defaults for the other four.
DVStudioProperty(
'shadowColor',
DVStudioPropertyKind.colour,
(m, v, p) {
final List<BoxShadow>? shadow = _shadowOf(v, p);
return shadow == null ? null : m.shadow(shadow);
},
source: (v, p) {
final List<BoxShadow>? shadow = _shadowOf(v, p);
if (shadow == null) return null;
final BoxShadow cast = shadow.single;
return '.shadow(<BoxShadow>[BoxShadow(color: '
'Color(0x${_hex(cast.color)}), '
'offset: Offset(${cast.offset.dx}, ${cast.offset.dy}), '
'blurRadius: ${cast.blurRadius}, '
'spreadRadius: ${cast.spreadRadius})])';
},
),
// Declared so the inspector offers each one, and exported by the colour.
for (final String part in _shadowParts)
DVStudioProperty(
part,
DVStudioPropertyKind.number,
(m, v, p) {
final List<BoxShadow>? shadow = _shadowOf(p['shadowColor'], p);
return shadow == null ? null : m.shadow(shadow);
},
source: (v, p) => null,
companionOf: 'shadowColor',
),
// A gradient is one decision made of three values: two colours and a
// direction. The first colour owns it, the way a border's colour owns its
// width -- applied separately, whichever ran last would paint a gradient
// from a colour to a default.
DVStudioProperty(
'gradientFrom',
DVStudioPropertyKind.colour,
(m, v, p) {
final LinearGradient? gradient = _gradientOf(v, p);
return gradient == null ? null : m.gradient(gradient);
},
source: (v, p) {
final LinearGradient? gradient = _gradientOf(v, p);
if (gradient == null) return null;
final Alignment begin = gradient.begin as Alignment;
final Alignment end = gradient.end as Alignment;
return '.gradient(LinearGradient('
'begin: Alignment(${begin.x}, ${begin.y}), '
'end: Alignment(${end.x}, ${end.y}), '
'colors: <Color>[Color(0x${_hex(gradient.colors.first)}), '
'Color(0x${_hex(gradient.colors.last)})]))';
},
),
for (final String part in _gradientParts)
DVStudioProperty(
part,
part == 'gradientTo'
? DVStudioPropertyKind.colour
: DVStudioPropertyKind.number,
(m, v, p) {
final LinearGradient? gradient = _gradientOf(p['gradientFrom'], p);
return gradient == null ? null : m.gradient(gradient);
},
source: (v, p) => null,
companionOf: 'gradientFrom',
),
DVStudioProperty('color', DVStudioPropertyKind.colour,
(m, v, p) => _colour(m, v, (m, v) => m.color(v)),
source: (v, p) => _colourSource('color', v)),
DVStudioProperty('backgroundColor', DVStudioPropertyKind.colour,
(m, v, p) => _colour(m, v, (m, v) => m.backgroundColor(v)),
source: (v, p) => _colourSource('backgroundColor', v)),
DVStudioProperty(
'fontWeight',
DVStudioPropertyKind.choice,
(m, v, p) {
final weight = _fontWeights[v];
return weight == null ? null : m.fontWeight(weight);
},
choices: _fontWeights.keys.cast<String>().toList(growable: false),
source: (v, p) =>
_fontWeights.containsKey(v) ? '.fontWeight(FontWeight.$v)' : null,
),
DVStudioProperty(
'align',
DVStudioPropertyKind.choice,
(m, v, p) {
final alignment = _alignments[v];
return alignment == null ? null : m.align(alignment);
},
choices: _alignments.keys.cast<String>().toList(growable: false),
source: (v, p) =>
_alignments.containsKey(v) ? '.align(Alignment.$v)' : null,
),
// A border is two values making one decision, which is why apply is given
// the whole property map. A width with no colour is a border nobody can
// see, and applying the colour and the width as two independent modifiers
// would leave whichever ran last holding a default for the other.
DVStudioProperty(
'borderColor',
DVStudioPropertyKind.colour,
(m, v, p) {
final colour = parseDocumentColor(v);
if (colour == null) return null;
return m.border(_borderOf(colour, p));
},
source: (v, p) {
final colour = parseDocumentColor(v);
if (colour == null) return null;
return '.border(${_borderSource(colour, p)})';
},
),
// One width per side, because the commonest border in any design is a
// single hairline under a header or between two rows -- and a document that
// could only say one width drew that as a box. Companions of the colour for
// the reason the plain width is: a side on its own is a line nobody chose a
// colour for.
for (final String side in _borderSides)
DVStudioProperty(
side,
DVStudioPropertyKind.number,
(m, v, p) {
final colour = parseDocumentColor(p['borderColor']);
if (colour == null || v is! num) return null;
return m.border(_borderOf(colour, p));
},
source: (v, p) => null,
companionOf: 'borderColor',
),
// Declared so the inspector offers it and the table stays the one place a
// style is defined. The colour above draws it: a width alone is a border
// nobody chose a colour for, and choosing one would put a line in the
// design that nobody asked for.
DVStudioProperty(
'borderWidth',
DVStudioPropertyKind.number,
(m, v, p) {
final colour = parseDocumentColor(p['borderColor']);
if (colour == null || v is! num) return null;
return m.border(Border.all(color: colour, width: v.toDouble()));
},
source: (v, p) => null,
companionOf: 'borderColor',
),
DVStudioProperty(
'opacity',
DVStudioPropertyKind.number,
(m, v, p) {
// Flutter asserts on anything outside 0..1, and a document can carry
// any number at all: a page that will not render because of one value
// is worse than one drawn at full strength.
if (v is! num || v < 0 || v > 1) return null;
return m.opacity(v.toDouble());
},
source: (v, p) =>
v is num && v >= 0 && v <= 1 ? '.opacity(${v.toDouble()})' : null,
),
DVStudioProperty(
'rotation',
DVStudioPropertyKind.number,
(m, v, p) {
// Zero is not a rotation. Wrapping every box in a Transform that turns
// it by nothing would put a layer in the tree of every page for the
// one design in ten that tilts something, and a document can carry any
// value at all -- a page that will not render because of one is worse
// than one drawn square.
if (v is! num || v == 0) return null;
return m.rotate(v.toDouble());
},
source: (v, p) =>
v is num && v != 0 ? '.rotate(${v.toDouble()})' : null,
),
// Where the layer is moved to after layout, as an inspector shows it: x
// and y, in pixels. One modifier, so either applies the whole offset and
// it is exported once: through x when x is set, through y when only y is.
// A value that is not a number moves nothing rather than taking the page
// down.
DVStudioProperty(
'offsetX',
DVStudioPropertyKind.number,
(m, v, p) => _moved(m, p),
source: (v, p) => _offsetSource(p),
),
DVStudioProperty(
'offsetY',
DVStudioPropertyKind.number,
(m, v, p) => _moved(m, p),
source: (v, p) => p['offsetX'] is num ? null : _offsetSource(p),
),
DVStudioProperty(
'clip',
DVStudioPropertyKind.flag,
// A frame that crops its content is its own decision in a design, and it
// has nothing to do with corners: a photograph cropped by a square frame
// is the commonest version. Without it the child paints outside the box
// and the page carries an overflow stripe.
(m, v, p) => v == true ? m.clipContent() : null,
source: (v, p) => v == true ? '.clipContent()' : null,
),
// A layer that takes the room its siblings leave: the list under a
// header, the label beside an icon. Nothing fixed that a larger font
// would overflow.
DVStudioProperty(
'fill',
DVStudioPropertyKind.flag,
(m, v, p) => v == true ? m.fill() : null,
source: (v, p) => v == true ? '.fill()' : null,
),
DVStudioProperty(
'blur',
DVStudioPropertyKind.number,
(m, v, p) {
// Zero is not a blur. A filter layer costs what a real blur costs and
// changes no pixel, and a design exported with nought is saying it does
// not blur rather than asking for that. A negative one is not a blur
// either: ImageFilter.blur asserts on it, which would take the whole
// page down over a number a document can easily carry.
if (v is! num || v <= 0) return null;
return m.blur(v.toDouble());
},
source: (v, p) =>
v is num && v > 0 ? '.blur(${v.toDouble()})' : null,
),
DVStudioProperty(
'backdropBlur',
DVStudioPropertyKind.number,
(m, v, p) {
// The other blur, kept separate for the reason the modifier keeps them
// separate: this one leaves the layer sharp and softens what shows
// through it, which is a frosted card rather than a soft-focus shape.
if (v is! num || v <= 0) return null;
return m.backdropBlur(v.toDouble());
},
source: (v, p) =>
v is num && v > 0 ? '.backdropBlur(${v.toDouble()})' : null,
),
DVStudioProperty(
'decoration',
DVStudioPropertyKind.choice,
(m, v, p) => switch (v) {
'underline' => m.decoration(TextDecoration.underline),
'lineThrough' => m.decoration(TextDecoration.lineThrough),
// 'none' included on purpose: a design that turned an underline off is
// saying something, and dropping it would leave whatever a theme
// provides.
'none' => m.decoration(TextDecoration.none),
_ => null,
},
choices: const <String>['none', 'underline', 'lineThrough'],
source: (v, p) => switch (v) {
'underline' => '.decoration(TextDecoration.underline)',
'lineThrough' => '.decoration(TextDecoration.lineThrough)',
'none' => '.decoration(TextDecoration.none)',
_ => null,
},
),
DVStudioProperty('card', DVStudioPropertyKind.flag,
(m, v, p) => v == true ? m.card() : null,
source: (v, p) => v == true ? '.card()' : null),
];