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: const EdgeInsets.all(8), onPressed: onPressed, child: Icon( previous ? CupertinoIcons.chevron_left : CupertinoIcons.chevron_right, ), ), ); } return IconButton( key: key, tooltip: label, onPressed: onPressed, icon: Icon(previous ? Icons.chevron_left : Icons.chevron_right), ); } return Padding( padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 4), child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Flexible( child: Text( '${index + 1} of $count', key: positionKey, overflow: TextOverflow.ellipsis, ), ), const SizedBox(width: 4), chevron( key: previousKey, previous: true, label: previousLabel, onPressed: onPrevious, ), chevron( key: nextKey, previous: false, label: nextLabel, onPressed: onNext, ), ], ), ); } }