Files
pipelines/app/lib/ui/adaptive/floating_destination_labels.dart
T

73 lines
2.3 KiB
Dart

import 'dart:ui' show SemanticsRole;
import 'package:flutter/cupertino.dart';
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.cupertino,
required this.labels,
required this.selected,
required this.buttonBuilder,
required this.onTap,
});
final bool cupertino;
final List<String> labels;
final int selected;
final Widget Function(int) buttonBuilder;
final ValueChanged<int> onTap;
@override
Widget build(BuildContext context) {
final color = cupertino
? CupertinoColors.label.resolveFrom(context)
: Theme.of(context).colorScheme.onSurface;
final style = cupertino
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle
: 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,
),
),
),
],
),
),
),
],
),
),
);
}
}