mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
new: tap server tab net io view to switch type
This commit is contained in:
@@ -13,6 +13,17 @@ enum NetViewType {
|
|||||||
@HiveField(2)
|
@HiveField(2)
|
||||||
traffic;
|
traffic;
|
||||||
|
|
||||||
|
NetViewType get next {
|
||||||
|
switch (this) {
|
||||||
|
case conn:
|
||||||
|
return speed;
|
||||||
|
case speed:
|
||||||
|
return traffic;
|
||||||
|
case traffic:
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String get toStr {
|
String get toStr {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case NetViewType.conn:
|
case NetViewType.conn:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class Disk {
|
|||||||
class DiskIO extends TimeSeq<DiskIOPiece> {
|
class DiskIO extends TimeSeq<DiskIOPiece> {
|
||||||
DiskIO(super.pre, super.now);
|
DiskIO(super.pre, super.now);
|
||||||
|
|
||||||
(String?, String?) getReadSpeed(String dev) {
|
(double?, double?) _getSpeed(String dev) {
|
||||||
final pres = this.pre.where(
|
final pres = this.pre.where(
|
||||||
(element) => element.dev == dev.replaceFirst('/dev/', ''),
|
(element) => element.dev == dev.replaceFirst('/dev/', ''),
|
||||||
);
|
);
|
||||||
@@ -37,11 +37,31 @@ class DiskIO extends TimeSeq<DiskIOPiece> {
|
|||||||
final sectorsRead = now.sectorsRead - pre.sectorsRead;
|
final sectorsRead = now.sectorsRead - pre.sectorsRead;
|
||||||
final sectorsWrite = now.sectorsWrite - pre.sectorsWrite;
|
final sectorsWrite = now.sectorsWrite - pre.sectorsWrite;
|
||||||
final time = now.time - pre.time;
|
final time = now.time - pre.time;
|
||||||
final read = '${(sectorsRead / time * 512).convertBytes}/s';
|
final read = (sectorsRead / time * 512);
|
||||||
final write = '${(sectorsWrite / time * 512).convertBytes}/s';
|
final write = (sectorsWrite / time * 512);
|
||||||
return (read, write);
|
return (read, write);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(String?, String?) getSpeed(String dev) {
|
||||||
|
final (read_, write_) = _getSpeed(dev);
|
||||||
|
final read = '${read_?.convertBytes}/s';
|
||||||
|
final write = '${write_?.convertBytes}/s';
|
||||||
|
return (read, write);
|
||||||
|
}
|
||||||
|
|
||||||
|
(String?, String?) getAllSpeed() {
|
||||||
|
if (pre.isEmpty || now.isEmpty) return (null, null);
|
||||||
|
var (read, write) = (0.0, 0.0);
|
||||||
|
for (var pre in pre) {
|
||||||
|
final (read_, write_) = _getSpeed(pre.dev);
|
||||||
|
read += read_ ?? 0;
|
||||||
|
write += write_ ?? 0;
|
||||||
|
}
|
||||||
|
final readStr = '${read.convertBytes}/s';
|
||||||
|
final writeStr = '${write.convertBytes}/s';
|
||||||
|
return (readStr, writeStr);
|
||||||
|
}
|
||||||
|
|
||||||
// Raw:
|
// Raw:
|
||||||
// 254 0 vda 584193 186416 40419294 845790 5024458 2028159 92899586 6997559 0 5728372 8143590 0 0 0 0 2006112 300240
|
// 254 0 vda 584193 186416 40419294 845790 5024458 2028159 92899586 6997559 0 5728372 8143590 0 0 0 0 2006112 300240
|
||||||
// 254 1 vda1 584029 186416 40412734 845668 5024453 2028159 92899586 6997558 0 5728264 7843226 0 0 0 0 0 0
|
// 254 1 vda1 584029 186416 40412734 845668 5024453 2028159 92899586 6997558 0 5728264 7843226 0 0 0 0 0 0
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import 'package:toolbox/data/model/server/system.dart';
|
|||||||
import 'package:toolbox/data/res/store.dart';
|
import 'package:toolbox/data/res/store.dart';
|
||||||
import 'package:toolbox/view/widget/expand_tile.dart';
|
import 'package:toolbox/view/widget/expand_tile.dart';
|
||||||
import 'package:toolbox/view/widget/server_func_btns.dart';
|
import 'package:toolbox/view/widget/server_func_btns.dart';
|
||||||
import 'package:toolbox/view/widget/value_notifier.dart';
|
|
||||||
|
|
||||||
import '../../../core/extension/numx.dart';
|
import '../../../core/extension/numx.dart';
|
||||||
import '../../../core/route.dart';
|
import '../../../core/route.dart';
|
||||||
@@ -53,7 +52,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
final _netSortType = ValueNotifier(_NetSortType.device);
|
var _netSortType = _NetSortType.device;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
@@ -328,7 +327,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDiskItem(Disk disk, ServerStatus ss) {
|
Widget _buildDiskItem(Disk disk, ServerStatus ss) {
|
||||||
final (read, write) = ss.diskIO.getReadSpeed(disk.dev);
|
final (read, write) = ss.diskIO.getSpeed(disk.dev);
|
||||||
final text = () {
|
final text = () {
|
||||||
final use = '${disk.used} / ${disk.size}';
|
final use = '${disk.used} / ${disk.size}';
|
||||||
if (read == null || write == null) return use;
|
if (read == null || write == null) return use;
|
||||||
@@ -377,32 +376,39 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
final devices = ns.devices;
|
final devices = ns.devices;
|
||||||
devices.sort(_netSortType.value.getSortFunc(ns));
|
devices.sort(_netSortType.getSortFunc(ns));
|
||||||
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
|
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||||
}
|
}
|
||||||
return ValueBuilder(
|
|
||||||
listenable: _netSortType,
|
|
||||||
build: () {
|
|
||||||
return CardX(
|
return CardX(
|
||||||
ExpandTile(
|
ExpandTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(l10n.net),
|
Text(l10n.net),
|
||||||
UIs.width13,
|
UIs.width13,
|
||||||
InkWell(
|
IconButton(
|
||||||
onTap: () {
|
onPressed: () {
|
||||||
_netSortType.value = _netSortType.value.next;
|
setState(() {
|
||||||
|
_netSortType = _netSortType.next;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
icon: AnimatedSwitcher(
|
||||||
|
duration: const Duration(milliseconds: 377),
|
||||||
|
transitionBuilder: (child, animation) => FadeTransition(
|
||||||
|
opacity: animation,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
key: ValueKey(_netSortType),
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.sort, size: 17),
|
const Icon(Icons.sort, size: 17),
|
||||||
UIs.width7,
|
UIs.width7,
|
||||||
Text(
|
Text(
|
||||||
_netSortType.value.name,
|
_netSortType.name,
|
||||||
style: UIs.textSize11Grey,
|
style: UIs.textSize11Grey,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -411,8 +417,6 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
children: children,
|
children: children,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNetSpeedItem(NetSpeed ns, String device) {
|
Widget _buildNetSpeedItem(NetSpeed ns, String device) {
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
|
|
||||||
final _flipedCardIds = <String>{};
|
final _flipedCardIds = <String>{};
|
||||||
|
|
||||||
|
final _netViewType = <String, NetViewType>{};
|
||||||
|
|
||||||
String? _tag;
|
String? _tag;
|
||||||
bool _useDoubleColumn = false;
|
bool _useDoubleColumn = false;
|
||||||
|
|
||||||
@@ -310,7 +312,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
children: [
|
children: [
|
||||||
_wrapWithSizedbox(_buildPercentCircle(ss.cpu.usedPercent())),
|
_wrapWithSizedbox(_buildPercentCircle(ss.cpu.usedPercent())),
|
||||||
_wrapWithSizedbox(_buildPercentCircle(ss.mem.usedPercent * 100)),
|
_wrapWithSizedbox(_buildPercentCircle(ss.mem.usedPercent * 100)),
|
||||||
_wrapWithSizedbox(_buildNet(ss)),
|
_wrapWithSizedbox(_buildNet(ss, spi.id)),
|
||||||
_wrapWithSizedbox(_buildIOData(
|
_wrapWithSizedbox(_buildIOData(
|
||||||
'Total:\n${rootDisk?.size}',
|
'Total:\n${rootDisk?.size}',
|
||||||
'Used:\n${rootDisk?.usedPercent}%',
|
'Used:\n${rootDisk?.usedPercent}%',
|
||||||
@@ -419,21 +421,29 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNet(ServerStatus ss) {
|
Widget _buildNet(ServerStatus ss, String id) {
|
||||||
return ValueListenableBuilder<NetViewType>(
|
final type = _netViewType[id] ?? Stores.setting.netViewType.fetch();
|
||||||
valueListenable: Stores.setting.netViewType.listenable(),
|
final data = type.build(ss);
|
||||||
builder: (_, val, __) {
|
|
||||||
final data = val.build(ss);
|
|
||||||
return AnimatedSwitcher(
|
return AnimatedSwitcher(
|
||||||
duration: const Duration(milliseconds: 177),
|
duration: const Duration(milliseconds: 377),
|
||||||
child: _buildIOData(data.up, data.down),
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
||||||
);
|
return FadeTransition(opacity: animation, child: child);
|
||||||
},
|
},
|
||||||
|
child: _buildIOData(
|
||||||
|
data.up,
|
||||||
|
data.down,
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_netViewType[id] = type.next;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
key: ValueKey(type)
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildIOData(String up, String down) {
|
Widget _buildIOData(String up, String down, {void Function()? onTap, Key? key}) {
|
||||||
return Column(
|
final child = Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
Text(
|
Text(
|
||||||
@@ -451,6 +461,13 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
if (onTap == null) return child;
|
||||||
|
return IconButton(
|
||||||
|
key: key,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||||
|
onPressed: onTap,
|
||||||
|
icon: child,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPercentCircle(double percent) {
|
Widget _buildPercentCircle(double percent) {
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
Widget _buildServer() {
|
Widget _buildServer() {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
_buildMoveOutServerFuncBtns(),
|
_buildServerFuncBtns(),
|
||||||
_buildSequence(),
|
_buildSequence(),
|
||||||
_buildNetViewType(),
|
_buildNetViewType(),
|
||||||
_buildUpdateInterval(),
|
_buildUpdateInterval(),
|
||||||
@@ -926,9 +926,13 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMoveOutServerFuncBtns() {
|
Widget _buildServerFuncBtns() {
|
||||||
return ExpandTile(
|
return ExpandTile(
|
||||||
title: Text(l10n.serverFuncBtns),
|
title: Text(l10n.serverFuncBtns),
|
||||||
|
subtitle: Text(
|
||||||
|
'${l10n.location} / ${l10n.displayName}',
|
||||||
|
style: UIs.textSize13Grey,
|
||||||
|
),
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(l10n.location),
|
title: Text(l10n.location),
|
||||||
|
|||||||
Reference in New Issue
Block a user