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

@ -37,15 +37,30 @@ extension MapExtensions<T> on Map<T, bool> {
bool get hasEnabled => values.any((element) => element == true);
//Replaces only keys that exist with the new values
Map<T, bool> replaceMap(Map<T, bool> oldMap) {
Map<T, bool> replaceMap(Map<T, bool> oldMap, {bool enabledOnly = false}) {
if (oldMap.isEmpty) return this;
Map<T, bool> result = {};
forEach((key, value) {
result[key] = oldMap[key] ?? false;
if (enabledOnly) {
if (oldMap[key] == true) {
result[key] = true;
} else {
result[key] = value;
}
} else {
result[key] = oldMap[key] ?? false;
}
});
return result;
}
Map<T, bool> sortByKey(String Function(T value) keySelector) {
final sortedEntries = entries.toList()..sort((a, b) => keySelector(a.key).compareTo(keySelector(b.key)));
return Map<T, bool>.fromEntries(sortedEntries);
}
}
extension MapExtensionsGeneric<K, V> on Map<K, V> {

View file

@ -0,0 +1,22 @@
import 'package:flutter/widgets.dart';
enum PositionContext { first, middle, last }
class PositionProvider extends InheritedWidget {
final PositionContext position;
const PositionProvider({
required this.position,
required super.child,
super.key,
});
static PositionContext of(BuildContext context) {
final provider = context.dependOnInheritedWidgetOfExactType<PositionProvider>();
assert(provider != null, 'No PositionProvider found in context');
return provider?.position ?? PositionContext.middle;
}
@override
bool updateShouldNotify(PositionProvider oldWidget) => position != oldWidget.position;
}