mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-02 16:19:44 +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;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ extension IntExt on int? {
|
||||
|
||||
extension DoubleExt on double {
|
||||
double toPrecision(int fractionDigits) {
|
||||
final mod = pow(10, fractionDigits.toDouble()).toDouble();
|
||||
return ((this * mod).round().toDouble() / mod);
|
||||
final mod = pow(10, fractionDigits).toDouble();
|
||||
return (this * mod).roundToDouble() / mod;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user