服务器状态页细节优化

This commit is contained in:
LollipopKit
2021-09-18 20:17:30 +08:00
parent c00d3c11d6
commit b4d44c41e5
8 changed files with 47 additions and 26 deletions

View File

@@ -19,7 +19,6 @@ class Analysis {
await Countly.start(); await Countly.start();
await Countly.enableCrashReporting(); await Countly.enableCrashReporting();
await Countly.giveAllConsent(); await Countly.giveAllConsent();
print('Countly init successfully.');
} }
static void recordView(String view) { static void recordView(String view) {

View File

@@ -1,3 +1,5 @@
// ignore_for_file: avoid_print
import 'dart:io'; import 'dart:io';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';

View File

@@ -27,24 +27,22 @@ void showSnackBarWithAction(
} }
Future<bool> openUrl(String url) async { Future<bool> openUrl(String url) async {
print('openUrl $url');
if (!await canLaunch(url)) { if (!await canLaunch(url)) {
print('canLaunch false');
return false; return false;
} }
final ok = await launch(url, forceSafariVC: false); final ok = await launch(url, forceSafariVC: false);
if (ok == true) { if (ok == true) {
return true; return true;
} }
print('launch $url failed');
return false; return false;
} }
Future<T?>? showRoundDialog<T>( Future<T?>? showRoundDialog<T>(
BuildContext context, String title, Widget child, List<Widget> actions, BuildContext context, String title, Widget child, List<Widget> actions,
{EdgeInsets? padding}) { {EdgeInsets? padding, bool barrierDismiss = true}) {
return showDialog<T>( return showDialog<T>(
context: context, context: context,
barrierDismissible: barrierDismiss,
builder: (ctx) { builder: (ctx) {
return CardDialog( return CardDialog(
title: Text(title), title: Text(title),

View File

@@ -29,7 +29,7 @@ class TcpStatus {
fail = json["fail"]?.toInt(); fail = json["fail"]?.toInt();
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>(); final Map<String, dynamic> data = <String, dynamic>{};
data["maxConn"] = maxConn; data["maxConn"] = maxConn;
data["active"] = active; data["active"] = active;
data["passive"] = passive; data["passive"] = passive;

View File

@@ -38,7 +38,6 @@ void runInZone(dynamic Function() body) {
} }
void onError(Object obj, StackTrace stack) { void onError(Object obj, StackTrace stack) {
print('error: $obj');
Analysis.recordException(obj); Analysis.recordException(obj);
final debugProvider = locator<DebugProvider>(); final debugProvider = locator<DebugProvider>();
debugProvider.addError(obj); debugProvider.addError(obj);

View File

@@ -2,6 +2,7 @@ import 'package:after_layout/after_layout.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:toolbox/core/route.dart'; import 'package:toolbox/core/route.dart';
import 'package:toolbox/core/update.dart';
import 'package:toolbox/core/utils.dart'; import 'package:toolbox/core/utils.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';
@@ -52,8 +53,12 @@ class _MyHomePageState extends State<MyHomePage>
body: TabBarView(controller: _tabController, children: const [ body: TabBarView(controller: _tabController, children: const [
ServerPage(), ServerPage(),
ConvertPage(), ConvertPage(),
ConvertPage(), Center(
ConvertPage(), child: Text('1'),
),
Center(
child: Text('2'),
),
]), ]),
); );
} }
@@ -106,5 +111,6 @@ class _MyHomePageState extends State<MyHomePage>
Future<void> afterFirstLayout(BuildContext context) async { Future<void> afterFirstLayout(BuildContext context) async {
await GetIt.I.allReady(); await GetIt.I.allReady();
await locator<ServerProvider>().loadLocalData(); await locator<ServerProvider>().loadLocalData();
await doUpdate(context);
} }
} }

View File

@@ -85,7 +85,10 @@ class _ServerPageState extends State<ServerPage>
void showAddServerDialog() { void showAddServerDialog() {
showRoundDialog(context, '新建服务器连接', _buildTextInputField(context), [ showRoundDialog(context, '新建服务器连接', _buildTextInputField(context), [
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () {
clearTextField();
Navigator.of(context).pop();
},
child: const Text('关闭')), child: const Text('关闭')),
TextButton( TextButton(
onPressed: () { onPressed: () {
@@ -101,12 +104,7 @@ class _ServerPageState extends State<ServerPage>
port: int.parse(portController.text), port: int.parse(portController.text),
user: usernameController.text, user: usernameController.text,
authorization: authorization)); authorization: authorization));
nameController.clear(); clearTextField();
ipController.clear();
portController.clear();
usernameController.clear();
passwordController.clear();
keyController.clear();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: const Text('连接')) child: const Text('连接'))
@@ -161,6 +159,15 @@ class _ServerPageState extends State<ServerPage>
); );
} }
void clearTextField() {
nameController.clear();
ipController.clear();
portController.clear();
usernameController.clear();
passwordController.clear();
keyController.clear();
}
Widget _buildEachServerCard(ServerStatus ss, ServerPrivateInfo spi) { Widget _buildEachServerCard(ServerStatus ss, ServerPrivateInfo spi) {
return GestureDetector( return GestureDetector(
child: _buildEachCardContent(ss, spi), child: _buildEachCardContent(ss, spi),
@@ -177,9 +184,12 @@ class _ServerPageState extends State<ServerPage>
keyController.text = auth['privateKey']; keyController.text = auth['privateKey'];
} }
showRoundDialog(context, '新建服务器连接', _buildTextInputField(context), [ showRoundDialog(context, '修改服务器信息', _buildTextInputField(context), [
TextButton( TextButton(
onPressed: () => Navigator.of(context).pop(), onPressed: () {
clearTextField();
Navigator.of(context).pop();
},
child: const Text('关闭')), child: const Text('关闭')),
TextButton( TextButton(
onPressed: () { onPressed: () {
@@ -197,16 +207,21 @@ class _ServerPageState extends State<ServerPage>
port: int.parse(portController.text), port: int.parse(portController.text),
user: usernameController.text, user: usernameController.text,
authorization: authorization)); authorization: authorization));
nameController.clear(); clearTextField();
ipController.clear();
portController.clear();
usernameController.clear();
passwordController.clear();
keyController.clear();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: const Text('连接')) child: const Text('保存')),
]); TextButton(
onPressed: () {
serverProvider.delServer(spi);
clearTextField();
Navigator.of(context).pop();
},
child: const Text(
'删除',
style: TextStyle(color: Colors.red),
))
], barrierDismiss: false);
}); });
} }

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env dart #!/usr/bin/env dart
// ignore_for_file: avoid_print
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';