9adee6cc60
Keep the public Cupertino-compatible parameters while retaining only the Material implementations and tests. The app is Material-only, so deleting unreachable Cupertino branches reduces dead code without changing the active path.
89 lines
2.4 KiB
Dart
89 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../adaptive/glass_bar.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) {
|
|
Widget chevron({
|
|
required Key? key,
|
|
required bool previous,
|
|
required String label,
|
|
required VoidCallback? onPressed,
|
|
}) {
|
|
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(false);
|
|
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,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|