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) {

View File

@@ -28,18 +28,18 @@ class ServerStatus {
}
*/
Cpu2Status? cpu2Status;
List<int?>? memList;
String? sysVer;
String? uptime;
List<DiskInfo?>? disk;
TcpStatus? tcp;
late Cpu2Status cpu2Status;
late List<int?> memList;
late String sysVer;
late String uptime;
late List<DiskInfo?> disk;
late TcpStatus tcp;
ServerStatus(
{this.cpu2Status,
this.cpu2Status,
this.memList,
this.sysVer,
this.uptime,
this.disk,
this.tcp});
this.tcp);
}