import 'dart:ui' show SemanticsRole; import 'package:flutter/material.dart'; /// Content-driven main navigation captions keep names visible without scaling /// down touch targets. Narrow lists and large text wrap into another row. class FloatingDestinationLabels extends StatelessWidget { const FloatingDestinationLabels({ super.key, required this.labels, required this.selected, required this.buttonBuilder, required this.onTap, }); final List labels; final int selected; final Widget Function(int) buttonBuilder; final ValueChanged onTap; @override Widget build(BuildContext context) { final color = Theme.of(context).colorScheme.onSurface; final style = Theme.of(context).textTheme.labelSmall!; return Semantics( role: SemanticsRole.tabBar, container: true, explicitChildNodes: true, child: Padding( padding: const EdgeInsets.all(8), child: Wrap( alignment: WrapAlignment.center, crossAxisAlignment: WrapCrossAlignment.center, spacing: 8, runSpacing: 8, children: [ for (var index = 0; index < labels.length; index++) GestureDetector( key: ValueKey('destination-label-${labels[index]}'), excludeFromSemantics: true, onTap: () => onTap(index), child: TextFieldTapRegion( child: Column( mainAxisSize: MainAxisSize.min, children: [ buttonBuilder(index), ExcludeSemantics( child: Text( labels[index], style: style.copyWith( color: color, fontWeight: index == selected ? FontWeight.w600 : style.fontWeight, ), ), ), ], ), ), ), ], ), ), ); } }