mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07: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
|
|
@ -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> {
|
||||
|
|
|
|||
22
lib/util/position_provider.dart
Normal file
22
lib/util/position_provider.dart
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue