Add filter to subscription-list

This commit is contained in:
2025-11-09 22:51:37 +01:00
parent febc0a8f43
commit 1aadd9c368
4 changed files with 110 additions and 7 deletions

View File

@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
class FilterChips<T extends Enum> extends StatelessWidget {
final List<(T, String)> options;
final T value;
final void Function(T)? onChanged;
const FilterChips({
Key? key,
required this.options,
required this.value,
required this.onChanged,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
for (var opt in options) _buildChiplet(context, opt.$1, opt.$2),
],
),
);
}
Widget _buildChiplet(BuildContext context, T optValue, String optText) {
final isSelected = optValue == value;
return Padding(
padding: const EdgeInsets.fromLTRB(0, 2, 4, 2),
child: InputChip(
label: Text(
optText,
style: isSelected ? TextStyle(color: Theme.of(context).colorScheme.onPrimary) : null,
),
visualDensity: VisualDensity(horizontal: -4, vertical: -4),
isEnabled: true,
selected: true,
showCheckmark: false,
onPressed: () {
if (!isSelected) onChanged?.call(optValue);
},
selectedColor: isSelected ? Theme.of(context).colorScheme.primary : null,
),
);
}
}