mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
feat: Improve library search screen (#477)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
571b682b80
commit
d22d340181
41 changed files with 2881 additions and 2026 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fladder/util/position_provider.dart';
|
||||
|
||||
class ExpressiveButtonGroup<T> extends StatelessWidget {
|
||||
final List<ButtonGroupOption<T>> options;
|
||||
final Set<T> selectedValues;
|
||||
|
|
@ -20,44 +22,77 @@ class ExpressiveButtonGroup<T> extends StatelessWidget {
|
|||
mainAxisSize: MainAxisSize.max,
|
||||
spacing: 2,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: List.generate(options.length, (index) {
|
||||
final option = options[index];
|
||||
final isSelected = selectedValues.contains(option.value);
|
||||
final isFirst = index == 0;
|
||||
final isLast = index == options.length - 1;
|
||||
children: List.generate(
|
||||
options.length,
|
||||
(index) {
|
||||
final option = options[index];
|
||||
final isSelected = selectedValues.contains(option.value);
|
||||
|
||||
final borderRadius = BorderRadius.horizontal(
|
||||
left: isSelected || isFirst ? const Radius.circular(20) : const Radius.circular(6),
|
||||
right: isSelected || isLast ? const Radius.circular(20) : const Radius.circular(6),
|
||||
);
|
||||
final position = index == 0
|
||||
? PositionContext.first
|
||||
: (index == options.length - 1 ? PositionContext.last : PositionContext.middle);
|
||||
|
||||
return ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(borderRadius: borderRadius),
|
||||
elevation: isSelected ? 3 : 0,
|
||||
backgroundColor: isSelected
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
foregroundColor:
|
||||
isSelected ? Theme.of(context).colorScheme.onPrimary : Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
textStyle: Theme.of(context).textTheme.labelLarge,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
onPressed: () {
|
||||
final newSet = Set<T>.from(selectedValues);
|
||||
if (multiSelection) {
|
||||
isSelected ? newSet.remove(option.value) : newSet.add(option.value);
|
||||
} else {
|
||||
newSet
|
||||
..clear()
|
||||
..add(option.value);
|
||||
}
|
||||
onSelected(newSet);
|
||||
},
|
||||
label: option.child,
|
||||
icon: isSelected ? option.selected ?? const Icon(Icons.check_rounded) : option.icon,
|
||||
);
|
||||
}),
|
||||
return PositionProvider(
|
||||
position: position,
|
||||
child: ExpressiveButton(
|
||||
isSelected: isSelected,
|
||||
label: option.child,
|
||||
icon: isSelected ? option.selected ?? const Icon(Icons.check_rounded) : option.icon,
|
||||
onPressed: () {
|
||||
final newSet = Set<T>.from(selectedValues);
|
||||
if (multiSelection) {
|
||||
isSelected ? newSet.remove(option.value) : newSet.add(option.value);
|
||||
} else {
|
||||
newSet
|
||||
..clear()
|
||||
..add(option.value);
|
||||
}
|
||||
onSelected(newSet);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ExpressiveButton extends StatelessWidget {
|
||||
const ExpressiveButton({
|
||||
super.key,
|
||||
required this.isSelected,
|
||||
required this.label,
|
||||
this.icon,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final bool isSelected;
|
||||
final Widget label;
|
||||
final Widget? icon;
|
||||
final Function()? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final position = PositionProvider.of(context);
|
||||
final borderRadius = BorderRadius.horizontal(
|
||||
left: isSelected || position == PositionContext.first ? const Radius.circular(16) : const Radius.circular(4),
|
||||
right: isSelected || position == PositionContext.last ? const Radius.circular(16) : const Radius.circular(4),
|
||||
);
|
||||
return ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(borderRadius: borderRadius),
|
||||
elevation: isSelected ? 4 : 0,
|
||||
backgroundColor:
|
||||
isSelected ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
foregroundColor:
|
||||
isSelected ? Theme.of(context).colorScheme.onPrimary : Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
textStyle: Theme.of(context).textTheme.labelLarge,
|
||||
visualDensity: VisualDensity.comfortable,
|
||||
padding: const EdgeInsets.all(12),
|
||||
),
|
||||
onPressed: onPressed,
|
||||
label: label,
|
||||
icon: icon,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue