buildList function
Implementation
Widget buildList(BuildContext context, OpenUiNode node) {
final theme = node.theme;
final props = node.props;
final marker = props.string('marker') ?? 'bullet';
final numbered = marker == 'number';
final none = marker == 'none';
final timeline = props.boolean('timeline') ?? false;
final entries = [
for (final (index, item) in _listItems(props['items']).indexed)
if (item is String || item is num || _isListItem(item)) (index, item),
];
final customs = [for (final (_, item) in entries) _itemMarker(item)];
final wide = customs.any((m) => m != null && m.length > 2);
final chips = customs.any((m) => m != null && _stepMarker.hasMatch(m));
final hasColumn = !none || customs.any((m) => m != null);
final bullet = !numbered && !none;
final compact = MediaQuery.sizeOf(context).width <= 640;
final (columnWidth, gap) = wide
? (compact ? 64.0 : 76.0, compact ? 20.0 : (timeline ? 24.0 : 16.0))
: bullet && !timeline && !chips
? (14.0, 8.0)
: (24.0, 12.0);
final fontSize = DefaultTextStyle.of(context).style.fontSize ?? 14;
final rows = <Widget>[];
for (final (k, (index, item)) in entries.indexed) {
final last = k == entries.length - 1;
final custom = customs[k];
final textMarker = custom != null && !_stepMarker.hasMatch(custom);
final rich = item is OpenUiElement && _isRich(item);
final id = item is OpenUiElement
? node.childId(item, k, slot: 'items')
: '';
final body = item is OpenUiElement
? _ListRowScope(
rich: rich,
child: OpenUiElementView(
key: ValueKey('openui:$id'),
element: item,
id: id,
),
)
: _richText(context, node, jsString(item), const TextStyle());
Widget? mark;
if (custom != null) {
mark = _customMarker(theme, custom);
} else if (!none) {
mark = ExcludeSemantics(
child: numbered
? _numberCircle(theme, index + 1)
: timeline
? _ring(theme)
: _dot(theme),
);
}
final markerBox = mark == null
? null
: numbered && !textMarker
? SizedBox.square(
dimension: 24,
child: custom == null
? mark
: DecoratedBox(
decoration: BoxDecoration(
color: theme.ink,
shape: BoxShape.circle,
),
child: Center(child: mark),
),
)
: SizedBox(
height: fontSize * 1.55,
child: Align(
alignment: textMarker
? AlignmentDirectional.centerStart
: Alignment.center,
child: mark,
),
);
final connects = timeline && !last && (!none || wide);
final row = Padding(
padding: EdgeInsets.only(
bottom: timeline ? (last ? 0.0 : 18.0) : (rich ? 4.0 : 0.0),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (hasColumn) ...[
SizedBox(width: columnWidth, child: markerBox),
SizedBox(width: gap),
],
Expanded(child: body),
],
),
);
rows.add(
Semantics(
key: item is OpenUiElement ? ValueKey(('list-item', id)) : null,
container: true,
role: SemanticsRole.listItem,
child: Stack(
children: [
if (connects)
PositionedDirectional(
start: wide ? (compact ? 73 : 83) : 11.5,
top: 1.7 * fontSize,
bottom: 0.15 * fontSize,
width: 1,
child: ColoredBox(color: theme.borderStrong),
),
row,
if (timeline && wide && textMarker)
PositionedDirectional(
start: compact ? 70 : 80,
top: 0.55 * fontSize,
child: _ring(theme),
),
],
),
),
);
}
return Semantics(
container: true,
role: SemanticsRole.list,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (final (k, row) in rows.indexed) ...[
if (k > 0 && !timeline) const SizedBox(height: 10),
row,
],
],
),
);
}