feat: Improve library search screen (#477)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-08-28 23:26:10 +02:00 committed by GitHub
parent 571b682b80
commit d22d340181
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 2881 additions and 2026 deletions

View file

@ -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,
);
}
}

View file

@ -11,6 +11,7 @@ class HideOnScroll extends ConsumerStatefulWidget {
final double height;
final Widget? Function(bool visible)? visibleBuilder;
final Duration duration;
final bool canHide;
final bool forceHide;
const HideOnScroll({
this.child,
@ -18,6 +19,7 @@ class HideOnScroll extends ConsumerStatefulWidget {
this.height = kBottomNavigationBarHeight,
this.visibleBuilder,
this.duration = const Duration(milliseconds: 200),
this.canHide = true,
this.forceHide = false,
super.key,
}) : assert(child != null || visibleBuilder != null);
@ -46,6 +48,12 @@ class _HideOnScrollState extends ConsumerState<HideOnScroll> {
}
void _onScroll() {
if (!widget.canHide) {
if (!isVisible) {
setState(() => isVisible = true);
}
return;
}
final position = scrollController.position;
final direction = position.userScrollDirection;
@ -78,9 +86,9 @@ class _HideOnScrollState extends ConsumerState<HideOnScroll> {
alignment: const Alignment(0, -1),
heightFactor: widget.forceHide
? 0
: isVisible
? 1.0
: 0,
: !isVisible && widget.canHide
? 0.0
: 1.0,
duration: widget.duration,
child: Wrap(
children: [widget.child!],