build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the UI represented by this widget.

Implementation

@override
Widget build(BuildContext context) {
  final theme = ThemeScope.of(context);
  final lStyle = _copyStyle(labelStyle ?? theme.labelMedium)
    ..foreground(theme.muted);
  final vStyle = _copyStyle(valueStyle ?? theme.titleMedium)
    ..foreground(theme.onSurface)
    ..bold();

  final valueText = unit != null ? '$value$unit' : value;

  final children = <Widget>[
    Text(label, style: lStyle),
    Text(valueText, style: vStyle),
  ];

  if (trend != null) {
    final (trendChar, defaultColor) = switch (trend!) {
      MetricTrend.up => ('▲', theme.success),
      MetricTrend.down => ('▼', theme.error),
      MetricTrend.flat => ('─', theme.muted),
    };
    final tStyle = _copyStyle(Style())
      ..foreground(trendColor ?? defaultColor);
    children.add(Text(trendChar, style: tStyle));
  }

  return Row(gap: 1, children: children);
}