Skip to content

Commit

Permalink
opt.
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Dec 27, 2023
1 parent 3a3ba4d commit 5284cee
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 89 deletions.
19 changes: 7 additions & 12 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/locale.dart';
import 'package:toolbox/data/res/rebuild.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/view/widget/value_notifier.dart';

import 'core/utils/ui.dart';
import 'data/res/build_data.dart';
Expand All @@ -27,20 +26,16 @@ class MyApp extends StatelessWidget {
}

Widget _wrapTheme(BuildContext context) {
return ValueBuilder(
return ListenableBuilder(
listenable: RebuildNodes.app,
build: () {
builder: (_, __) {
final tMode = Stores.setting.themeMode.fetch();
// Issue #57
var themeMode = ThemeMode.system;
switch (tMode) {
case 1 || 2:
themeMode = ThemeMode.values[tMode];
break;
case 3:
themeMode = ThemeMode.dark;
break;
}
final themeMode = switch (tMode) {
1 || 2 => ThemeMode.values[tMode],
3 => ThemeMode.dark,
_ => ThemeMode.system,
};
final locale = Stores.setting.locale.fetch().toLocale;
final darkTheme = ThemeData(
useMaterial3: true,
Expand Down
6 changes: 1 addition & 5 deletions lib/data/model/app/rebuild.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/foundation.dart';

// ignore: prefer_void_to_null
class RebuildNode implements ValueListenable<Null> {
class RebuildNode implements Listenable {
final List<VoidCallback> _listeners = [];

RebuildNode();
Expand All @@ -21,7 +20,4 @@ class RebuildNode implements ValueListenable<Null> {
listener();
}
}

@override
Null get value => null;
}
5 changes: 2 additions & 3 deletions lib/view/page/backup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import 'package:toolbox/view/widget/expand_tile.dart';
import 'package:toolbox/view/widget/cardx.dart';
import 'package:toolbox/view/widget/input_field.dart';
import 'package:toolbox/view/widget/store_switch.dart';
import 'package:toolbox/view/widget/value_notifier.dart';

class BackupPage extends StatelessWidget {
BackupPage({super.key});
Expand Down Expand Up @@ -161,9 +160,9 @@ class BackupPage extends StatelessWidget {
),
ListTile(
title: Text(l10n.manual),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: webdavLoading,
build: () {
builder: (_, __) {
if (webdavLoading.value) {
return UIs.centerSizedLoadingSmall;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/view/page/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import '../../data/res/url.dart';
import '../widget/appbar.dart';
import '../widget/cardx.dart';
import '../widget/url_text.dart';
import '../widget/value_notifier.dart';

class HomePage extends StatefulWidget {
const HomePage({super.key});
Expand Down Expand Up @@ -114,6 +113,7 @@ class _HomePageState extends State<HomePage>
return Scaffold(
drawer: _buildDrawer(),
appBar: CustomAppBar(
centerTitle: false,
title: const Text(BuildData.name),
actions: <Widget>[
IconButton(
Expand All @@ -133,9 +133,9 @@ class _HomePageState extends State<HomePage>
}
},
),
bottomNavigationBar: ValueBuilder(
bottomNavigationBar: ListenableBuilder(
listenable: _selectIndex,
build: _buildBottomBar,
builder: (_, __) => _buildBottomBar(),
),
);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/view/page/ping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:toolbox/core/extension/context/snackbar.dart';
import 'package:toolbox/core/extension/uint8list.dart';
import 'package:toolbox/core/utils/share.dart';
import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/view/widget/value_notifier.dart';

import '../../data/model/server/ping_result.dart';
import '../../data/res/color.dart';
Expand Down Expand Up @@ -49,9 +48,9 @@ class _PingPageState extends State<PingPage>
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
body: ValueBuilder(
body: ListenableBuilder(
listenable: _results,
build: _buildBody,
builder: (_, __) => _buildBody(),
),
floatingActionButton: _buildFAB(),
);
Expand Down
21 changes: 10 additions & 11 deletions lib/view/page/server/edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import '../../widget/appbar.dart';
import '../../widget/input_field.dart';
import '../../widget/cardx.dart';
import '../../widget/tag.dart';
import '../../widget/value_notifier.dart';

class ServerEditPage extends StatefulWidget {
const ServerEditPage({super.key, this.spi});
Expand Down Expand Up @@ -221,9 +220,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
_buildJumpServer(),
ListTile(
title: Text(l10n.autoConnect),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _autoConnect,
build: () => Switch(
builder: (_, __) => Switch(
value: _autoConnect.value,
onChanged: (val) {
_autoConnect.value = val;
Expand All @@ -245,9 +244,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
Widget _buildAuth() {
final switch_ = ListTile(
title: Text(l10n.keyAuth),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _keyIdx,
build: () => Switch(
builder: (_, __) => Switch(
value: _keyIdx.value != null,
onChanged: (val) {
if (val) {
Expand All @@ -261,9 +260,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
);

/// Put [switch_] out of [ValueBuilder] to avoid rebuild
return ValueBuilder(
return ListenableBuilder(
listenable: _keyIdx,
build: () {
builder: (_, __) {
final children = <Widget>[switch_];
if (_keyIdx.value != null) {
children.add(_buildKeyAuth());
Expand Down Expand Up @@ -334,9 +333,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
}

Widget _buildRadio(int index, PrivateKeyInfo pki) {
return ValueBuilder(
return ListenableBuilder(
listenable: _keyIdx,
build: () => Radio<int>(
builder: (_, __) => Radio<int>(
value: index,
groupValue: _keyIdx.value,
onChanged: (value) {
Expand All @@ -347,9 +346,9 @@ class _ServerEditPageState extends State<ServerEditPage> {
}

Widget _buildJumpServer() {
return ValueBuilder(
return ListenableBuilder(
listenable: _jumpServer,
build: () {
builder: (_, __) {
final children = Pros.server.servers
.where((element) => element.spi.jumpId == null)
.where((element) => element.spi.id != widget.spi?.id)
Expand Down
13 changes: 6 additions & 7 deletions lib/view/page/server/tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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';
Expand Down Expand Up @@ -61,9 +60,9 @@ class _ServerPageState extends State<ServerPage>
super.build(context);
return Scaffold(
appBar: _buildTagsSwitcher(Pros.server),
body: ValueBuilder(
body: ListenableBuilder(
listenable: Stores.setting.textFactor.listenable(),
build: () {
builder: (_, __) {
_textFactorDouble = Stores.setting.textFactor.fetch();
_textFactor = TextScaler.linear(_textFactorDouble);
return _buildBody();
Expand Down Expand Up @@ -200,9 +199,9 @@ class _ServerPageState extends State<ServerPage>
final cardStatus = _getCardNoti(id);
final title = _buildServerCardTitle(srv.status, srv.state, srv.spi);

return ValueBuilder(
return ListenableBuilder(
listenable: cardStatus,
build: () {
builder: (_, __) {
late final List<Widget> children;
if (srv.state == ServerState.finished) {
if (cardStatus.value.flip) {
Expand Down Expand Up @@ -417,9 +416,9 @@ class _ServerPageState extends State<ServerPage>

Widget _buildDisk(ServerStatus ss, String id) {
final cardNoti = _getCardNoti(id);
return ValueBuilder(
return ListenableBuilder(
listenable: cardNoti,
build: () {
builder: (_, __) {
final rootDisk = findRootDisk(ss.disk);
final isSpeed = cardNoti.value.diskIO ??
!Stores.setting.serverTabPreferDiskAmount.fetch();
Expand Down
53 changes: 26 additions & 27 deletions lib/view/page/setting/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import '../../widget/appbar.dart';
import '../../widget/input_field.dart';
import '../../widget/cardx.dart';
import '../../widget/store_switch.dart';
import '../../widget/value_notifier.dart';

class SettingPage extends StatefulWidget {
const SettingPage({super.key});
Expand Down Expand Up @@ -285,9 +284,9 @@ class _SettingPageState extends State<SettingPage> {
onTap: () {
_updateIntervalKey.currentState?.showButtonMenu();
},
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _updateInterval,
build: () => PopupMenuButton(
builder: (_, __) => PopupMenuButton(
key: _updateIntervalKey,
itemBuilder: (_) => items,
initialValue: _updateInterval.value,
Expand All @@ -311,9 +310,9 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildAppColor() {
return ListTile(
trailing: ClipOval(
child: ValueBuilder(
child: ListenableBuilder(
listenable: _selectedColorValue,
build: () => Container(
builder: (_, __) => Container(
color: primaryColor,
height: 27,
width: 27,
Expand Down Expand Up @@ -444,8 +443,8 @@ class _SettingPageState extends State<SettingPage> {
onTap: () {
_maxRetryKey.currentState?.showButtonMenu();
},
trailing: ValueBuilder(
build: () => PopupMenuButton(
trailing: ListenableBuilder(
builder: (_, __) => PopupMenuButton(
key: _maxRetryKey,
itemBuilder: (BuildContext context) => items,
initialValue: _maxRetryCount.value,
Expand Down Expand Up @@ -490,9 +489,9 @@ class _SettingPageState extends State<SettingPage> {
onTap: () {
_themeKey.currentState?.showButtonMenu();
},
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _nightMode,
build: () => PopupMenuButton(
builder: (_, __) => PopupMenuButton(
key: _themeKey,
itemBuilder: (BuildContext context) => items,
initialValue: _nightMode.value,
Expand Down Expand Up @@ -577,9 +576,9 @@ class _SettingPageState extends State<SettingPage> {
}

Widget _buildTermFontSize() {
return ValueBuilder(
return ListenableBuilder(
listenable: _termFontSize,
build: () => ListTile(
builder: (_, __) => ListTile(
title: Text(l10n.fontSize),
trailing: Text(
_termFontSize.value.toString(),
Expand Down Expand Up @@ -641,9 +640,9 @@ class _SettingPageState extends State<SettingPage> {
onTap: () {
_localeKey.currentState?.showButtonMenu();
},
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _localeCode,
build: () => PopupMenuButton(
builder: (_, __) => PopupMenuButton(
key: _localeKey,
itemBuilder: (BuildContext context) => items,
initialValue: _localeCode.value,
Expand Down Expand Up @@ -681,9 +680,9 @@ class _SettingPageState extends State<SettingPage> {
).toList();
return ListTile(
title: Text('${l10n.light} ${l10n.theme.toLowerCase()}'),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _editorTheme,
build: () => PopupMenuButton(
builder: (_, __) => PopupMenuButton(
key: _editorThemeKey,
itemBuilder: (BuildContext context) => items,
initialValue: _editorTheme.value,
Expand Down Expand Up @@ -714,9 +713,9 @@ class _SettingPageState extends State<SettingPage> {
).toList();
return ListTile(
title: Text('${l10n.dark} ${l10n.theme.toLowerCase()}'),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _editorDarkTheme,
build: () => PopupMenuButton(
builder: (_, __) => PopupMenuButton(
key: _editorDarkThemeKey,
itemBuilder: (BuildContext context) => items,
initialValue: _editorDarkTheme.value,
Expand Down Expand Up @@ -768,9 +767,9 @@ class _SettingPageState extends State<SettingPage> {
onTap: () {
_rotateQuarterKey.currentState?.showButtonMenu();
},
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _rotateQuarter,
build: () => PopupMenuButton(
builder: (_, __) => PopupMenuButton(
key: _rotateQuarterKey,
itemBuilder: (BuildContext context) => items,
initialValue: _rotateQuarter.value,
Expand Down Expand Up @@ -816,9 +815,9 @@ class _SettingPageState extends State<SettingPage> {
return ListTile(
title: Text(l10n.keyboardType),
subtitle: Text(l10n.keyboardCompatibility, style: UIs.textGrey),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _keyboardType,
build: () => PopupMenuButton<int>(
builder: (_, __) => PopupMenuButton<int>(
key: _keyboardTypeKey,
itemBuilder: (BuildContext context) => items,
initialValue: _keyboardType.value,
Expand Down Expand Up @@ -872,9 +871,9 @@ class _SettingPageState extends State<SettingPage> {
.toList();
return ListTile(
title: Text(l10n.netViewType),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _netViewType,
build: () => PopupMenuButton<NetViewType>(
builder: (_, __) => PopupMenuButton<NetViewType>(
key: _netViewTypeKey,
itemBuilder: (BuildContext context) => items,
initialValue: _netViewType.value,
Expand Down Expand Up @@ -942,9 +941,9 @@ class _SettingPageState extends State<SettingPage> {
return ListTile(
title: Text(l10n.textScaler),
subtitle: Text(l10n.textScalerTip, style: UIs.textGrey),
trailing: ValueBuilder(
trailing: ListenableBuilder(
listenable: _textScaler,
build: () => Text(
builder: (_, __) => Text(
_textScaler.value.toString(),
style: UIs.text15,
),
Expand Down Expand Up @@ -1013,9 +1012,9 @@ class _SettingPageState extends State<SettingPage> {
}

Widget _buildEditorFontSize() {
return ValueBuilder(
return ListenableBuilder(
listenable: _editorFontSize,
build: () => ListTile(
builder: (_, __) => ListTile(
title: Text(l10n.fontSize),
trailing: Text(
_editorFontSize.value.toString(),
Expand Down
Loading

0 comments on commit 5284cee

Please sign in to comment.