Files
pipelines/app/lib/ui/navigation/chevron_pager.dart
T
alan 4d9ee1ea78 Give glass control bars equal end and edge gaps
Inside a glass bar the first and last controls now keep the same gap from
the pill's sides as from its top and bottom, from shared GlassBarMetrics
(48/44 targets, 8 edge gap). Applies to the artifact viewer bar (hugs its
actions without a pager), the chevron pagers (position text inset like an
icon), and the chat composer's Cupertino Send/Stop (centred circle).
Run 7 in the full-app probe now records change captures for diff captures.
2026-11-02 18:35:37 +00:00

112 lines
3.2 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/glass_bar.dart';
import '../adaptive/host.dart';
/// Previous and next as chevrons in one row at the bottom right, with the
/// position before them (`2 of 5`). Each chevron is named for assistive
/// technology ([previousLabel], [nextLabel]); an end of the list disables its
/// chevron rather than hiding it, so the row never shifts.
class ChevronPager extends StatelessWidget {
const ChevronPager({
super.key,
required this.index,
required this.count,
required this.previousLabel,
required this.nextLabel,
this.onPrevious,
this.onNext,
this.previousKey,
this.nextKey,
this.positionKey,
});
final int index;
final int count;
final String previousLabel;
final String nextLabel;
final VoidCallback? onPrevious;
final VoidCallback? onNext;
final Key? previousKey;
final Key? nextKey;
final Key? positionKey;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
Widget chevron({
required Key? key,
required bool previous,
required String label,
required VoidCallback? onPressed,
}) {
if (cupertino) {
return Semantics(
button: true,
enabled: onPressed != null,
label: label,
excludeSemantics: true,
child: CupertinoButton(
key: key,
padding: EdgeInsets.zero,
minimumSize: GlassBarMetrics.cupertinoMinimumSize(),
onPressed: onPressed,
child: Icon(
previous
? CupertinoIcons.chevron_left
: CupertinoIcons.chevron_right,
size: GlassBarMetrics.iconSize(true),
),
),
);
}
return IconButton(
key: key,
tooltip: label,
constraints: GlassBarMetrics.materialConstraints(),
padding: EdgeInsets.zero,
onPressed: onPressed,
icon: Icon(
previous ? Icons.chevron_left : Icons.chevron_right,
size: GlassBarMetrics.iconSize(false),
),
);
}
// The surrounding glass bar supplies the edge gap ([GlassBarMetrics]).
// The position keeps an icon's inset on each side, so it sits as far from
// the bar's edge and from the chevrons as an icon would.
final inset = GlassBarMetrics.iconInset(cupertino);
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: inset),
child: Text(
'${index + 1} of $count',
key: positionKey,
style: Theme.of(context).textTheme.labelLarge,
overflow: TextOverflow.ellipsis,
),
),
),
chevron(
key: previousKey,
previous: true,
label: previousLabel,
onPressed: onPrevious,
),
chevron(
key: nextKey,
previous: false,
label: nextLabel,
onPressed: onNext,
),
],
);
}
}