new: tap server tab net io view to switch type
This commit is contained in:
@@ -11,7 +11,6 @@ import 'package:toolbox/data/model/server/system.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/view/widget/expand_tile.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/route.dart';
|
||||
@@ -53,7 +52,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
],
|
||||
);
|
||||
|
||||
final _netSortType = ValueNotifier(_NetSortType.device);
|
||||
var _netSortType = _NetSortType.device;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
@@ -328,7 +327,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
}
|
||||
|
||||
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 use = '${disk.used} / ${disk.size}';
|
||||
if (read == null || write == null) return use;
|
||||
@@ -377,41 +376,46 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
));
|
||||
} else {
|
||||
final devices = ns.devices;
|
||||
devices.sort(_netSortType.value.getSortFunc(ns));
|
||||
devices.sort(_netSortType.getSortFunc(ns));
|
||||
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
|
||||
}
|
||||
return ValueBuilder(
|
||||
listenable: _netSortType,
|
||||
build: () {
|
||||
return CardX(
|
||||
ExpandTile(
|
||||
title: Row(
|
||||
children: [
|
||||
Text(l10n.net),
|
||||
UIs.width13,
|
||||
InkWell(
|
||||
onTap: () {
|
||||
_netSortType.value = _netSortType.value.next;
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.sort, size: 17),
|
||||
UIs.width7,
|
||||
Text(
|
||||
_netSortType.value.name,
|
||||
style: UIs.textSize11Grey,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
leading: const Icon(Icons.device_hub, size: 17),
|
||||
initiallyExpanded: children.length <= 7,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
},
|
||||
return CardX(
|
||||
ExpandTile(
|
||||
title: Row(
|
||||
children: [
|
||||
Text(l10n.net),
|
||||
UIs.width13,
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_netSortType = _netSortType.next;
|
||||
});
|
||||
},
|
||||
icon: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 377),
|
||||
transitionBuilder: (child, animation) => FadeTransition(
|
||||
opacity: animation,
|
||||
child: child,
|
||||
),
|
||||
child: Row(
|
||||
key: ValueKey(_netSortType),
|
||||
children: [
|
||||
const Icon(Icons.sort, size: 17),
|
||||
UIs.width7,
|
||||
Text(
|
||||
_netSortType.name,
|
||||
style: UIs.textSize11Grey,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
leading: const Icon(Icons.device_hub, size: 17),
|
||||
initiallyExpanded: children.length <= 7,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ class _ServerPageState extends State<ServerPage>
|
||||
|
||||
final _flipedCardIds = <String>{};
|
||||
|
||||
final _netViewType = <String, NetViewType>{};
|
||||
|
||||
String? _tag;
|
||||
bool _useDoubleColumn = false;
|
||||
|
||||
@@ -310,7 +312,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
children: [
|
||||
_wrapWithSizedbox(_buildPercentCircle(ss.cpu.usedPercent())),
|
||||
_wrapWithSizedbox(_buildPercentCircle(ss.mem.usedPercent * 100)),
|
||||
_wrapWithSizedbox(_buildNet(ss)),
|
||||
_wrapWithSizedbox(_buildNet(ss, spi.id)),
|
||||
_wrapWithSizedbox(_buildIOData(
|
||||
'Total:\n${rootDisk?.size}',
|
||||
'Used:\n${rootDisk?.usedPercent}%',
|
||||
@@ -419,21 +421,29 @@ class _ServerPageState extends State<ServerPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNet(ServerStatus ss) {
|
||||
return ValueListenableBuilder<NetViewType>(
|
||||
valueListenable: Stores.setting.netViewType.listenable(),
|
||||
builder: (_, val, __) {
|
||||
final data = val.build(ss);
|
||||
return AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 177),
|
||||
child: _buildIOData(data.up, data.down),
|
||||
);
|
||||
Widget _buildNet(ServerStatus ss, String id) {
|
||||
final type = _netViewType[id] ?? Stores.setting.netViewType.fetch();
|
||||
final data = type.build(ss);
|
||||
return AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 377),
|
||||
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) {
|
||||
return Column(
|
||||
Widget _buildIOData(String up, String down, {void Function()? onTap, Key? key}) {
|
||||
final child = Column(
|
||||
children: [
|
||||
const SizedBox(height: 5),
|
||||
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) {
|
||||
|
||||
@@ -211,7 +211,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
Widget _buildServer() {
|
||||
return Column(
|
||||
children: [
|
||||
_buildMoveOutServerFuncBtns(),
|
||||
_buildServerFuncBtns(),
|
||||
_buildSequence(),
|
||||
_buildNetViewType(),
|
||||
_buildUpdateInterval(),
|
||||
@@ -926,9 +926,13 @@ class _SettingPageState extends State<SettingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMoveOutServerFuncBtns() {
|
||||
Widget _buildServerFuncBtns() {
|
||||
return ExpandTile(
|
||||
title: Text(l10n.serverFuncBtns),
|
||||
subtitle: Text(
|
||||
'${l10n.location} / ${l10n.displayName}',
|
||||
style: UIs.textSize13Grey,
|
||||
),
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(l10n.location),
|
||||
|
||||
Reference in New Issue
Block a user