Fix & Optimize

- fix ping when results is empty
- optimize ping speed
This commit is contained in:
Junyuan Feng
2022-05-03 20:26:00 +08:00
parent 5c59833233
commit 52b82af52c
3 changed files with 23 additions and 17 deletions

View File

@@ -2,8 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 118;
static const String engine = "Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision c860cba910 (6 weeks ago) • 2022-03-25 00:23:12 -0500\nEngine • revision 57d3bac3dd\nTools • Dart 2.16.2 • DevTools 2.9.2\n";
static const String buildAt = "2022-05-03 12:05:15.250795";
static const int modifications = 4;
static const int build = 119;
static const String engine =
"Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision c860cba910 (6 weeks ago) • 2022-03-25 00:23:12 -0500\nEngine • revision 57d3bac3dd\nTools • Dart 2.16.2 • DevTools 2.9.2\n";
static const String buildAt = "2022-05-03 12:06:26.688732";
static const int modifications = 0;
}

View File

@@ -77,6 +77,9 @@ class _PingPageState extends State<PingPage>
String _buildPingSummary(PingResult result) {
final ip = result.ip ?? 'unkown';
if (result.results == null || result.results!.isEmpty) {
return '$ip - no results';
}
final ttl = result.results?.first.ttl ?? 'unkown';
final loss = result.statistic?.loss ?? 'unkown';
final min = result.statistic?.min ?? 'unkown';
@@ -91,14 +94,15 @@ class _PingPageState extends State<PingPage>
showSnackBar(context, const Text('Please input a target'));
return;
}
for (var si in locator<ServerProvider>().servers) {
if (si.client == null) {
continue;
await Future.wait(locator<ServerProvider>().servers.map((e) async {
if (e.client == null) {
return;
}
final result = await si.client!.run('ping -c 3 $target').string;
_results.add(PingResult.parse(si.info.name, result));
final result = await e.client!.run('ping -c 3 $target').string;
_results.add(PingResult.parse(e.info.name, result));
setState(() {});
}
}));
}
Widget _buildControl() {
@@ -115,7 +119,7 @@ class _PingPageState extends State<PingPage>
foregroundColor: MaterialStateProperty.all(primaryColor)),
child: Row(
children: const [
Icon(Icons.stop),
Icon(Icons.delete),
SizedBox(
width: 7,
),
@@ -124,6 +128,7 @@ class _PingPageState extends State<PingPage>
),
onPressed: () {
_results.clear();
setState(() {});
},
),
TextButton(