diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 6146ffff..875e3676 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -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 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 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 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 Widget _buildIcon() { return ConstrainedBox( constraints: const BoxConstraints(maxHeight: 60, maxWidth: 60), - child: Image.asset('assets/app_icon.png'), + child: appIcon, ); } diff --git a/lib/view/page/server/detail.dart b/lib/view/page/server/detail.dart index 42e39524..8c8d2da7 100644 --- a/lib/view/page/server/detail.dart +++ b/lib/view/page/server/detail.dart @@ -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 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 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), ), diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index 46b27b0c..4dbe631f 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -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 with AfterLayoutMixin { bool usePublicKey = false; - int _typeOptionIndex = -1; - final List _keyInfo = ['', '']; + int _pubKeyIndex = -1; + late PrivateKeyInfo _keyInfo; @override void initState() { @@ -109,13 +110,17 @@ class _ServerEditPageState extends State with AfterLayoutMixin { : const SizedBox(), usePublicKey ? Consumer(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 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 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 with AfterLayoutMixin { ); } - Radio _buildRadio(int index, String key, String pwd) { + Radio _buildRadio(int index, PrivateKeyInfo pki) { return Radio( 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 with AfterLayoutMixin { final auth = widget.spi?.authorization as Map; passwordController.text = auth['passphrase']; keyController.text = auth['privateKey']; - setState(() { - usePublicKey = true; - }); + usePublicKey = true; } + setState(() {}); } } } diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 76e5a893..bd685efa 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -52,7 +52,7 @@ class _ServerPageState extends State 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 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')