Files
pipelines/app/lib/ui/navigation/chevron_pager.dart
T

111 lines
3.0 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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: const Size(44, 44),
onPressed: onPressed,
child: Icon(
previous
? CupertinoIcons.chevron_left
: CupertinoIcons.chevron_right,
size: 30,
),
),
);
}
return IconButton(
key: key,
tooltip: label,
constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
padding: EdgeInsets.zero,
onPressed: onPressed,
icon: Icon(
previous ? Icons.chevron_left : Icons.chevron_right,
size: 28,
),
);
}
return Padding(
// The surrounding glass pill supplies the edge gap. Keeping this row's
// horizontal padding at zero also leaves room for four 48px controls on
// a narrow phone at large text sizes.
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Flexible(
fit: FlexFit.tight,
child: Text(
'${index + 1} of $count',
key: positionKey,
style: Theme.of(context).textTheme.labelLarge,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 0),
chevron(
key: previousKey,
previous: true,
label: previousLabel,
onPressed: onPrevious,
),
chevron(
key: nextKey,
previous: false,
label: nextLabel,
onPressed: onNext,
),
],
),
);
}
}