55 lines
1.7 KiB
Dart
55 lines
1.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:please_pay_me/theme/tokens.dart';
|
|
|
|
/// iOS sliding segmented control — the native alternative to tabs.
|
|
class AppSegmentedControl extends StatelessWidget {
|
|
const AppSegmentedControl({
|
|
super.key,
|
|
required this.labels,
|
|
required this.index,
|
|
required this.onChanged,
|
|
this.padding = const EdgeInsets.symmetric(horizontal: AppSpacing.gutter),
|
|
});
|
|
|
|
final List<String> labels;
|
|
final int index;
|
|
final ValueChanged<int> onChanged;
|
|
final EdgeInsetsGeometry padding;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: padding,
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: CupertinoSlidingSegmentedControl<int>(
|
|
groupValue: index.clamp(0, labels.length - 1),
|
|
backgroundColor: AppColors.of(context, AppColors.systemGray5),
|
|
thumbColor: AppColors.of(context, AppColors.groupedSurface),
|
|
onValueChanged: (value) {
|
|
if (value != null) onChanged(value);
|
|
},
|
|
children: {
|
|
for (var i = 0; i < labels.length; i++)
|
|
i: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
child: Text(
|
|
labels[i],
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: GoogleFonts.inter(
|
|
textStyle: AppTypography.subhead.copyWith(
|
|
fontWeight: i == index ? FontWeight.w600 : FontWeight.w400,
|
|
),
|
|
color: AppColors.of(context, AppColors.label),
|
|
),
|
|
),
|
|
),
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|