Improve UI. Rounded Card.

This commit is contained in:
Junyuan Feng
2022-02-04 18:52:35 +08:00
parent 026d203608
commit 1bd43829bb
16 changed files with 271 additions and 100 deletions

View File

@@ -354,7 +354,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 85; CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -362,7 +362,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.85; MARKETING_VERSION = 1.0.88;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -484,7 +484,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 85; CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -492,7 +492,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.85; MARKETING_VERSION = 1.0.88;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -508,7 +508,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 85; CURRENT_PROJECT_VERSION = 88;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -516,7 +516,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.85; MARKETING_VERSION = 1.0.88;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View File

@@ -9,6 +9,5 @@ class ServerInfo {
SSHClient? client; SSHClient? client;
ServerConnectionState connectionState; ServerConnectionState connectionState;
ServerInfo( ServerInfo(this.info, this.status, this.client, this.connectionState);
this.info, this.status, this.client, this.connectionState);
} }

View File

@@ -324,8 +324,11 @@ class ServerProvider extends BusyProvider {
notifyListeners(); notifyListeners();
} }
Future<String?> runSnippet(int idx, Snippet snippet) async { Future<String?> runSnippet(ServerPrivateInfo spi, Snippet snippet) async {
final result = await _servers[idx].client!.run(snippet.script); final result = await _servers
.firstWhere((element) => element.info == spi)
.client!
.run(snippet.script);
return utf8.decode(result); return utf8.decode(result);
} }
} }

View File

@@ -2,8 +2,8 @@
class BuildData { class BuildData {
static const String name = "ServerBox"; static const String name = "ServerBox";
static const int build = 87; static const int build = 88;
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n"; static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (7 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const String buildAt = "2022-02-02 13:20:22.346643"; static const String buildAt = "2022-02-04 18:44:51.481488";
static const int modifications = 8; static const int modifications = 16;
} }

View File

@@ -0,0 +1,3 @@
import 'package:flutter/material.dart';
const roundRectCardPadding = EdgeInsets.symmetric(horizontal: 17);

View File

@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:toolbox/core/utils.dart'; import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/view/widget/input_field.dart'; import 'package:toolbox/view/widget/input_field.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
class ConvertPage extends StatefulWidget { class ConvertPage extends StatefulWidget {
const ConvertPage({Key? key}) : super(key: key); const ConvertPage({Key? key}) : super(key: key);
@@ -95,8 +96,8 @@ class _ConvertPageState extends State<ConvertPage>
} }
Widget _buildTypeOption() { Widget _buildTypeOption() {
return Card( return RoundRectCard(
child: ExpansionTile( ExpansionTile(
tilePadding: const EdgeInsets.only(left: 7, right: 27), tilePadding: const EdgeInsets.only(left: 7, right: 27),
childrenPadding: EdgeInsets.zero, childrenPadding: EdgeInsets.zero,
title: Row( title: Row(

View File

@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:toolbox/core/utils.dart'; import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/view/widget/input_field.dart'; import 'package:toolbox/view/widget/input_field.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
class PingPage extends StatefulWidget { class PingPage extends StatefulWidget {
const PingPage({Key? key}) : super(key: key); const PingPage({Key? key}) : super(key: key);
@@ -46,10 +47,9 @@ class _PingPageState extends State<PingPage>
child: Column(children: [ child: Column(children: [
const SizedBox(height: 13), const SizedBox(height: 13),
buildInput(context, _textEditingController, buildInput(context, _textEditingController,
maxLines: 1, hint: 'Type here.'), maxLines: 1),
_buildControl(), _buildControl(),
buildInput(context, _textEditingControllerResult, buildInput(context, _textEditingControllerResult),
hint: 'Result here.'),
])), ])),
onTap: () => FocusScope.of(context).requestFocus(FocusNode()), onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
), ),
@@ -70,8 +70,8 @@ class _PingPageState extends State<PingPage>
Widget _buildControl() { Widget _buildControl() {
return SizedBox( return SizedBox(
height: 57, height: 57,
child: Card( child: RoundRectCard(
child: InkWell( InkWell(
onTap: () => FocusScope.of(context).unfocus(), onTap: () => FocusScope.of(context).unfocus(),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,

View File

@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
import 'package:toolbox/core/route.dart'; import 'package:toolbox/core/route.dart';
import 'package:toolbox/data/provider/private_key.dart'; import 'package:toolbox/data/provider/private_key.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/view/page/private_key/edit.dart'; import 'package:toolbox/view/page/private_key/edit.dart';
import 'package:toolbox/view/widget/round_rect_card.dart'; import 'package:toolbox/view/widget/round_rect_card.dart';
@@ -29,7 +30,7 @@ class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
itemCount: key.infos.length, itemCount: key.infos.length,
itemExtent: 57, itemExtent: 57,
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return RoundRectCard(Row( return RoundRectCard(Padding(padding: roundRectCardPadding, child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -47,7 +48,7 @@ class _PrivateKeyListState extends State<StoredPrivateKeysPage> {
style: _textStyle, style: _textStyle,
)) ))
], ],
)); ),));
}) })
: const Center(child: Text('No saved private keys.')); : const Center(child: Text('No saved private keys.'));
}, },

View File

@@ -6,6 +6,7 @@ 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/icon/linux_icons.dart'; import 'package:toolbox/data/res/icon/linux_icons.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/view/widget/round_rect_card.dart'; import 'package:toolbox/view/widget/round_rect_card.dart';
const style11 = TextStyle(fontSize: 11); const style11 = TextStyle(fontSize: 11);
@@ -44,7 +45,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
title: Text(si.info.name), title: Text(si.info.name),
), ),
body: ListView( body: ListView(
padding: const EdgeInsets.all(17), padding: const EdgeInsets.all(13),
children: [ children: [
_buildLinuxIcon(si.status.sysVer), _buildLinuxIcon(si.status.sysVer),
SizedBox(height: _media.size.height * 0.03), SizedBox(height: _media.size.height * 0.03),
@@ -68,7 +69,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildCPUView(ServerStatus ss) { Widget _buildCPUView(ServerStatus ss) {
return RoundRectCard( return RoundRectCard(
SizedBox( Padding(padding: roundRectCardPadding, child: SizedBox(
height: 12 * ss.cpu2Status.coresCount + 67, height: 12 * ss.cpu2Status.coresCount + 67,
child: Column(children: [ child: Column(children: [
SizedBox( SizedBox(
@@ -103,7 +104,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
), ),
_buildCPUProgress(ss) _buildCPUProgress(ss)
]), ]),
), ),),
); );
} }
@@ -158,7 +159,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildUpTimeAndSys(ServerStatus ss) { Widget _buildUpTimeAndSys(ServerStatus ss) {
return RoundRectCard(Padding( return RoundRectCard(Padding(
padding: const EdgeInsets.symmetric(vertical: 13), padding: const EdgeInsets.symmetric(vertical: 13, horizontal: 17),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -191,7 +192,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
final pColor = primaryColor; final pColor = primaryColor;
final used = ss.memory.used / ss.memory.total; final used = ss.memory.used / ss.memory.total;
final width = _media.size.width - 17 * 2 - 17 * 2; final width = _media.size.width - 17 * 2 - 17 * 2;
return RoundRectCard(SizedBox( return RoundRectCard(Padding(padding: roundRectCardPadding, child: SizedBox(
height: 47, height: 47,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@@ -233,7 +234,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
) )
], ],
), ),
)); ),));
} }
Widget _buildMemExplain(String value, Color color) { Widget _buildMemExplain(String value, Color color) {
@@ -265,7 +266,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
return RoundRectCard(SizedBox( return RoundRectCard(SizedBox(
height: 27 * clone.length + 25, height: 27 * clone.length + 25,
child: ListView.builder( child: ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 13), padding: const EdgeInsets.symmetric(vertical: 13, horizontal: 17),
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
itemCount: clone.length, itemCount: clone.length,
itemBuilder: (_, idx) { itemBuilder: (_, idx) {
@@ -302,7 +303,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
]; ];
children.addAll(ns.devices.map((e) => _buildNetSpeedItem(ns, e))); children.addAll(ns.devices.map((e) => _buildNetSpeedItem(ns, e)));
return RoundRectCard(Padding( return RoundRectCard(Padding(
padding: const EdgeInsets.symmetric(vertical: 7), padding: const EdgeInsets.symmetric(vertical: 7, horizontal: 17),
child: Column( child: Column(
children: children, children: children,
), ),

View File

@@ -1,5 +1,6 @@
import 'package:after_layout/after_layout.dart'; import 'package:after_layout/after_layout.dart';
import 'package:circle_chart/circle_chart.dart'; import 'package:circle_chart/circle_chart.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:marquee/marquee.dart'; import 'package:marquee/marquee.dart';
@@ -8,6 +9,7 @@ import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:toolbox/core/route.dart'; import 'package:toolbox/core/route.dart';
import 'package:toolbox/data/model/server/server.dart'; import 'package:toolbox/data/model/server/server.dart';
import 'package:toolbox/data/model/server/server_connection_state.dart'; import 'package:toolbox/data/model/server/server_connection_state.dart';
import 'package:toolbox/data/model/server/server_private_info.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';
@@ -15,6 +17,8 @@ import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart'; import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/server/detail.dart'; import 'package:toolbox/view/page/server/detail.dart';
import 'package:toolbox/view/page/server/edit.dart'; import 'package:toolbox/view/page/server/edit.dart';
import 'package:toolbox/view/page/snippet/list.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
class ServerPage extends StatefulWidget { class ServerPage extends StatefulWidget {
final TabController tabController; final TabController tabController;
@@ -47,8 +51,8 @@ class _ServerPageState extends State<ServerPage>
_theme = Theme.of(context); _theme = Theme.of(context);
_primaryColor = primaryColor; _primaryColor = primaryColor;
if (widget.tabController.index == 0) { if (widget.tabController.index == 0) {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
} }
} }
@override @override
@@ -65,15 +69,19 @@ class _ServerPageState extends State<ServerPage>
), ),
); );
} }
return SingleChildScrollView( return ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 7), padding: const EdgeInsets.all(7),
child: Column( itemBuilder: (ctx, idx) {
children: [ if (idx == pro.servers.length) {
const SizedBox(height: 13), return SizedBox(height: _media.padding.bottom);
...pro.servers.map((e) => _buildEachServerCard(e)), }
SizedBox(height: _media.padding.bottom), return _buildEachServerCard(pro.servers[idx]);
], },
)); itemCount: pro.servers.length + 1,
separatorBuilder: (_, __) => const SizedBox(
height: 3,
),
);
}); });
return Scaffold( return Scaffold(
body: autoUpdate body: autoUpdate
@@ -98,8 +106,8 @@ class _ServerPageState extends State<ServerPage>
} }
Widget _buildEachServerCard(ServerInfo si) { Widget _buildEachServerCard(ServerInfo si) {
return Card( return RoundRectCard(
child: InkWell( InkWell(
onLongPress: () => AppRoute( onLongPress: () => AppRoute(
ServerEditPage( ServerEditPage(
spi: si.info, spi: si.info,
@@ -109,7 +117,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, si.info)),
onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'), onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'),
'server detail page') 'server detail page')
.go(context), .go(context),
@@ -117,8 +125,8 @@ class _ServerPageState extends State<ServerPage>
); );
} }
Widget _buildRealServerCard( Widget _buildRealServerCard(ServerStatus ss, String serverName,
ServerStatus ss, String serverName, ServerConnectionState cs) { ServerConnectionState cs, ServerPrivateInfo spi) {
final rootDisk = final rootDisk =
ss.disk.firstWhere((element) => element.mountLocation == '/'); ss.disk.firstWhere((element) => element.mountLocation == '/');
@@ -132,29 +140,112 @@ class _ServerPageState extends State<ServerPage>
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Padding(
mainAxisAlignment: MainAxisAlignment.spaceBetween, padding: const EdgeInsets.symmetric(horizontal: 11),
children: [ child: Row(
Text( mainAxisAlignment: MainAxisAlignment.spaceBetween,
serverName, children: [
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12), Row(
textScaleFactor: 1.0, children: [
), Text(
hasError serverName,
? ConstrainedBox( style: const TextStyle(
constraints: BoxConstraints( fontWeight: FontWeight.bold, fontSize: 12),
maxWidth: _media.size.width * 0.57, maxHeight: 15), textScaleFactor: 1.0,
child: Marquee( ),
accelerationDuration: const Duration(seconds: 3), const Icon(
accelerationCurve: Curves.linear, Icons.keyboard_arrow_right,
decelerationDuration: const Duration(seconds: 3), size: 17,
decelerationCurve: Curves.linear, color: Colors.grey,
text: topRightStr,
textScaleFactor: 1.0,
style: style),
) )
: Text(topRightStr, style: style, textScaleFactor: 1.0), ],
], ),
Row(
children: [
hasError
? ConstrainedBox(
constraints: BoxConstraints(
maxWidth: _media.size.width * 0.57,
maxHeight: 15),
child: Marquee(
accelerationDuration: const Duration(seconds: 3),
accelerationCurve: Curves.linear,
decelerationDuration: const Duration(seconds: 3),
decelerationCurve: Curves.linear,
text: topRightStr,
textScaleFactor: 1.0,
style: style),
)
: Text(topRightStr, style: style, textScaleFactor: 1.0),
const SizedBox(
width: 13,
),
DropdownButtonHideUnderline(
child: DropdownButton2(
customButton: const Icon(
Icons.list_alt,
size: 19,
),
customItemsIndexes: const [3],
customItemsHeight: 8,
items: [
...MenuItems.firstItems.map(
(item) => DropdownMenuItem<MenuItem>(
value: item,
child: MenuItems.buildItem(item),
),
),
const DropdownMenuItem<Divider>(
enabled: false, child: Divider()),
...MenuItems.secondItems.map(
(item) => DropdownMenuItem<MenuItem>(
value: item,
child: MenuItems.buildItem(item),
),
),
],
onChanged: (value) {
final item = value as MenuItem;
switch (item) {
case MenuItems.sftp:
//Do something
break;
case MenuItems.apt:
//Do something
break;
case MenuItems.snippet:
AppRoute(
SnippetListPage(
spi: spi,
),
'snippet list')
.go(context);
break;
case MenuItems.edit:
AppRoute(
ServerEditPage(
spi: spi,
),
'Edit server info page')
.go(context);
break;
}
},
itemHeight: 37,
itemPadding: const EdgeInsets.only(left: 17, right: 17),
dropdownWidth: 160,
dropdownPadding: const EdgeInsets.symmetric(vertical: 7),
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(7),
),
dropdownElevation: 8,
offset: const Offset(0, 8),
),
),
],
)
],
),
), ),
const SizedBox( const SizedBox(
height: 17, height: 17,
@@ -286,3 +377,54 @@ class _ServerPageState extends State<ServerPage>
_serverProvider.startAutoRefresh(); _serverProvider.startAutoRefresh();
} }
} }
class MenuItem {
final String text;
final IconData icon;
const MenuItem({
required this.text,
required this.icon,
});
}
class MenuItems {
static const List<MenuItem> firstItems = [sftp, snippet, apt];
static const List<MenuItem> secondItems = [edit];
static const sftp = MenuItem(text: 'SFTP', icon: Icons.home);
static const snippet = MenuItem(text: 'Snippet', icon: Icons.label);
static const apt = MenuItem(text: 'Apt', icon: Icons.system_security_update);
static const edit = MenuItem(text: 'Edit', icon: Icons.settings);
static Widget buildItem(MenuItem item) {
return Row(
children: [
Icon(item.icon),
const SizedBox(
width: 10,
),
Text(
item.text,
),
],
);
}
static onChanged(BuildContext context, MenuItem item) {
switch (item) {
case MenuItems.sftp:
//Do something
break;
case MenuItems.apt:
//Do something
break;
case MenuItems.snippet:
//Do something
break;
case MenuItems.edit:
//Do something
break;
}
}
}

View File

@@ -6,6 +6,7 @@ import 'package:toolbox/data/provider/app.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/color.dart'; import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/data/res/tab.dart'; import 'package:toolbox/data/res/tab.dart';
import 'package:toolbox/data/store/setting.dart'; import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart'; import 'package:toolbox/locator.dart';
@@ -77,7 +78,7 @@ class _SettingPageState extends State<SettingPage> {
display = 'Current: v1.0.${BuildData.build}'; display = 'Current: v1.0.${BuildData.build}';
} }
return ListTile( return ListTile(
contentPadding: EdgeInsets.zero, contentPadding: roundRectCardPadding,
trailing: const Icon(Icons.keyboard_arrow_right), trailing: const Icon(Icons.keyboard_arrow_right),
title: Text( title: Text(
display, display,
@@ -90,8 +91,8 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildUpdateInterval() { Widget _buildUpdateInterval() {
return ExpansionTile( return ExpansionTile(
tilePadding: EdgeInsets.zero, tilePadding: roundRectCardPadding,
childrenPadding: EdgeInsets.zero, childrenPadding: roundRectCardPadding,
textColor: priColor, textColor: priColor,
title: const Text( title: const Text(
'Server status update interval', 'Server status update interval',
@@ -142,8 +143,8 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildAppColorPreview() { Widget _buildAppColorPreview() {
return ExpansionTile( return ExpansionTile(
textColor: priColor, textColor: priColor,
tilePadding: EdgeInsets.zero, tilePadding: roundRectCardPadding,
childrenPadding: EdgeInsets.zero, childrenPadding: roundRectCardPadding,
children: [ children: [
_buildAppColorPicker(priColor), _buildAppColorPicker(priColor),
_buildColorPickerConfirmBtn() _buildColorPickerConfirmBtn()
@@ -183,8 +184,8 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildLaunchPage() { Widget _buildLaunchPage() {
return ExpansionTile( return ExpansionTile(
textColor: priColor, textColor: priColor,
tilePadding: EdgeInsets.zero, tilePadding: roundRectCardPadding,
childrenPadding: EdgeInsets.zero, childrenPadding: roundRectCardPadding,
title: const Text( title: const Text(
'Launch page', 'Launch page',
style: textStyle, style: textStyle,

View File

@@ -2,23 +2,26 @@ 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/server_private_info.dart';
import 'package:toolbox/data/model/server/snippet.dart'; import 'package:toolbox/data/model/server/snippet.dart';
import 'package:toolbox/data/provider/server.dart'; import 'package:toolbox/data/provider/server.dart';
import 'package:toolbox/data/provider/snippet.dart'; import 'package:toolbox/data/provider/snippet.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/padding.dart';
import 'package:toolbox/locator.dart'; import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/snippet/edit.dart'; import 'package:toolbox/view/page/snippet/edit.dart';
import 'package:toolbox/view/widget/round_rect_card.dart'; import 'package:toolbox/view/widget/round_rect_card.dart';
class SnippetListPage extends StatefulWidget { class SnippetListPage extends StatefulWidget {
const SnippetListPage({Key? key}) : super(key: key); const SnippetListPage({Key? key, this.spi}) : super(key: key);
final ServerPrivateInfo? spi;
@override @override
_SnippetListPageState createState() => _SnippetListPageState(); _SnippetListPageState createState() => _SnippetListPageState();
} }
class _SnippetListPageState extends State<SnippetListPage> { class _SnippetListPageState extends State<SnippetListPage> {
int _selectedIndex = 0; late ServerPrivateInfo _selectedIndex;
final _textStyle = TextStyle(color: primaryColor); final _textStyle = TextStyle(color: primaryColor);
@override @override
@@ -45,7 +48,7 @@ class _SnippetListPageState extends State<SnippetListPage> {
itemCount: key.snippets.length, itemCount: key.snippets.length,
itemExtent: 57, itemExtent: 57,
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return RoundRectCard(Row( return RoundRectCard(Padding(padding: roundRectCardPadding, child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -64,14 +67,21 @@ class _SnippetListPageState extends State<SnippetListPage> {
style: _textStyle, style: _textStyle,
)), )),
TextButton( TextButton(
onPressed: () => _showRunDialog(key.snippets[idx]), onPressed: () {
final snippet = key.snippets[idx];
if (widget.spi == null) {
_showRunDialog(snippet);
return;
}
run(context, snippet);
},
child: Text( child: Text(
'Run', 'Run',
style: _textStyle, style: _textStyle,
)) ))
]) ])
], ],
)); ),));
}) })
: const Center(child: Text('No saved snippets.')); : const Center(child: Text('No saved snippets.'));
}, },
@@ -84,6 +94,7 @@ class _SnippetListPageState extends State<SnippetListPage> {
if (provider.servers.isEmpty) { if (provider.servers.isEmpty) {
return const Text('No server available'); return const Text('No server available');
} }
_selectedIndex = provider.servers.first.info;
return SizedBox( return SizedBox(
height: 111, height: 111,
child: Stack(children: [ child: Stack(children: [
@@ -104,7 +115,8 @@ class _SnippetListPageState extends State<SnippetListPage> {
itemExtent: 37, itemExtent: 37,
diameterRatio: 1.2, diameterRatio: 1.2,
controller: FixedExtentScrollController(initialItem: 0), controller: FixedExtentScrollController(initialItem: 0),
onSelectedItemChanged: (idx) => _selectedIndex = idx, onSelectedItemChanged: (idx) =>
_selectedIndex = provider.servers[idx].info,
physics: const FixedExtentScrollPhysics(), physics: const FixedExtentScrollPhysics(),
childDelegate: ListWheelChildBuilderDelegate( childDelegate: ListWheelChildBuilderDelegate(
builder: (context, index) => Center( builder: (context, index) => Center(
@@ -118,22 +130,24 @@ class _SnippetListPageState extends State<SnippetListPage> {
])); ]));
}), [ }), [
TextButton( TextButton(
onPressed: () async { onPressed: () async => run(context, snippet),
final result = await locator<ServerProvider>()
.runSnippet(_selectedIndex, snippet);
if (result != null) {
showRoundDialog(context, 'Result',
Text(result, style: const TextStyle(fontSize: 13)), [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Close'))
]);
}
},
child: const Text('Run')), child: const Text('Run')),
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
child: const Text('Cancel')), child: const Text('Cancel')),
]); ]);
} }
Future<void> run(BuildContext context, Snippet snippet) async {
final result = await locator<ServerProvider>()
.runSnippet(widget.spi ?? _selectedIndex, snippet);
if (result != null) {
showRoundDialog(context, 'Result',
Text(result, style: const TextStyle(fontSize: 13)), [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Close'))
]);
}
}
} }

View File

@@ -1,9 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
Widget buildInput(BuildContext context, TextEditingController controller, Widget buildInput(BuildContext context, TextEditingController controller,
{int maxLines = 20, String? hint}) { {int maxLines = 20, String? hint}) {
return Card( return RoundRectCard(
child: TextField( TextField(
maxLines: maxLines, maxLines: maxLines,
decoration: InputDecoration( decoration: InputDecoration(
fillColor: Theme.of(context).cardColor, fillColor: Theme.of(context).cardColor,

View File

@@ -8,11 +8,8 @@ class RoundRectCard extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Card( return Card(
child: Padding( child: child,
padding: const EdgeInsets.symmetric(horizontal: 17), clipBehavior: Clip.antiAlias,
child: child,
),
margin: const EdgeInsets.symmetric(vertical: 7),
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(17))), borderRadius: BorderRadius.all(Radius.circular(17))),
); );

View File

@@ -145,6 +145,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.4" version: "4.0.4"
dropdown_button2:
dependency: "direct main"
description:
name: dropdown_button2
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
extended_image: extended_image:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@@ -56,6 +56,7 @@ dependencies:
marquee: ^2.2.0 marquee: ^2.2.0
dart_ping: ^6.1.1 dart_ping: ^6.1.1
dart_ping_ios: ^1.0.0 dart_ping_ios: ^1.0.0
dropdown_button2: ^1.1.1
dev_dependencies: dev_dependencies: