mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
Fix, Improve
- fix range exception when no data fetched from server - display empty when no server stored - server edit page auto select stored/used key item
This commit is contained in:
@@ -8,6 +8,8 @@ import 'package:toolbox/core/update.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/res/icon/common.dart';
|
||||
import 'package:toolbox/data/res/url.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/convert.dart';
|
||||
import 'package:toolbox/view/page/debug.dart';
|
||||
@@ -69,7 +71,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
UserAccountsDrawerHeader(
|
||||
accountName: const Text('ToolBox'),
|
||||
accountName: const Text(BuildData.name),
|
||||
accountEmail: Text(_buildVersionStr()),
|
||||
currentAccountPicture: _buildIcon(),
|
||||
),
|
||||
@@ -82,7 +84,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
leading: const Icon(Icons.vpn_key),
|
||||
title: const Text('Private Key'),
|
||||
onTap: () =>
|
||||
AppRoute(const StoredPrivateKeysPage(), 'Setting').go(context),
|
||||
AppRoute(const StoredPrivateKeysPage(), 'private key list').go(context),
|
||||
),
|
||||
AboutListTile(
|
||||
icon: const Icon(Icons.text_snippet),
|
||||
@@ -92,11 +94,11 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
applicationIcon: _buildIcon(),
|
||||
aboutBoxChildren: const [
|
||||
UrlText(
|
||||
text: '\nMade with ❤️ by https://github.com/LollipopKit',
|
||||
text: '\nMade with ❤️ by $myGithub',
|
||||
replace: 'LollipopKit'),
|
||||
UrlText(
|
||||
text:
|
||||
'\nThanks https://github.com/RainSunMe for participating in the test.\n\nAll rights reserved.',
|
||||
'\nThanks $rainSunMeGithub for participating in the test.\n\nAll rights reserved.',
|
||||
replace: 'RainSunMe',
|
||||
),
|
||||
],
|
||||
@@ -109,7 +111,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
Widget _buildIcon() {
|
||||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 60, maxWidth: 60),
|
||||
child: Image.asset('assets/app_icon.png'),
|
||||
child: appIcon,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:toolbox/data/model/server/server.dart';
|
||||
import 'package:toolbox/data/model/server/server_status.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/data/res/linux_icons.dart';
|
||||
import 'package:toolbox/data/res/icon/linux_icons.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
class ServerDetailPage extends StatefulWidget {
|
||||
@@ -37,7 +37,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
Widget _buildMainPage(ServerInfo si) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(si.info.name ?? 'Server Detail'),
|
||||
title: Text(si.info.name),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(17),
|
||||
@@ -194,7 +194,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
SizedBox(
|
||||
width: width * (1 - used),
|
||||
child: LinearProgressIndicator(
|
||||
value: ss.memList[4] / ss.memList[0],
|
||||
// length == 2: failed to get mem list, now mem list = [100,0] which is initial value.
|
||||
value: ss.memList.length == 2 ? 0 : ss.memList[4] / ss.memList[0],
|
||||
backgroundColor: Colors.grey[100],
|
||||
color: pColor.withAlpha(77),
|
||||
),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/model/server/private_key_info.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
import 'package:toolbox/data/provider/private_key.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
@@ -32,8 +33,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
|
||||
bool usePublicKey = false;
|
||||
|
||||
int _typeOptionIndex = -1;
|
||||
final List<String> _keyInfo = ['', ''];
|
||||
int _pubKeyIndex = -1;
|
||||
late PrivateKeyInfo _keyInfo;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -109,13 +110,17 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
: const SizedBox(),
|
||||
usePublicKey
|
||||
? Consumer<PrivateKeyProvider>(builder: (_, key, __) {
|
||||
for (var item in key.infos) {
|
||||
if (item.id == widget.spi?.pubKeyId) {
|
||||
_pubKeyIndex = key.infos.indexOf(item);
|
||||
}
|
||||
}
|
||||
final tiles = key.infos
|
||||
.map(
|
||||
(e) => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(e.id, textAlign: TextAlign.start),
|
||||
trailing: _buildRadio(key.infos.indexOf(e),
|
||||
e.privateKey, e.password)),
|
||||
trailing: _buildRadio(key.infos.indexOf(e), e)),
|
||||
)
|
||||
.toList();
|
||||
tiles.add(ListTile(
|
||||
@@ -155,7 +160,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
showSnackBar(context, const Text('Please enter password.'));
|
||||
return;
|
||||
}
|
||||
if (usePublicKey && _typeOptionIndex == -1) {
|
||||
if (usePublicKey && _pubKeyIndex == -1) {
|
||||
showSnackBar(context, const Text('Please select a private key.'));
|
||||
return;
|
||||
}
|
||||
@@ -166,14 +171,18 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
portController.text = '22';
|
||||
}
|
||||
final authorization = usePublicKey
|
||||
? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]}
|
||||
? {
|
||||
"privateKey": _keyInfo.privateKey,
|
||||
"passphrase": _keyInfo.password
|
||||
}
|
||||
: passwordController.text;
|
||||
final spi = ServerPrivateInfo(
|
||||
name: nameController.text,
|
||||
ip: ipController.text,
|
||||
port: int.parse(portController.text),
|
||||
user: usernameController.text,
|
||||
authorization: authorization);
|
||||
authorization: authorization,
|
||||
pubKeyId: usePublicKey ? _keyInfo.id : null);
|
||||
|
||||
if (widget.spi == null) {
|
||||
_serverProvider.addServer(spi);
|
||||
@@ -187,15 +196,14 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
);
|
||||
}
|
||||
|
||||
Radio _buildRadio(int index, String key, String pwd) {
|
||||
Radio _buildRadio(int index, PrivateKeyInfo pki) {
|
||||
return Radio<int>(
|
||||
value: index,
|
||||
groupValue: _typeOptionIndex,
|
||||
groupValue: _pubKeyIndex,
|
||||
onChanged: (int? value) {
|
||||
setState(() {
|
||||
_typeOptionIndex = value!;
|
||||
_keyInfo[0] = key;
|
||||
_keyInfo[1] = pwd;
|
||||
_pubKeyIndex = value!;
|
||||
_keyInfo = pki;
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -214,10 +222,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final auth = widget.spi?.authorization as Map;
|
||||
passwordController.text = auth['passphrase'];
|
||||
keyController.text = auth['privateKey'];
|
||||
setState(() {
|
||||
usePublicKey = true;
|
||||
});
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
if (pro.servers.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'There is not server.\nClick the fab to add one.',
|
||||
'There is no server.\nClick the fab to add one.',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
@@ -106,7 +106,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(13),
|
||||
child: _buildRealServerCard(
|
||||
si.status, si.info.name ?? '', si.connectionState),
|
||||
si.status, si.info.name, si.connectionState),
|
||||
),
|
||||
onTap: () =>
|
||||
AppRoute(ServerDetailPage(si.client.id!), 'server detail page')
|
||||
|
||||
Reference in New Issue
Block a user