import 'package:flutter/material.dart'; import 'run_detail_tab.dart'; import 'run_detail_tab_strip.dart'; /// The run detail's tabs on a wide layout: a Material [SegmentedButton] of /// icon-and-label segments under the run header, at the top of the detail /// where the eye already is, with labels at the button text size. /// /// The segments keep their order and positions across runs: Artifacts is /// always one, disabled with a `0` count when the run recorded none. Keys /// match the phone bar's: the whole row `run-detail-tabs`, each label /// `run-detail-tab-`. class RunDetailTopTabs extends StatelessWidget { const RunDetailTopTabs({ super.key, required this.tabs, required this.selected, required this.onSelected, this.artifactCount, this.disabled = const {}, this.disabledReasons = const {}, }); final List tabs; final RunDetailTab selected; final ValueChanged onSelected; final int? artifactCount; final Set disabled; /// Why a disabled tab cannot open, as its tooltip. final Map disabledReasons; @override Widget build(BuildContext context) { final count = artifactCount; final scheme = Theme.of(context).colorScheme; return Align( key: const Key('run-detail-tabs'), alignment: AlignmentDirectional.centerStart, child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: SegmentedButton( showSelectedIcon: false, // On the frosted strip the unselected segments take the surface, // so the selected one's tonal fill stands out from the glass. style: ButtonStyle( backgroundColor: WidgetStateProperty.resolveWith( (states) => states.contains(WidgetState.selected) ? scheme.secondaryContainer : scheme.surface, ), ), segments: [ for (final tab in tabs) ButtonSegment( value: tab, enabled: !disabled.contains(tab), tooltip: disabled.contains(tab) ? disabledReasons[tab] : null, icon: Icon(tab.icon), label: Row( key: ValueKey('run-detail-tab-${tab.name}'), mainAxisSize: MainAxisSize.min, children: [ Text(tab.label), if (tab == RunDetailTab.artifacts && count != null) ...[ const SizedBox(width: 6), RunArtifactsCount(count: count), ], ], ), ), ], selected: {selected}, onSelectionChanged: (value) { if (value.isNotEmpty) onSelected(value.first); }, ), ), ); } }