Files
PiliPlus/lib/utils/extension/num_ext.dart
bggRGjQaUbCoE 20a36e8f9a tweaks
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
2025-12-25 13:46:21 +08:00

25 lines
628 B
Dart

import 'dart:math' show pow;
import 'package:flutter/widgets.dart';
extension ImageExtension on num {
int? cacheSize(BuildContext context) {
if (this == 0) {
return null;
}
return (this * MediaQuery.devicePixelRatioOf(context)).round();
}
}
extension IntExt on int? {
int? operator +(int other) => this == null ? null : this! + other;
int? operator -(int other) => this == null ? null : this! - other;
}
extension DoubleExt on double {
double toPrecision(int fractionDigits) {
var mod = pow(10, fractionDigits.toDouble()).toDouble();
return ((this * mod).round().toDouble() / mod);
}
}