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/core/utils.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
import 'package:toolbox/data/res/build_data.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/locator.dart';
|
||||||
import 'package:toolbox/view/page/convert.dart';
|
import 'package:toolbox/view/page/convert.dart';
|
||||||
import 'package:toolbox/view/page/debug.dart';
|
import 'package:toolbox/view/page/debug.dart';
|
||||||
@@ -69,7 +71,7 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
children: [
|
children: [
|
||||||
UserAccountsDrawerHeader(
|
UserAccountsDrawerHeader(
|
||||||
accountName: const Text('ToolBox'),
|
accountName: const Text(BuildData.name),
|
||||||
accountEmail: Text(_buildVersionStr()),
|
accountEmail: Text(_buildVersionStr()),
|
||||||
currentAccountPicture: _buildIcon(),
|
currentAccountPicture: _buildIcon(),
|
||||||
),
|
),
|
||||||
@@ -82,7 +84,7 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
leading: const Icon(Icons.vpn_key),
|
leading: const Icon(Icons.vpn_key),
|
||||||
title: const Text('Private Key'),
|
title: const Text('Private Key'),
|
||||||
onTap: () =>
|
onTap: () =>
|
||||||
AppRoute(const StoredPrivateKeysPage(), 'Setting').go(context),
|
AppRoute(const StoredPrivateKeysPage(), 'private key list').go(context),
|
||||||
),
|
),
|
||||||
AboutListTile(
|
AboutListTile(
|
||||||
icon: const Icon(Icons.text_snippet),
|
icon: const Icon(Icons.text_snippet),
|
||||||
@@ -92,11 +94,11 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
applicationIcon: _buildIcon(),
|
applicationIcon: _buildIcon(),
|
||||||
aboutBoxChildren: const [
|
aboutBoxChildren: const [
|
||||||
UrlText(
|
UrlText(
|
||||||
text: '\nMade with ❤️ by https://github.com/LollipopKit',
|
text: '\nMade with ❤️ by $myGithub',
|
||||||
replace: 'LollipopKit'),
|
replace: 'LollipopKit'),
|
||||||
UrlText(
|
UrlText(
|
||||||
text:
|
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',
|
replace: 'RainSunMe',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -109,7 +111,7 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
Widget _buildIcon() {
|
Widget _buildIcon() {
|
||||||
return ConstrainedBox(
|
return ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxHeight: 60, maxWidth: 60),
|
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/model/server/server_status.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
import 'package:toolbox/data/res/color.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';
|
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||||
|
|
||||||
class ServerDetailPage extends StatefulWidget {
|
class ServerDetailPage extends StatefulWidget {
|
||||||
@@ -37,7 +37,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
Widget _buildMainPage(ServerInfo si) {
|
Widget _buildMainPage(ServerInfo si) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(si.info.name ?? 'Server Detail'),
|
title: Text(si.info.name),
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
padding: const EdgeInsets.all(17),
|
padding: const EdgeInsets.all(17),
|
||||||
@@ -194,7 +194,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
width: width * (1 - used),
|
width: width * (1 - used),
|
||||||
child: LinearProgressIndicator(
|
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],
|
backgroundColor: Colors.grey[100],
|
||||||
color: pColor.withAlpha(77),
|
color: pColor.withAlpha(77),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:toolbox/core/route.dart';
|
import 'package:toolbox/core/route.dart';
|
||||||
import 'package:toolbox/core/utils.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/model/server/server_private_info.dart';
|
||||||
import 'package:toolbox/data/provider/private_key.dart';
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
@@ -32,8 +33,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
|
|
||||||
bool usePublicKey = false;
|
bool usePublicKey = false;
|
||||||
|
|
||||||
int _typeOptionIndex = -1;
|
int _pubKeyIndex = -1;
|
||||||
final List<String> _keyInfo = ['', ''];
|
late PrivateKeyInfo _keyInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -109,13 +110,17 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
: const SizedBox(),
|
: const SizedBox(),
|
||||||
usePublicKey
|
usePublicKey
|
||||||
? Consumer<PrivateKeyProvider>(builder: (_, key, __) {
|
? 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
|
final tiles = key.infos
|
||||||
.map(
|
.map(
|
||||||
(e) => ListTile(
|
(e) => ListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
title: Text(e.id, textAlign: TextAlign.start),
|
title: Text(e.id, textAlign: TextAlign.start),
|
||||||
trailing: _buildRadio(key.infos.indexOf(e),
|
trailing: _buildRadio(key.infos.indexOf(e), e)),
|
||||||
e.privateKey, e.password)),
|
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
tiles.add(ListTile(
|
tiles.add(ListTile(
|
||||||
@@ -155,7 +160,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
showSnackBar(context, const Text('Please enter password.'));
|
showSnackBar(context, const Text('Please enter password.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (usePublicKey && _typeOptionIndex == -1) {
|
if (usePublicKey && _pubKeyIndex == -1) {
|
||||||
showSnackBar(context, const Text('Please select a private key.'));
|
showSnackBar(context, const Text('Please select a private key.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -166,14 +171,18 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
portController.text = '22';
|
portController.text = '22';
|
||||||
}
|
}
|
||||||
final authorization = usePublicKey
|
final authorization = usePublicKey
|
||||||
? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]}
|
? {
|
||||||
|
"privateKey": _keyInfo.privateKey,
|
||||||
|
"passphrase": _keyInfo.password
|
||||||
|
}
|
||||||
: passwordController.text;
|
: passwordController.text;
|
||||||
final spi = ServerPrivateInfo(
|
final spi = ServerPrivateInfo(
|
||||||
name: nameController.text,
|
name: nameController.text,
|
||||||
ip: ipController.text,
|
ip: ipController.text,
|
||||||
port: int.parse(portController.text),
|
port: int.parse(portController.text),
|
||||||
user: usernameController.text,
|
user: usernameController.text,
|
||||||
authorization: authorization);
|
authorization: authorization,
|
||||||
|
pubKeyId: usePublicKey ? _keyInfo.id : null);
|
||||||
|
|
||||||
if (widget.spi == null) {
|
if (widget.spi == null) {
|
||||||
_serverProvider.addServer(spi);
|
_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>(
|
return Radio<int>(
|
||||||
value: index,
|
value: index,
|
||||||
groupValue: _typeOptionIndex,
|
groupValue: _pubKeyIndex,
|
||||||
onChanged: (int? value) {
|
onChanged: (int? value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_typeOptionIndex = value!;
|
_pubKeyIndex = value!;
|
||||||
_keyInfo[0] = key;
|
_keyInfo = pki;
|
||||||
_keyInfo[1] = pwd;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -214,10 +222,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
final auth = widget.spi?.authorization as Map;
|
final auth = widget.spi?.authorization as Map;
|
||||||
passwordController.text = auth['passphrase'];
|
passwordController.text = auth['passphrase'];
|
||||||
keyController.text = auth['privateKey'];
|
keyController.text = auth['privateKey'];
|
||||||
setState(() {
|
usePublicKey = true;
|
||||||
usePublicKey = true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
if (pro.servers.isEmpty) {
|
if (pro.servers.isEmpty) {
|
||||||
return const Center(
|
return const Center(
|
||||||
child: Text(
|
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,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -106,7 +106,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(13),
|
padding: const EdgeInsets.all(13),
|
||||||
child: _buildRealServerCard(
|
child: _buildRealServerCard(
|
||||||
si.status, si.info.name ?? '', si.connectionState),
|
si.status, si.info.name, si.connectionState),
|
||||||
),
|
),
|
||||||
onTap: () =>
|
onTap: () =>
|
||||||
AppRoute(ServerDetailPage(si.client.id!), 'server detail page')
|
AppRoute(ServerDetailPage(si.client.id!), 'server detail page')
|
||||||
|
|||||||
Reference in New Issue
Block a user