Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Jan 28, 2024
1 parent b9640c3 commit d1441fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 50 deletions.
11 changes: 3 additions & 8 deletions lib/data/store/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:toolbox/core/persistant_store.dart';
import 'package:toolbox/core/utils/platform/base.dart';
import 'package:toolbox/data/model/app/menu/server_func.dart';
import 'package:toolbox/data/model/ssh/virtual_key.dart';

import '../model/app/net_view.dart';
import '../res/default.dart';
Expand Down Expand Up @@ -141,9 +140,7 @@ class SettingStore extends PersistentStore {

late final sshVirtKeys = listProperty(
'sshVirtKeys',
Defaults.sshVirtKeys,
encoder: (val) => val.index,
decoder: (val) => VirtKey.values[val],
Defaults.sshVirtKeys.map((e) => e.index).toList(),
);

late final netViewType = property(
Expand Down Expand Up @@ -212,7 +209,7 @@ class SettingStore extends PersistentStore {
/// Whether collapse UI items by default
late final collapseUIDefault = property('collapseUIDefault', true);

late final serverFuncBtns = listProperty<ServerFuncBtn>(
late final serverFuncBtns = listProperty(
'serverBtns',
[
ServerFuncBtn.terminal,
Expand All @@ -221,9 +218,7 @@ class SettingStore extends PersistentStore {
ServerFuncBtn.process,
ServerFuncBtn.pkg,
ServerFuncBtn.snippet,
],
encoder: (val) => val.index,
decoder: (val) => ServerFuncBtn.values[val],
].map((e) => e.index).toList(),
);

// Never show these settings for users
Expand Down
10 changes: 5 additions & 5 deletions lib/view/page/setting/seq/srv_func_seq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {

Widget _buildBody() {
final keys_ = Stores.setting.serverFuncBtns.fetch();
final keys = <ServerFuncBtn>[];
final keys = <int>[];
for (final key in keys_) {
keys.add(key);
}
final disabled =
ServerFuncBtn.values.where((e) => !keys.contains(e)).toList();
ServerFuncBtn.values.map((e) => e.index).where((e) => !keys.contains(e)).toList();
final allKeys = [...keys, ...disabled];
return ReorderableListView.builder(
padding: const EdgeInsets.all(7),
Expand All @@ -43,7 +43,7 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
return CardX(
key: ValueKey(idx),
child: ListTile(
title: Text(key.toStr),
title: Text(ServerFuncBtn.values[key].toStr),
leading: _buildCheckBox(keys, key, idx, idx < keys.length),
trailing: isDesktop ? null : const Icon(Icons.drag_handle),
),
Expand All @@ -62,8 +62,8 @@ class _ServerDetailOrderPageState extends State<ServerFuncBtnsOrderPage> {
}

Widget _buildCheckBox(
List<ServerFuncBtn> keys,
ServerFuncBtn key,
List<int> keys,
int key,
int idx,
bool value,
) {
Expand Down
11 changes: 6 additions & 5 deletions lib/view/page/setting/seq/virt_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {

Widget _buildBody() {
final keys_ = Stores.setting.sshVirtKeys.fetch();
final keys = <VirtKey>[];
final keys = <int>[];
for (final key in keys_) {
keys.add(key);
}
final disabled = VirtKey.values.where((e) => !keys.contains(e)).toList();
final disabled = VirtKey.values.map((e) => e.index).where((e) => !keys.contains(e)).toList();
final allKeys = [...keys, ...disabled];
return ReorderableListView.builder(
padding: const EdgeInsets.all(7),
itemBuilder: (_, idx) {
final key = allKeys[idx];
final help = key.help;
final item = VirtKey.values[key];
final help = item.help;
return CardX(
key: ValueKey(idx),
child: ListTile(
title: _buildTitle(key),
title: _buildTitle(item),
subtitle: help == null ? null : Text(help, style: UIs.textGrey),
leading: _buildCheckBox(keys, key, idx, idx < keys.length),
trailing: isDesktop ? null : const Icon(Icons.drag_handle),
Expand Down Expand Up @@ -75,7 +76,7 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
);
}

Widget _buildCheckBox(List<VirtKey> keys, VirtKey key, int idx, bool value) {
Widget _buildCheckBox(List<int> keys, int key, int idx, bool value) {
return Checkbox(
value: value,
onChanged: (val) {
Expand Down
53 changes: 21 additions & 32 deletions lib/view/widget/server_func_btns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/context/snackbar.dart';
import 'package:toolbox/core/extension/ssh_client.dart';
import 'package:toolbox/core/extension/uint8list.dart';
import 'package:toolbox/core/extension/widget.dart';
import 'package:toolbox/core/utils/platform/base.dart';
import 'package:toolbox/core/utils/platform/path.dart';
import 'package:toolbox/data/model/app/menu/server_func.dart';
Expand All @@ -17,6 +18,7 @@ import 'package:toolbox/data/model/server/snippet.dart';
import 'package:toolbox/data/res/path.dart';
import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/data/res/ui.dart';

import '../../core/route.dart';
import '../../core/utils/server.dart';
Expand Down Expand Up @@ -67,43 +69,30 @@ class ServerFuncBtns extends StatelessWidget {

@override
Widget build(BuildContext context) {
// return Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: ServerTabMenuType.values
// .map(
// (e) => Stores.setting.serverFuncBtnsDisplayName.fetch()
// ? Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// IconButton(
// onPressed: () => _onTapMoreBtns(e, spi, context),
// padding: EdgeInsets.zero,
// tooltip: e.name,
// icon: Icon(e.icon, size: iconSize ?? 15),
// ),
// Text(e.toStr, style: UIs.textSize9Grey)
// ],
// )
// : IconButton(
// onPressed: () => _onTapMoreBtns(e, spi, context),
// padding: EdgeInsets.zero,
// tooltip: e.name,
// icon: Icon(e.icon, size: iconSize ?? 15),
// ),
// )
// .toList(),
// );
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: Stores.setting.serverFuncBtns
.fetch()
.map((e) => ServerFuncBtn.values[e])
.map(
(e) => IconButton(
onPressed: () => _onTapMoreBtns(e, spi, context),
padding: EdgeInsets.zero,
tooltip: e.toStr,
icon: Icon(e.icon, size: iconSize ?? 15),
),
(e) => Stores.setting.moveOutServerTabFuncBtns.fetch()
? IconButton(
onPressed: () => _onTapMoreBtns(e, spi, context),
padding: EdgeInsets.zero,
tooltip: e.toStr,
icon: Icon(e.icon, size: iconSize ?? 15),
)
: Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () => _onTapMoreBtns(e, spi, context),
padding: EdgeInsets.zero,
icon: Icon(e.icon, size: iconSize ?? 15),
),
Text(e.toStr, style: UIs.text11Grey)
],
).padding(const EdgeInsets.only(bottom: 13)),
)
.toList(),
);
Expand Down

0 comments on commit d1441fb

Please sign in to comment.