Update server_status_interval_edit view

This commit is contained in:
LollipopKit
2021-10-26 16:05:40 +08:00
parent ad0638b5b3
commit dd3c07f39d
11 changed files with 107 additions and 43 deletions

View File

@@ -49,11 +49,10 @@ class MyApp extends StatelessWidget {
focusedBorder: UnderlineInputBorder( focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor))), borderSide: BorderSide(color: primaryColor))),
radioTheme: RadioThemeData( radioTheme: RadioThemeData(
fillColor: getMaterialStateColor(primaryColor)), fillColor: getMaterialStateColor(primaryColor),),
), ),
darkTheme: ThemeData.dark().copyWith( darkTheme: ThemeData.dark().copyWith(
primaryColor: primaryColor, primaryColor: primaryColor,
appBarTheme: AppBarTheme(backgroundColor: primaryColor),
floatingActionButtonTheme: FloatingActionButtonThemeData( floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: primaryColor), backgroundColor: primaryColor),
iconTheme: IconThemeData(color: primaryColor), iconTheme: IconThemeData(color: primaryColor),

View File

@@ -73,11 +73,10 @@ class ServerProvider extends BusyProvider {
} }
Future<void> startAutoRefresh() async { Future<void> startAutoRefresh() async {
Timer.periodic( final duration =
Duration( locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
seconds: locator<SettingStore>() if (duration == 0) return;
.serverStatusUpdateInterval Timer.periodic(Duration(seconds: duration), (_) async {
.fetch()!), (_) async {
await refreshData(); await refreshData();
}); });
} }
@@ -86,12 +85,14 @@ class ServerProvider extends BusyProvider {
_servers.add(genInfo(info)); _servers.add(genInfo(info));
locator<ServerStore>().put(info); locator<ServerStore>().put(info);
notifyListeners(); notifyListeners();
refreshData();
} }
void delServer(ServerPrivateInfo info) { void delServer(ServerPrivateInfo info) {
_servers.removeWhere((e) => e.info == info); _servers.removeWhere((e) => e.info == info);
locator<ServerStore>().delete(info); locator<ServerStore>().delete(info);
notifyListeners(); notifyListeners();
refreshData();
} }
void updateServer(ServerPrivateInfo old, ServerPrivateInfo newInfo) { void updateServer(ServerPrivateInfo old, ServerPrivateInfo newInfo) {
@@ -100,6 +101,7 @@ class ServerProvider extends BusyProvider {
_servers[idx].client = genClient(newInfo); _servers[idx].client = genClient(newInfo);
locator<ServerStore>().update(old, newInfo); locator<ServerStore>().update(old, newInfo);
notifyListeners(); notifyListeners();
refreshData();
} }
Future<ServerStatus> _getData(ServerPrivateInfo info, int idx) async { Future<ServerStatus> _getData(ServerPrivateInfo info, int idx) async {

View File

@@ -3,7 +3,8 @@
class BuildData { class BuildData {
static const String name = "ToolBox"; static const String name = "ToolBox";
static const int build = 23; static const int build = 23;
static const String engine = "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (11 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n"; static const String engine =
"Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (11 days ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
static const String buildAt = "2021-10-26 14:18:53.461371"; static const String buildAt = "2021-10-26 14:18:53.461371";
static const int modifications = 4; static const int modifications = 4;
} }

View File

@@ -1,5 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
@@ -109,7 +110,7 @@ class _ConvertPageState extends State<ConvertPage>
child: SizedBox( child: SizedBox(
width: _media.size.width * 0.3, width: _media.size.width * 0.3,
child: Row( child: Row(
children: const [Icon(Icons.change_circle), Text('Upside down')], children: const [Icon(Icons.change_circle), Text(' Upside down')],
), ),
), ),
onPressed: () { onPressed: () {
@@ -147,7 +148,18 @@ class _ConvertPageState extends State<ConvertPage>
Widget _buildResult() { Widget _buildResult() {
return SizedBox( return SizedBox(
height: _media.size.height * 0.33, height: _media.size.height * 0.33,
child: _buildInput(_textEditingControllerResult), child: Stack(
children: [
_buildInput(_textEditingControllerResult),
Positioned(
right: 7,
top: 7,
child: IconButton(
onPressed: () =>
FlutterClipboard.copy(_textEditingControllerResult.text),
icon: const Icon(Icons.copy)))
],
),
); );
} }

View File

@@ -55,6 +55,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
minLines: 3, minLines: 3,
maxLines: 10, maxLines: 10,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
enableSuggestions: false,
decoration: buildDecoration('Private Key', icon: Icons.vpn_key), decoration: buildDecoration('Private Key', icon: Icons.vpn_key),
), ),
TextField( TextField(

View File

@@ -62,25 +62,30 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
TextField( TextField(
controller: nameController, controller: nameController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: buildDecoration('Name', icon: Icons.info), decoration:
buildDecoration('Name', icon: Icons.info, hint: 'Example'),
), ),
TextField( TextField(
controller: ipController, controller: ipController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
autocorrect: false, autocorrect: false,
decoration: buildDecoration('Host', icon: Icons.storage), enableSuggestions: false,
decoration: buildDecoration('Host',
icon: Icons.storage, hint: 'example.com'),
), ),
TextField( TextField(
controller: portController, controller: portController,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: decoration: buildDecoration('Port',
buildDecoration('Port', icon: Icons.format_list_numbered), icon: Icons.format_list_numbered, hint: '22'),
), ),
TextField( TextField(
controller: usernameController, controller: usernameController,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
autocorrect: false, autocorrect: false,
decoration: buildDecoration('User', icon: Icons.account_box), enableSuggestions: false,
decoration: buildDecoration('User',
icon: Icons.account_box, hint: 'root'),
), ),
const SizedBox(height: 7), const SizedBox(height: 7),
Row( Row(
@@ -96,7 +101,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
controller: passwordController, controller: passwordController,
obscureText: true, obscureText: true,
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: buildDecoration('Pwd', icon: Icons.password), decoration: buildDecoration('Pwd',
icon: Icons.password, hint: 'Password'),
onSubmitted: (_) => {}, onSubmitted: (_) => {},
) )
: const SizedBox(), : const SizedBox(),
@@ -138,8 +144,23 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
child: const Icon(Icons.send), child: const Icon(Icons.send),
onPressed: () { onPressed: () {
if (ipController.text == '') {
showSnackBar(context, const Text('Please enter host.'));
return;
}
if (!usePublicKey && passwordController.text == '') {
showSnackBar(context, const Text('Please enter password.'));
return;
}
if (usePublicKey && _typeOptionIndex == -1) { if (usePublicKey && _typeOptionIndex == -1) {
showSnackBar(context, const Text('Please select a private key.')); showSnackBar(context, const Text('Please select a private key.'));
return;
}
if (usernameController.text == '') {
usernameController.text = 'root';
}
if (portController.text == '') {
portController.text = '22';
} }
final authorization = usePublicKey final authorization = usePublicKey
? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]} ? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]}

View File

@@ -121,7 +121,8 @@ class _ServerPageState extends State<ServerPage>
Text(ss.uptime!, Text(ss.uptime!,
textScaleFactor: 1.0, textScaleFactor: 1.0,
style: TextStyle( style: TextStyle(
color: _theme.textTheme.bodyText1!.color!.withAlpha(100), fontSize: 11)) color: _theme.textTheme.bodyText1!.color!.withAlpha(100),
fontSize: 11))
], ],
), ),
const SizedBox( const SizedBox(

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart'; import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import 'package:toolbox/core/utils.dart'; import 'package:toolbox/data/res/color.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';
import 'package:toolbox/view/widget/round_rect_card.dart'; import 'package:toolbox/view/widget/round_rect_card.dart';
@@ -15,14 +15,20 @@ class SettingPage extends StatefulWidget {
class _SettingPageState extends State<SettingPage> { class _SettingPageState extends State<SettingPage> {
late SettingStore _store; late SettingStore _store;
late int _selectedColorValue; late int _selectedColorValue;
final TextEditingController _intervalController = TextEditingController(); double _value = 0;
late Color _textColor;
@override
void didChangeDependencies() {
super.didChangeDependencies();
_textColor = Theme.of(context).textTheme.bodyText1!.color!;
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_store = locator<SettingStore>(); _store = locator<SettingStore>();
_intervalController.text = _value = _store.serverStatusUpdateInterval.fetch()!.toDouble();
_store.serverStatusUpdateInterval.fetch()!.toString();
} }
@override @override
@@ -36,28 +42,40 @@ class _SettingPageState extends State<SettingPage> {
children: [ children: [
RoundRectCard(_buildAppColorPreview()), RoundRectCard(_buildAppColorPreview()),
RoundRectCard( RoundRectCard(
ListTile( ExpansionTile(
contentPadding: EdgeInsets.zero, tilePadding: EdgeInsets.zero,
title: const Text( childrenPadding: EdgeInsets.zero,
'Server status update interval (seconds)', title: Text(
style: TextStyle(fontSize: 14), 'Server status update interval',
style: TextStyle(fontSize: 14, color: _textColor),
textAlign: TextAlign.start, textAlign: TextAlign.start,
), ),
trailing: SizedBox( subtitle: const Text(
width: MediaQuery.of(context).size.width * 0.1, 'Will take effect the next time app launches.',
child: TextField( style: TextStyle(color: Colors.grey),
textAlign: TextAlign.center, ),
controller: _intervalController, trailing: Text('${_value.toInt()} s'),
keyboardType: TextInputType.number, children: [
onSubmitted: (val) { Slider(
_store.serverStatusUpdateInterval.put(int.parse(val)); thumbColor: primaryColor,
showSnackBar( activeColor: primaryColor.withOpacity(0.7),
context, min: 0,
const Text( max: 10,
'This setting will take effect \nthe next time app launch')); value: _value,
onChanged: (newValue) {
setState(() {
_value = newValue;
});
}, },
onChangeEnd: (val) =>
_store.serverStatusUpdateInterval.put(val.toInt()),
label: '${_value.toInt()} seconds',
divisions: 10,
), ),
), const SizedBox(height: 3,),
_value == 0.0 ? const Text('You set to 0, will not update automatically.') : const SizedBox(),
const SizedBox(height: 13,)
],
), ),
) )
], ],
@@ -81,9 +99,9 @@ class _SettingPageState extends State<SettingPage> {
width: 27, width: 27,
), ),
), ),
title: const Text( title: Text(
'App primary color', 'App primary color',
style: TextStyle(fontSize: 14), style: TextStyle(fontSize: 14, color: _textColor),
)); ));
} }

View File

@@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
InputDecoration buildDecoration(String label, InputDecoration buildDecoration(String label,
{TextStyle? textStyle, IconData? icon}) { {TextStyle? textStyle, IconData? icon, String? hint}) {
return InputDecoration( return InputDecoration(
labelText: label, labelText: label,
labelStyle: textStyle, labelStyle: textStyle,
hintText: hint,
icon: Icon( icon: Icon(
icon, icon,
color: primaryColor, color: primaryColor,

View File

@@ -45,6 +45,13 @@ packages:
url: "https://github.com/LollipopKit/circle_chart" url: "https://github.com/LollipopKit/circle_chart"
source: git source: git
version: "0.0.3" version: "0.0.3"
clipboard:
dependency: "direct main"
description:
name: clipboard
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
clock: clock:
dependency: transitive dependency: transitive
description: description:

View File

@@ -50,6 +50,7 @@ dependencies:
git: git:
url: https://github.com/LollipopKit/circle_chart url: https://github.com/LollipopKit/circle_chart
ref: main ref: main
clipboard: ^0.1.3
dev_dependencies: dev_dependencies: