optimize ping page & make.dart

This commit is contained in:
Junyuan Feng
2022-11-07 20:15:39 +08:00
parent 5b8468effa
commit bfd31e561c
10 changed files with 78 additions and 43 deletions

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 158;
static const int build = 159;
static const String engine =
"Flutter 3.3.4 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision eb6d86ee27 (5 weeks ago) • 2022-10-04 22:31:45 -0700\nEngine • revision c08d7d5efc\nTools • Dart 2.18.2 • DevTools 2.15.0\n";
static const String buildAt = "2022-11-07 19:16:17.058901";
static const String buildAt = "2022-11-07 19:55:21.553007";
static const int modifications = 0;
}

View File

@@ -122,6 +122,8 @@ class MessageLookup extends MessageLookupByLibrary {
"import": MessageLookupByLibrary.simpleMessage("Import"),
"importAndExport":
MessageLookupByLibrary.simpleMessage("Import and Export"),
"inputDomainHere":
MessageLookupByLibrary.simpleMessage("Input Domain here"),
"install": MessageLookupByLibrary.simpleMessage("install"),
"installDockerWithUrl": MessageLookupByLibrary.simpleMessage(
"Please https://docs.docker.com/engine/install docker first."),

View File

@@ -111,6 +111,7 @@ class MessageLookup extends MessageLookupByLibrary {
"httpFailedWithCode": m5,
"import": MessageLookupByLibrary.simpleMessage("导入"),
"importAndExport": MessageLookupByLibrary.simpleMessage("导入或导出"),
"inputDomainHere": MessageLookupByLibrary.simpleMessage("在这里输入域名"),
"install": MessageLookupByLibrary.simpleMessage("安装"),
"installDockerWithUrl": MessageLookupByLibrary.simpleMessage(
"请先 https://docs.docker.com/engine/install docker"),

View File

@@ -1340,6 +1340,16 @@ class S {
args: [],
);
}
/// `Input Domain here`
String get inputDomainHere {
return Intl.message(
'Input Domain here',
name: 'inputDomainHere',
desc: '',
args: [],
);
}
}
class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View File

@@ -127,5 +127,6 @@
"clickSee": "Click here",
"feedback": "Feedback",
"feedbackOnGithub": "If you have any questions, please feedback on Github.",
"update": "Update"
"update": "Update",
"inputDomainHere": "Input Domain here"
}

View File

@@ -127,5 +127,6 @@
"clickSee": "点击查看",
"feedback": "反馈",
"feedbackOnGithub": "如果你有任何问题请在GitHub反馈",
"update": "更新"
"update": "更新",
"inputDomainHere": "在这里输入域名"
}

View File

@@ -9,6 +9,12 @@ import 'package:toolbox/locator.dart';
import 'package:toolbox/view/widget/input_field.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
final doaminReg =
RegExp(r'^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$');
final ipv4Reg =
RegExp(r'^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$');
final ipv6Reg = RegExp(r'^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$');
class PingPage extends StatefulWidget {
const PingPage({Key? key}) : super(key: key);
@@ -45,23 +51,25 @@ class _PingPageState extends State<PingPage>
super.build(context);
return Scaffold(
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 7),
child: Column(children: [
const SizedBox(height: 13),
buildInput(context, _textEditingController,
maxLines: 1, onSubmitted: (_) => doPing()),
SizedBox(
width: double.infinity,
height: _media.size.height * 0.6,
child: ListView.builder(
controller: ScrollController(),
itemCount: _results.length,
itemBuilder: (context, index) {
final result = _results[index];
return _buildResultItem(result);
}),
),
])),
padding: const EdgeInsets.symmetric(horizontal: 7),
child: Column(children: [
const SizedBox(height: 13),
buildInput(context, _textEditingController,
hint: s.inputDomainHere,
maxLines: 1,
onSubmitted: (_) => doPing()),
SizedBox(
width: double.infinity,
height: _media.size.height * 0.6,
child: ListView.builder(
controller: ScrollController(),
itemCount: _results.length,
itemBuilder: (context, index) {
final result = _results[index];
return _buildResultItem(result);
}),
),
])),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.play_arrow),
onPressed: () {
@@ -118,14 +126,25 @@ class _PingPageState extends State<PingPage>
return;
}
await Future.wait(_serverProvider.servers.map((e) async {
if (e.client == null) {
return;
}
final result = await e.client!.run('ping -c 3 $target').string;
_results.add(PingResult.parse(e.info.name, result));
setState(() {});
}));
if (!doaminReg.hasMatch(target) &&
!ipv4Reg.hasMatch(target) &&
!ipv6Reg.hasMatch(target)) {
showSnackBar(context, Text(s.pingInputIP));
return;
}
try {
await Future.wait(_serverProvider.servers.map((e) async {
if (e.client == null) {
return;
}
final result = await e.client!.run('ping -c 3 $target').string;
_results.add(PingResult.parse(e.info.name, result));
setState(() {});
}));
} catch (e) {
showSnackBar(context, Text(e.toString()));
}
}
@override