opt.: popupmenu

This commit is contained in:
lollipopkit
2023-05-09 22:04:45 +08:00
parent b4f3fce64a
commit c1d1af8c01
15 changed files with 145 additions and 211 deletions

View File

@@ -25,16 +25,19 @@ extension ColorX on Color {
});
}
MaterialColor get materialColor => MaterialColor(value, {
50: withOpacity(0.05),
100: withOpacity(0.1),
200: withOpacity(0.2),
300: withOpacity(0.3),
400: withOpacity(0.4),
500: withOpacity(0.5),
600: withOpacity(0.6),
700: withOpacity(0.7),
800: withOpacity(0.8),
900: withOpacity(0.9),
});
MaterialColor get materialColor => MaterialColor(
value,
{
50: withOpacity(0.05),
100: withOpacity(0.1),
200: withOpacity(0.2),
300: withOpacity(0.3),
400: withOpacity(0.4),
500: withOpacity(0.5),
600: withOpacity(0.6),
700: withOpacity(0.7),
800: withOpacity(0.8),
900: withOpacity(0.9),
},
);
}

View File

@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/data/res/ui.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../data/model/server/snippet.dart';
@@ -97,21 +96,6 @@ void setTransparentNavigationBar(BuildContext context) {
}
}
Widget buildPopuopMenu<T>({
required List<PopupMenuEntry<T>> items,
required void Function(T) onSelected,
Widget child = popMenuChild,
EdgeInsetsGeometry? padding,
}) {
return PopupMenuButton<T>(
itemBuilder: (_) => items,
onSelected: onSelected,
padding: padding ?? EdgeInsets.zero,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
child: child,
);
}
String tabTitleName(BuildContext context, int i) {
final s = S.of(context)!;
switch (i) {
@@ -120,7 +104,7 @@ String tabTitleName(BuildContext context, int i) {
case 1:
return s.convert;
case 2:
return s.ping;
return 'Ping';
default:
return '';
}
@@ -165,7 +149,7 @@ void showSnippetDialog(
var snippet = provider.snippets.first;
showRoundDialog(
context: context,
title: Text(s.chooseDestination),
title: Text(s.choose),
child: Picker(
items: provider.snippets.map((e) => Text(e.name)).toList(),
onSelected: (idx) => snippet = provider.snippets[idx],

View File

@@ -8,7 +8,6 @@
"appPrimaryColor": "App primary color",
"attention": "Attention",
"auto": "Auto",
"backDir": "Back",
"backup": "Backup",
"backupAndRestore": "Backup and Restore",
"backupTip": "The exported data is simply encrypted. \nPlease keep it safe.",
@@ -17,30 +16,27 @@
"canPullRefresh": "You can pull to refresh.",
"cancel": "Cancel",
"choose": "Choose",
"chooseDestination": "Choose destination",
"chooseFontFile": "Choose a font file",
"choosePrivateKey": "Choose private key",
"clear": "Clear",
"clickSee": "Click here",
"close": "Close",
"cmd": "Command",
"containerName": "Container name",
"containerStatus": "Container status",
"convert": "Convert",
"copy": "Copy",
"copyPath": "Copy path",
"createFile": "Create file",
"createFolder": "Create folder",
"currentMode": "Current Mode",
"dark": "Dark",
"debug": "Debug",
"decode": "Decode",
"delete": "Delete",
"disconnected": "Disconnected",
"dl2Local": "Download [{fileName}] to local?",
"dockerContainerName": "Container name",
"dl2Local": "Download {fileName} to local?",
"dockerEditHost": "Edit DOCKER_HOST",
"dockerEmptyRunningItems": "No running container. \nIt may be that the env DOCKER_HOST is not read correctly. You can found it by running `echo $DOCKER_HOST` in terminal.",
"dockerImage": "Image",
"dockerImagesFmt": "{count} images",
"dockerNotInstalled": "Docker not installed",
"dockerStatusRunningAndStoppedFmt": "{runningCount} running, {stoppedCount} container stopped.",
@@ -65,10 +61,10 @@
"foundNUpdate": "Found {count} update",
"getPushTokenFailed": "Can't fetch push token",
"gettingToken": "Getting token...",
"go": "Go",
"goto": "Go to",
"host": "Host",
"httpFailedWithCode": "request failed, status code: {code}",
"image": "Image",
"imagesList": "Images list",
"import": "Import",
"inputDomainHere": "Input Domain here",
@@ -80,7 +76,7 @@
"isBusy": "Is busy now",
"keepForeground": "Keep app foreground!",
"keyAuth": "Key Auth",
"lastTry": "Last try!",
"lastTry": "Last try",
"launchPage": "Launch page",
"license": "License",
"light": "Light",
@@ -106,14 +102,12 @@
"nullToken": "Null token",
"ok": "OK",
"onServerDetailPage": "On server detail page",
"onlyIOS": "Only valid on iOS",
"open": "Open",
"paste": "Paste",
"path": "Path",
"pickFile": "Pick file",
"ping": "Ping",
"pingAvg": "Avg:",
"pingInputIP": "Please input a target IP/domain.",
"pingInputIP": "Please input a target IP / domain.",
"pingNoServer": "No server to ping.\nPlease add a server in server tab.",
"pkg": "Pkg",
"platformNotSupportUpdate": "Current platform does not support in app update.\nPlease build from source and install it.",

View File

@@ -8,7 +8,6 @@
"appPrimaryColor": "App主要色",
"attention": "注意",
"auto": "自动",
"backDir": "返回上一级",
"backup": "备份",
"backupAndRestore": "备份和恢复",
"backupTip": "导出的数据仅进行了简单加密,请妥善保管。",
@@ -17,40 +16,37 @@
"canPullRefresh": "可以下拉刷新",
"cancel": "取消",
"choose": "选择",
"chooseDestination": "选择目标",
"chooseFontFile": "选择字体文件",
"choosePrivateKey": "选择私钥",
"clear": "清除",
"clickSee": "点击查看",
"close": "关闭",
"cmd": "命令",
"containerName": "容器名",
"containerStatus": "容器状态",
"convert": "转换",
"copy": "复制",
"copyPath": "复制路径",
"createFile": "创建文件",
"createFolder": "创建文件夹",
"currentMode": "当前模式",
"dark": "暗",
"debug": "调试",
"decode": "解码",
"delete": "删除",
"disconnected": "连接断开",
"dl2Local": "下载 [{fileName}] 到本地?",
"dockerContainerName": "容器名",
"dl2Local": "下载 {fileName} 到本地?",
"dockerEditHost": "编辑 DOCKER_HOST",
"dockerEmptyRunningItems": "没有正在运行的容器。\n这可能是因为环境变量 DOCKER_HOST 没有被正确读取。你可以通过在终端内运行 `echo $DOCKER_HOST` 来获取。",
"dockerImage": "镜像",
"dockerImagesFmt": "共 {count} 个镜像",
"dockerNotInstalled": "Docker未安装",
"dockerNotInstalled": "Docker 未安装",
"dockerStatusRunningAndStoppedFmt": "{runningCount}个正在运行, {stoppedCount}个已停止",
"dockerStatusRunningFmt": "{count}个容器正在运行",
"download": "下载",
"downloadFinished": "下载完成",
"downloadFinished": "下载完成",
"downloadStatus": "{size} 的 {percent}%",
"edit": "编辑",
"encode": "编码",
"error": "出错了",
"error": "错误",
"exampleName": "名称示例",
"experimentalFeature": "实验性功能",
"export": "导出",
@@ -65,21 +61,21 @@
"foundNUpdate": "找到 {count} 个更新",
"getPushTokenFailed": "未能获取到推送token",
"gettingToken": "正在获取Token...",
"go": "开始",
"goto": "前往",
"host": "主机",
"httpFailedWithCode": "请求失败, 状态码: {code}",
"image": "镜像",
"imagesList": "镜像列表",
"import": "导入",
"inputDomainHere": "在这里输入域名",
"install": "安装",
"installDockerWithUrl": "请先 https://docs.docker.com/engine/install docker",
"invalidJson": "无效的json存在格式问题",
"invalidJson": "无效的 JSON",
"invalidVersion": "不支持的版本",
"invalidVersionHelp": "请确保正确安装了docker或者使用的非自编译版本。如果没有以上问题请在 {url} 提交问题。",
"isBusy": "当前正忙",
"keepForeground": "请保持应用处于前台!",
"keyAuth": "钥认证",
"keyAuth": "钥认证",
"lastTry": "最后尝试",
"launchPage": "启动页",
"license": "开源证书",
@@ -106,12 +102,10 @@
"nullToken": "无Token",
"ok": "好",
"onServerDetailPage": "在服务器详情页",
"onlyIOS": "仅在iOS上有效",
"open": "打开",
"paste": "粘贴",
"path": "路径",
"pickFile": "选择文件",
"ping": "Ping",
"pingAvg": "平均:",
"pingInputIP": "请输入目标IP或域名",
"pingNoServer": "没有服务器可用于Ping\n请在服务器tab添加服务器后再试",

View File

@@ -37,8 +37,7 @@ Future<void> initApp() async {
final settings = locator<SettingStore>();
await loadFontFile(settings.fontPath.fetch());
///设置Logger
Logger.root.level = Level.ALL; // defaults to Level.INFO
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print('[${record.loggerName}][${record.level.name}]: ${record.message}');

View File

@@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../core/utils/ui.dart';
import '../widget/input_field.dart';
import '../widget/popup_menu.dart';
import '../widget/round_rect_card.dart';
class ConvertPage extends StatefulWidget {
@@ -132,28 +133,30 @@ class _ConvertPageState extends State<ConvertPage>
)
],
),
trailing: ConstrainedBox(
constraints: BoxConstraints(maxWidth: _media.size.width * 0.35),
child: buildPopuopMenu<int>(
items: items,
onSelected: (p0) {
setState(() {
_typeOptionIndex = p0;
});
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
typeOption[_typeOptionIndex],
textScaleFactor: 1.0,
textAlign: TextAlign.right,
style: const TextStyle(
fontWeight: FontWeight.w500, color: Colors.grey),
trailing: PopupMenu<int>(
items: items,
initialValue: _typeOptionIndex,
onSelected: (p0) {
setState(() {
_typeOptionIndex = p0;
});
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Text(
typeOption[_typeOptionIndex],
textScaleFactor: 1.0,
textAlign: TextAlign.right,
style: const TextStyle(
fontWeight: FontWeight.w500,
color: Colors.grey,
),
],
),
),
const Icon(Icons.keyboard_arrow_down, color: Colors.grey)
],
),
),
),

View File

@@ -16,6 +16,7 @@ import '../../data/res/url.dart';
import '../../data/store/docker.dart';
import '../../locator.dart';
import '../widget/dropdown_menu.dart';
import '../widget/popup_menu.dart';
import '../widget/round_rect_card.dart';
import '../widget/two_line_text.dart';
import '../widget/url_text.dart';
@@ -96,14 +97,14 @@ class _DockerManagePageState extends State<DockerManagePage> {
children: [
Input(
type: TextInputType.text,
label: _s.dockerImage,
label: _s.image,
hint: 'xxx:1.1',
controller: imageCtrl,
),
Input(
type: TextInputType.text,
controller: nameCtrl,
label: _s.dockerContainerName,
label: _s.containerName,
hint: 'xxx',
),
Input(
@@ -466,7 +467,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
Widget _buildMoreBtn(DockerPsItem dItem, bool busy) {
final item = dItem.running ? DockerMenuItems.stop : DockerMenuItems.start;
return buildPopuopMenu(
return PopupMenu(
items: [
PopupMenuItem<DropdownBtnItem>(
value: item,

View File

@@ -154,9 +154,9 @@ class _MyHomePageState extends State<MyHomePage>
icon: const Icon(Icons.code),
label: _s.convert,
),
NavigationDestination(
icon: const Icon(Icons.leak_add),
label: _s.ping,
const NavigationDestination(
icon: Icon(Icons.leak_add),
label: 'Ping',
),
],
);

View File

@@ -20,6 +20,7 @@ import '../../../data/res/url.dart';
import '../../../data/store/setting.dart';
import '../../../locator.dart';
import '../../widget/dropdown_menu.dart';
import '../../widget/popup_menu.dart';
import '../../widget/round_rect_card.dart';
import '../../widget/url_text.dart';
import '../docker.dart';
@@ -258,7 +259,7 @@ class _ServerPageState extends State<ServerPage>
}
Widget _buildMoreBtn(ServerPrivateInfo spi) {
return buildPopuopMenu(
return PopupMenu(
items: <PopupMenuEntry>[
...ServerTabMenuItems.firstItems.map(
(item) => PopupMenuItem<DropdownBtnItem>(

View File

@@ -21,6 +21,7 @@ import '../../data/res/ui.dart';
import '../../data/store/setting.dart';
import '../../locator.dart';
import '../widget/future_widget.dart';
import '../widget/popup_menu.dart';
import '../widget/round_rect_card.dart';
class SettingPage extends StatefulWidget {
@@ -193,8 +194,9 @@ class _SettingPageState extends State<SettingPage> {
_s.willTakEeffectImmediately,
style: grey,
),
trailing: buildPopuopMenu<int>(
trailing: PopupMenu<int>(
items: items,
initialValue: _updateInterval,
onSelected: (val) {
setState(() {
_updateInterval = val;
@@ -263,8 +265,9 @@ class _SettingPageState extends State<SettingPage> {
title: Text(
_s.launchPage,
),
trailing: buildPopuopMenu<int>(
trailing: PopupMenu<int>(
items: items,
initialValue: _launchPageIdx,
onSelected: (idx) {
setState(() {
_launchPageIdx = idx;
@@ -295,8 +298,9 @@ class _SettingPageState extends State<SettingPage> {
title: Text(
_s.termTheme,
),
trailing: buildPopuopMenu<int>(
trailing: PopupMenu<int>(
items: items,
initialValue: _termThemeIdx,
onSelected: (idx) {
setState(() {
_termThemeIdx = idx;
@@ -326,8 +330,9 @@ class _SettingPageState extends State<SettingPage> {
_s.maxRetryCount,
textAlign: TextAlign.start,
),
trailing: buildPopuopMenu<int>(
trailing: PopupMenu<int>(
items: items,
initialValue: _maxRetryCount,
onSelected: (val) {
setState(() {
_maxRetryCount = val;
@@ -356,8 +361,9 @@ class _SettingPageState extends State<SettingPage> {
title: Text(
_s.themeMode,
),
trailing: buildPopuopMenu<int>(
trailing: PopupMenu<int>(
items: items,
initialValue: _nightMode,
onSelected: (idx) {
_nightMode = idx;
_setting.themeMode.put(_nightMode);

View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:toolbox/data/res/ui.dart';
class PopupMenu<T> extends StatelessWidget {
final List<PopupMenuEntry<T>> items;
final void Function(T) onSelected;
final Widget child;
final EdgeInsetsGeometry padding;
final T? initialValue;
const PopupMenu({
super.key,
required this.items,
required this.onSelected,
this.child = popMenuChild,
this.padding = const EdgeInsets.all(7),
this.initialValue,
});
@override
Widget build(BuildContext context) {
return PopupMenuButton<T>(
itemBuilder: (_) => items,
onSelected: onSelected,
initialValue: initialValue,
padding: padding,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
child: child,
);
}
}