From 691471dae504faef76a075a5f1a6252e677db0dd Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sun, 19 Nov 2023 13:34:06 +0800 Subject: [PATCH] new: setting of `preferDiskAmount` --- lib/view/page/server/tab.dart | 45 ++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 328124437..078afbfe6 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -14,6 +14,7 @@ import 'package:toolbox/data/model/app/shell_func.dart'; import 'package:toolbox/data/model/server/try_limiter.dart'; import 'package:toolbox/data/res/provider.dart'; import 'package:toolbox/data/res/store.dart'; +import 'package:toolbox/view/widget/value_notifier.dart'; import '../../../core/route.dart'; import '../../../data/model/app/net_view.dart'; @@ -430,26 +431,32 @@ class _ServerPageState extends State } Widget _buildDisk(ServerStatus ss, String id) { - final rootDisk = findRootDisk(ss.disk); - final isSpeed = _diskViewSpeed[id] ?? !Stores.setting.serverTabPreferDiskAmount.fetch(); - - final (r, w) = ss.diskIO.getAllSpeed(); - - return AnimatedSwitcher( - duration: const Duration(milliseconds: 377), - transitionBuilder: (Widget child, Animation animation) { - return FadeTransition(opacity: animation, child: child); + return ValueBuilder( + listenable: Stores.setting.serverTabPreferDiskAmount.listenable(), + build: () { + final rootDisk = findRootDisk(ss.disk); + final isSpeed = _diskViewSpeed[id] ?? + !Stores.setting.serverTabPreferDiskAmount.fetch(); + + final (r, w) = ss.diskIO.getAllSpeed(); + + return AnimatedSwitcher( + duration: const Duration(milliseconds: 377), + transitionBuilder: (Widget child, Animation animation) { + return FadeTransition(opacity: animation, child: child); + }, + child: _buildIOData( + isSpeed ? '${l10n.read}:\n$r' : 'Total:\n${rootDisk?.size}', + isSpeed ? '${l10n.write}:\n$w' : 'Used:\n${rootDisk?.usedPercent}%', + onTap: () { + setState(() { + _diskViewSpeed[id] = !isSpeed; + }); + }, + key: ValueKey(isSpeed), + ), + ); }, - child: _buildIOData( - isSpeed ? '${l10n.read}:\n$r' : 'Total:\n${rootDisk?.size}', - isSpeed ? '${l10n.write}:\n$w' : 'Used:\n${rootDisk?.usedPercent}%', - onTap: () { - setState(() { - _diskViewSpeed[id] = !isSpeed; - }); - }, - key: ValueKey(isSpeed), - ), ); }