import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../adaptive/host.dart'; import '../text/monospace.dart'; /// One recorded fact of a detail Summary: a small muted label over its value. class FactsGridItem { const FactsGridItem({ required this.label, required this.value, this.key, this.monospace = false, this.wide = false, }); final String label; final String value; final Key? key; /// Draws the value in the monospace family (and gives it a whole line). final bool monospace; /// Gives the fact a whole line even when its value is short. final bool wide; } /// A value longer than this takes a whole line so it is never squeezed. const int kFactsGridLongValue = 28; /// The pane width from which the grid shows three facts per line. const double kFactsGridThreeColumnWidth = 600; /// A detail Summary's facts as one compact grid on the page, the same on /// both hosts and in every detail (run, pipeline): two facts per line on a /// phone, three from [kFactsGridThreeColumnWidth]; a long, wide or monospace /// value (a path, a hash) takes a whole line. /// /// The grid always fills its width and starts at the leading edge, so a /// single fact is a cell at the start of the line, never a shrunk block /// centred on the page. It draws no card or group of its own. class FactsGrid extends StatelessWidget { const FactsGrid({ super.key, required this.items, this.padding = const EdgeInsets.fromLTRB(16, 12, 16, 12), this.selectable = true, this.cupertino, }); final List items; final EdgeInsetsGeometry padding; /// Material values are selectable text; Cupertino values stay plain text. final bool selectable; /// Overrides the host detection (a feature that picks its style per /// platform). final bool? cupertino; @override Widget build(BuildContext context) { final cupertino = this.cupertino ?? usesCupertinoHost(context); final labelStyle = cupertino ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( color: CupertinoColors.secondaryLabel.resolveFrom(context), ) : Theme.of(context).textTheme.bodySmall?.copyWith( color: Theme.of(context).colorScheme.onSurfaceVariant, ); final TextStyle valueStyle = (cupertino ? CupertinoTheme.of(context).textTheme.textStyle : Theme.of(context).textTheme.bodyMedium) ?? const TextStyle(); return Padding( padding: padding, child: LayoutBuilder( builder: (context, constraints) { const gap = 16.0; final width = constraints.maxWidth; final columns = width >= kFactsGridThreeColumnWidth ? 3 : 2; final cell = (width - gap * (columns - 1)) / columns; return SizedBox( width: width, child: Wrap( spacing: gap, runSpacing: 12, children: [ for (final item in items) SizedBox( key: item.key, width: item.wide || item.monospace || item.value.length > kFactsGridLongValue ? width : cell, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(item.label, style: labelStyle), const SizedBox(height: 2), _value(item, valueStyle, cupertino), ], ), ), ], ), ); }, ), ); } Widget _value(FactsGridItem item, TextStyle base, bool cupertino) { final style = item.monospace ? base.copyWith(fontFamily: appMonospaceFamily) : base; if (cupertino || !selectable) return Text(item.value, style: style); return SelectableText(item.value, style: style); } }