Add filter to subscription-list
This commit is contained in:
47
flutter/lib/components/filter_chips/filter_chips.dart
Normal file
47
flutter/lib/components/filter_chips/filter_chips.dart
Normal 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user