Convert to not nullable

This commit is contained in:
LollipopKit
2021-10-28 09:33:39 +08:00
parent 5843219289
commit 2dbb1a1857
5 changed files with 37 additions and 31 deletions

View File

@@ -6,9 +6,10 @@ class Cpu2Status {
Cpu2Status(this.pre, this.now);
double usedPercent({int coreIdx = 0}) {
final used = (now[coreIdx].idle - pre[coreIdx].idle) /
(now[coreIdx].total - pre[coreIdx].total);
return used.isNaN ? 0 : used;
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
final used = idleDelta / totalDelta;
return used.isNaN ? 0 : 100 - used * 100;
}
Cpu2Status update(List<CpuStatus> newStatus) {