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

@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:toolbox/data/res/color.dart';
@@ -109,7 +110,7 @@ class _ConvertPageState extends State<ConvertPage>
child: SizedBox(
width: _media.size.width * 0.3,
child: Row(
children: const [Icon(Icons.change_circle), Text('Upside down')],
children: const [Icon(Icons.change_circle), Text(' Upside down')],
),
),
onPressed: () {
@@ -147,7 +148,18 @@ class _ConvertPageState extends State<ConvertPage>
Widget _buildResult() {
return SizedBox(
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,
maxLines: 10,
keyboardType: TextInputType.text,
enableSuggestions: false,
decoration: buildDecoration('Private Key', icon: Icons.vpn_key),
),
TextField(

View File

@@ -62,25 +62,30 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
TextField(
controller: nameController,
keyboardType: TextInputType.text,
decoration: buildDecoration('Name', icon: Icons.info),
decoration:
buildDecoration('Name', icon: Icons.info, hint: 'Example'),
),
TextField(
controller: ipController,
keyboardType: TextInputType.text,
autocorrect: false,
decoration: buildDecoration('Host', icon: Icons.storage),
enableSuggestions: false,
decoration: buildDecoration('Host',
icon: Icons.storage, hint: 'example.com'),
),
TextField(
controller: portController,
keyboardType: TextInputType.number,
decoration:
buildDecoration('Port', icon: Icons.format_list_numbered),
decoration: buildDecoration('Port',
icon: Icons.format_list_numbered, hint: '22'),
),
TextField(
controller: usernameController,
keyboardType: TextInputType.text,
autocorrect: false,
decoration: buildDecoration('User', icon: Icons.account_box),
enableSuggestions: false,
decoration: buildDecoration('User',
icon: Icons.account_box, hint: 'root'),
),
const SizedBox(height: 7),
Row(
@@ -96,7 +101,8 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
controller: passwordController,
obscureText: true,
keyboardType: TextInputType.text,
decoration: buildDecoration('Pwd', icon: Icons.password),
decoration: buildDecoration('Pwd',
icon: Icons.password, hint: 'Password'),
onSubmitted: (_) => {},
)
: const SizedBox(),
@@ -138,8 +144,23 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.send),
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) {
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
? {"privateKey": _keyInfo[0], "passphrase": _keyInfo[1]}

View File

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

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.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/locator.dart';
import 'package:toolbox/view/widget/round_rect_card.dart';
@@ -15,14 +15,20 @@ class SettingPage extends StatefulWidget {
class _SettingPageState extends State<SettingPage> {
late SettingStore _store;
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
void initState() {
super.initState();
_store = locator<SettingStore>();
_intervalController.text =
_store.serverStatusUpdateInterval.fetch()!.toString();
_value = _store.serverStatusUpdateInterval.fetch()!.toDouble();
}
@override
@@ -36,28 +42,40 @@ class _SettingPageState extends State<SettingPage> {
children: [
RoundRectCard(_buildAppColorPreview()),
RoundRectCard(
ListTile(
contentPadding: EdgeInsets.zero,
title: const Text(
'Server status update interval (seconds)',
style: TextStyle(fontSize: 14),
ExpansionTile(
tilePadding: EdgeInsets.zero,
childrenPadding: EdgeInsets.zero,
title: Text(
'Server status update interval',
style: TextStyle(fontSize: 14, color: _textColor),
textAlign: TextAlign.start,
),
trailing: SizedBox(
width: MediaQuery.of(context).size.width * 0.1,
child: TextField(
textAlign: TextAlign.center,
controller: _intervalController,
keyboardType: TextInputType.number,
onSubmitted: (val) {
_store.serverStatusUpdateInterval.put(int.parse(val));
showSnackBar(
context,
const Text(
'This setting will take effect \nthe next time app launch'));
},
),
subtitle: const Text(
'Will take effect the next time app launches.',
style: TextStyle(color: Colors.grey),
),
trailing: Text('${_value.toInt()} s'),
children: [
Slider(
thumbColor: primaryColor,
activeColor: primaryColor.withOpacity(0.7),
min: 0,
max: 10,
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,
),
),
title: const Text(
title: Text(
'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';
InputDecoration buildDecoration(String label,
{TextStyle? textStyle, IconData? icon}) {
{TextStyle? textStyle, IconData? icon, String? hint}) {
return InputDecoration(
labelText: label,
labelStyle: textStyle,
hintText: hint,
icon: Icon(
icon,
color: primaryColor,