mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-23 04:00:28 +08:00
refa: danmaku & feat: scroll fixed velocity (#1791)
This commit is contained in:
committed by
GitHub
parent
0a40d11133
commit
49b7ea14c3
28
lib/utils/extension/box_ext.dart
Normal file
28
lib/utils/extension/box_ext.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
extension BoxExt<E> on Box<E> {
|
||||
bool equal(dynamic key, E value) {
|
||||
return const DeepCollectionEquality().equals(value, get(key));
|
||||
}
|
||||
|
||||
Future<void>? putNE(dynamic key, E value) {
|
||||
if (!equal(key, value)) {
|
||||
return put(key, value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void>? putAllNE(Map<dynamic, E> entries) {
|
||||
final Map<dynamic, E> newEntries = {};
|
||||
entries.forEach((key, value) {
|
||||
if (!equal(key, value)) {
|
||||
newEntries[key] = value;
|
||||
}
|
||||
});
|
||||
if (newEntries.isNotEmpty) {
|
||||
return putAll(newEntries);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user