优化使用体验

This commit is contained in:
jyuesong
2022-01-19 15:14:29 +08:00
parent 16f4f27f17
commit 3959155c1b
8 changed files with 190 additions and 133 deletions

View File

@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart';
@@ -24,8 +23,7 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
final TextEditingController _commandController = TextEditingController();
final TextEditingController _cronController = TextEditingController();
final String scheduleCron = r"[ \t]*(@reboot|@yearly|@annually|@monthly|@weekly|@daily|@midnight|@hourly|((((([1-5]?[0-9])-)?([1-5]?[0-9])|\*)(/([1-5]?[0-9]))?,)*((([1-5]?[0-9])-)?([1-5]?[0-9])|\*)(/([1-5]?[0-9]))?)[ \t]+(((((2[0-3]|1[0-9]|[0-9])-)?(2[0-3]|1[0-9]|[0-9])|\*)(/(2[0-3]|1[0-9]|[0-9]))?,)*(((2[0-3]|1[0-9]|[0-9])-)?(2[0-3]|1[0-9]|[0-9])|\*)(/(2[0-3]|1[0-9]|[0-9]))?)[ \t]+(((((3[01]|[12][0-9]|[1-9])-)?(3[01]|[12][0-9]|[1-9])|\*)(/(3[01]|[12][0-9]|[1-9]))?,)*(((3[01]|[12][0-9]|[1-9])-)?(3[01]|[12][0-9]|[1-9])|\*)(/(3[01]|[12][0-9]|[1-9]))?)[ \t]+((((((1[0-2]|[1-9])|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])-)?((1[0-2]|[1-9])|[Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu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u]|[Ff][Rr][Ii]|[Ss][Aa][Tt])|\*)(/([0-7]|[Ss][Uu][Nn]|[Mm][Oo][Nn]|[Tt][Uu][Ee]|[Ww][Ee][Dd]|[Tt][Hh][Uu]|[Ff][Rr][Ii]|[Ss][Aa][Tt]))?,)*((([0-7]|[Ss][Uu][Nn]|[Mm][Oo][Nn]|[Tt][Uu][Ee]|[Ww][Ee][Dd]|[Tt][Hh][Uu]|[Ff][Rr][Ii]|[Ss][Aa][Tt])-)?([0-7]|[Ss][Uu][Nn]|[Mm][Oo][Nn]|[Tt][Uu][Ee]|[Ww][Ee][Dd]|[Tt][Hh][Uu]|[Ff][Rr][Ii]|[Ss][Aa][Tt])|\*)(/([0-7]|[Ss][Uu][Nn]|[Mm][Oo][Nn]|[Tt][Uu][Ee]|[Ww][Ee][Dd]|[Tt][Hh][Uu]|[Ff][Rr][Ii]|[Ss][Aa][Tt]))?))[ \t]*$";
FocusNode focusNode = FocusNode();
@override
void initState() {
@@ -38,6 +36,11 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
} else {
taskBean = TaskBean();
}
WidgetsBinding.instance?.addPostFrameCallback(
(timeStamp) {
focusNode.requestFocus();
},
);
}
@override
@@ -98,6 +101,7 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
height: 10,
),
TextField(
focusNode: focusNode,
controller: _nameController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
@@ -133,9 +137,6 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
controller: _commandController,
maxLines: 4,
minLines: 1,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(scheduleCron)),
],
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入命令",
@@ -174,6 +175,15 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
),
autofocus: false,
),
const SizedBox(
height: 5,
),
const Text(
"定时的cron不校验,自己确保写的是正确的cron",
style: TextStyle(
fontSize: 12,
),
),
],
),
),
@@ -196,12 +206,14 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
return;
}
commitReal();
}
void commitReal() async {
taskBean.name = _nameController.text;
taskBean.command = _commandController.text;
taskBean.schedule = _cronController.text;
HttpResponse<NullResponse> response = await Api.addTask(
_nameController.text, _commandController.text, _cronController.text,
id: taskBean.sId);
HttpResponse<NullResponse> response = await Api.addTask(_nameController.text, _commandController.text, _cronController.text, id: taskBean.sId);
if (response.success) {
"操作成功".toast();