mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
Convert to not nullable
This commit is contained in:
@@ -6,9 +6,10 @@ class Cpu2Status {
|
|||||||
Cpu2Status(this.pre, this.now);
|
Cpu2Status(this.pre, this.now);
|
||||||
|
|
||||||
double usedPercent({int coreIdx = 0}) {
|
double usedPercent({int coreIdx = 0}) {
|
||||||
final used = (now[coreIdx].idle - pre[coreIdx].idle) /
|
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
|
||||||
(now[coreIdx].total - pre[coreIdx].total);
|
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
|
||||||
return used.isNaN ? 0 : used;
|
final used = idleDelta / totalDelta;
|
||||||
|
return used.isNaN ? 0 : 100 - used * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cpu2Status update(List<CpuStatus> newStatus) {
|
Cpu2Status update(List<CpuStatus> newStatus) {
|
||||||
|
|||||||
@@ -28,18 +28,18 @@ class ServerStatus {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Cpu2Status? cpu2Status;
|
late Cpu2Status cpu2Status;
|
||||||
List<int?>? memList;
|
late List<int?> memList;
|
||||||
String? sysVer;
|
late String sysVer;
|
||||||
String? uptime;
|
late String uptime;
|
||||||
List<DiskInfo?>? disk;
|
late List<DiskInfo?> disk;
|
||||||
TcpStatus? tcp;
|
late TcpStatus tcp;
|
||||||
|
|
||||||
ServerStatus(
|
ServerStatus(
|
||||||
{this.cpu2Status,
|
this.cpu2Status,
|
||||||
this.memList,
|
this.memList,
|
||||||
this.sysVer,
|
this.sysVer,
|
||||||
this.uptime,
|
this.uptime,
|
||||||
this.disk,
|
this.disk,
|
||||||
this.tcp});
|
this.tcp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ class ServerProvider extends BusyProvider {
|
|||||||
Cpu2Status([emptyCpuStatus], [emptyCpuStatus]);
|
Cpu2Status([emptyCpuStatus], [emptyCpuStatus]);
|
||||||
|
|
||||||
ServerStatus get emptyStatus => ServerStatus(
|
ServerStatus get emptyStatus => ServerStatus(
|
||||||
cpu2Status: emptyCpu2Status,
|
emptyCpu2Status,
|
||||||
memList: [100, 0],
|
[100, 0],
|
||||||
disk: [
|
'',
|
||||||
|
'',
|
||||||
|
[
|
||||||
DiskInfo(
|
DiskInfo(
|
||||||
mountLocation: '/',
|
mountLocation: '/',
|
||||||
mountPath: '/',
|
mountPath: '/',
|
||||||
@@ -39,9 +41,7 @@ class ServerProvider extends BusyProvider {
|
|||||||
avail: '0',
|
avail: '0',
|
||||||
usedPercent: 0)
|
usedPercent: 0)
|
||||||
],
|
],
|
||||||
sysVer: '',
|
TcpStatus(maxConn: 0, active: 0, passive: 0, fail: 0));
|
||||||
uptime: '',
|
|
||||||
tcp: TcpStatus(maxConn: 0, active: 0, passive: 0, fail: 0));
|
|
||||||
|
|
||||||
Future<void> loadLocalData() async {
|
Future<void> loadLocalData() async {
|
||||||
setBusyState(true);
|
setBusyState(true);
|
||||||
@@ -145,12 +145,12 @@ class ServerProvider extends BusyProvider {
|
|||||||
final tcp = await client.execute('cat /proc/net/snmp') ?? '';
|
final tcp = await client.execute('cat /proc/net/snmp') ?? '';
|
||||||
|
|
||||||
return ServerStatus(
|
return ServerStatus(
|
||||||
cpu2Status: _getCPU(cpu, _servers[idx].status.cpu2Status!),
|
_getCPU(cpu, _servers[idx].status.cpu2Status),
|
||||||
memList: _getMem(mem),
|
_getMem(mem),
|
||||||
sysVer: sysVer.trim(),
|
sysVer.trim(),
|
||||||
disk: _getDisk(disk),
|
_getUpTime(upTime),
|
||||||
uptime: _getUpTime(upTime),
|
_getDisk(disk),
|
||||||
tcp: _getTcp(tcp));
|
_getTcp(tcp));
|
||||||
}
|
}
|
||||||
|
|
||||||
Cpu2Status _getCPU(String raw, Cpu2Status old) {
|
Cpu2Status _getCPU(String raw, Cpu2Status old) {
|
||||||
|
|||||||
@@ -34,10 +34,15 @@ class _ServerDetailPageState extends State<ServerDetailPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCPUView(ServerStatus ss) {
|
Widget _buildCPUView(ServerStatus ss) {
|
||||||
return Text(ss.cpu2Status!.toString());
|
return ListView.builder(
|
||||||
|
itemBuilder: (ctx, idx) {
|
||||||
|
return Text('$idx ${ss.cpu2Status.usedPercent(coreIdx: idx)}');
|
||||||
|
},
|
||||||
|
itemCount: ss.cpu2Status.now.length,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMemView(ServerStatus ss) {
|
Widget _buildMemView(ServerStatus ss) {
|
||||||
return Text(ss.memList!.length.toString());
|
return Text(ss.memList.length.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
Widget _buildRealServerCard(
|
Widget _buildRealServerCard(
|
||||||
ServerStatus ss, String serverName, ServerConnectionState cs) {
|
ServerStatus ss, String serverName, ServerConnectionState cs) {
|
||||||
final rootDisk =
|
final rootDisk =
|
||||||
ss.disk!.firstWhere((element) => element!.mountLocation == '/');
|
ss.disk.firstWhere((element) => element!.mountLocation == '/');
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -123,7 +123,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
|
||||||
textScaleFactor: 1.0,
|
textScaleFactor: 1.0,
|
||||||
),
|
),
|
||||||
Text(getTopRightStr(cs, ss.uptime!),
|
Text(getTopRightStr(cs, ss.uptime),
|
||||||
textScaleFactor: 1.0,
|
textScaleFactor: 1.0,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: _theme.textTheme.bodyText1!.color!.withAlpha(100),
|
color: _theme.textTheme.bodyText1!.color!.withAlpha(100),
|
||||||
@@ -136,11 +136,11 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
_buildPercentCircle(ss.cpu2Status!.usedPercent(), 'CPU'),
|
_buildPercentCircle(ss.cpu2Status.usedPercent(), 'CPU'),
|
||||||
_buildPercentCircle(
|
_buildPercentCircle(
|
||||||
ss.memList![1]! / ss.memList![0]! * 100 + 0.01, 'Mem'),
|
ss.memList[1]! / ss.memList[0]! * 100 + 0.01, 'Mem'),
|
||||||
_buildIOData('Net', 'Conn:\n' + ss.tcp!.maxConn!.toString(),
|
_buildIOData('Net', 'Conn:\n' + ss.tcp.maxConn!.toString(),
|
||||||
'Fail:\n' + ss.tcp!.fail.toString()),
|
'Fail:\n' + ss.tcp.fail.toString()),
|
||||||
_buildIOData('Disk', 'Total:\n' + rootDisk!.size!,
|
_buildIOData('Disk', 'Total:\n' + rootDisk!.size!,
|
||||||
'Used:\n' + rootDisk.usedPercent.toString() + '%')
|
'Used:\n' + rootDisk.usedPercent.toString() + '%')
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user