14 Commits

Author SHA1 Message Date
jyuesong
484e1eeee3 fix bug 2022-06-23 18:55:11 +08:00
jyuesong
e2a2ae55ec 支持高刷 2022-06-23 17:16:04 +08:00
NewTab
558b780235 Merge pull request #4 from huoxue1/main
新增订阅管理,新增环境变量备份和导入导出
2022-06-23 16:43:12 +08:00
3343780376
1cd3724805 新增订阅管理
新增环境变量导入和导出
2022-06-23 16:30:39 +08:00
jyuesong
7e3a63169e 依赖管理支持批量添加 2022-06-16 15:54:19 +08:00
jyuesong
1298dba590 支持上传脚本 2022-06-16 14:37:47 +08:00
jyuesong
2005083d2e 新增代码文件支持行号显示 2022-06-15 11:05:49 +08:00
jyuesong
4e3f8a0df9 1.1.0 release 2022-06-08 10:42:26 +08:00
jyuesong
5698277301 1.1.0 release 2022-06-08 10:18:24 +08:00
jyuesong
02be737264 1.1.0 release 2022-06-08 10:11:49 +08:00
jyuesong
9558f3d235 1.1.0 release 2022-06-08 10:11:32 +08:00
jyuesong
14c3b1a965 优化使用体验 2022-06-08 10:06:54 +08:00
jyuesong
b89de1414a 优化使用体验 2022-06-07 19:32:39 +08:00
jyuesong
9759caf9b8 优化搜索框样式,优化任务列表,环境变量等相关页面使用体验 2022-06-07 18:28:38 +08:00
232 changed files with 10156 additions and 1396 deletions

1
.gitignore vendored
View File

@@ -44,3 +44,4 @@ app.*.map.json
/android/app/debug /android/app/debug
/android/app/profile /android/app/profile
/android/app/release /android/app/release
.fvm/

View File

@@ -1,10 +1,36 @@
# This file tracks properties of this Flutter project. # This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc. # Used by Flutter tool to assess capabilities and perform upgrades etc.
# #
# This file should be version controlled and should not be manually edited. # This file should be version controlled.
version: version:
revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
channel: stable channel: stable
project_type: app project_type: app
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: linux
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: macos
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
- platform: windows
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
# User provided section
# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

BIN
assets/images/dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

BIN
assets/images/faceid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/images/figure.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

BIN
assets/images/icon_a.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
assets/images/icon_b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/images/icon_cron.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
assets/images/icon_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
assets/images/icon_env.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 960 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
assets/images/icon_fail.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
assets/images/icon_file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
assets/images/icon_idle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
assets/images/icon_s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
assets/images/js.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
assets/images/json.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

BIN
assets/images/light.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

BIN
assets/images/normal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/images/other.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

BIN
assets/images/py.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
assets/images/shell.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
assets/images/svip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
assets/images/svip_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
assets/images/ts.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
assets/images/vip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
assets/images/vip_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -24,12 +24,14 @@ class BaseStateWidget<T extends BaseViewModel> extends ConsumerStatefulWidget {
_BaseStateWidgetState<T> createState() => _BaseStateWidgetState<T>(); _BaseStateWidgetState<T> createState() => _BaseStateWidgetState<T>();
} }
class _BaseStateWidgetState<T extends BaseViewModel> extends ConsumerState<BaseStateWidget<T>> with LazyLoadState<BaseStateWidget<T>> { class _BaseStateWidgetState<T extends BaseViewModel>
extends ConsumerState<BaseStateWidget<T>>
with LazyLoadState<BaseStateWidget<T>> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var viewModel = ref.watch<T>(widget.model); var viewModel = ref.watch<T>(widget.model);
if (viewModel.failedToast != null) { if (viewModel.failedToast != null) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
(viewModel.failedToast ?? "").toast(); (viewModel.failedToast ?? "").toast();
viewModel.clearToast(); viewModel.clearToast();
}); });
@@ -72,7 +74,7 @@ class _BaseStateWidgetState<T extends BaseViewModel> extends ConsumerState<BaseS
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (widget.onReady != null && !widget.lazyLoad) { if (widget.onReady != null && !widget.lazyLoad) {
widget.onReady!(ref.read<T>(widget.model)); widget.onReady!(ref.read<T>(widget.model));
} }

View File

@@ -9,6 +9,7 @@ import 'package:qinglong_app/module/login/user_bean.dart';
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart'; import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
import 'package:qinglong_app/module/others/login_log/login_log_bean.dart'; import 'package:qinglong_app/module/others/login_log/login_log_bean.dart';
import 'package:qinglong_app/module/others/scripts/script_bean.dart'; import 'package:qinglong_app/module/others/scripts/script_bean.dart';
import 'package:qinglong_app/module/others/subscription/subscription_bean.dart';
import 'package:qinglong_app/module/others/task_log/task_log_bean.dart'; import 'package:qinglong_app/module/others/task_log/task_log_bean.dart';
import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/module/task/task_bean.dart';
import 'package:qinglong_app/utils/utils.dart'; import 'package:qinglong_app/utils/utils.dart';
@@ -353,15 +354,10 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> addDependency(String name, int type) async { static Future<HttpResponse<NullResponse>> addDependency(List<Map<String, dynamic>> list) async {
return await Http.post<NullResponse>( return await Http.post<NullResponse>(
Url.dependencies, Url.dependencies,
[ list,
{
"name": name,
"type": type,
}
],
); );
} }
@@ -382,4 +378,89 @@ class Api {
[id], [id],
); );
} }
// 获取订阅
static Future<HttpResponse<List<Subscription>>> getSubscription()async{
return await Http.get<List<Subscription>>(
Url.subscriptions,
{}
);
}
// 新增订阅
static Future<HttpResponse<Subscription>> postSubscription(Subscription subscription)async{
var data = subscription.toJson();
data.remove("id");
data.remove("status");
data.remove("pid");
data.remove("log_path");
data.remove("is_disabled");
data.remove("createdAt");
data.remove("updatedAt");
data.remove("pullType");
data.remove("pullOption");
return await Http.post<Subscription>(
Url.subscriptions,
data
);
}
// 修改订阅
static Future<HttpResponse<Subscription>> putSubscription(Subscription subscription)async{
return await Http.put<Subscription>(
Url.subscriptions,
subscription.toJson()
);
}
// 删除订阅 参数未一个id数组
static Future<HttpResponse<NullResponse>> deleteSubscription(List<int> ids)async{
return await Http.delete<NullResponse>(
Url.subscriptions,
ids
);
}
// 删除订阅 参数未一个id数组
static Future<HttpResponse<NullResponse>> disableSubscription(List<int> ids)async{
return await Http.put<NullResponse>(
Url.disableSubscriptions,
ids
);
}
// 删除订阅 参数未一个id数组
static Future<HttpResponse<NullResponse>> enableSubscription(List<int> ids)async{
return await Http.put<NullResponse>(
Url.enableSubscriptions,
ids
);
}
// 开始执行订阅
static Future<HttpResponse<NullResponse>> startSubscription(
List<int> subscriptions) async {
return await Http.put<NullResponse>(
Url.runSubscriptions,
subscriptions,
);
}
// 暂停订阅执行
static Future<HttpResponse<NullResponse>> stopSubscription(
List<int> subscriptions) async {
return await Http.put<NullResponse>(
Url.stopSubscriptions,
subscriptions,
);
}
// 获取订阅的日志
static Future<HttpResponse<String>> subTimeLog(int subId) async {
return await Http.get<String>(
Url.subtimeLog(subId),
null,
);
}
} }

View File

@@ -122,7 +122,8 @@ class Http {
if (!pushedLoginPage) { if (!pushedLoginPage) {
"身份已过期,请重新登录".toast(); "身份已过期,请重新登录".toast();
pushedLoginPage = true; pushedLoginPage = true;
navigatorState.currentState?.pushNamedAndRemoveUntil(Routes.routeLogin, (route) => false); navigatorState.currentState
?.pushNamedAndRemoveUntil(Routes.routeLogin, (route) => false);
} }
} }
@@ -136,9 +137,15 @@ class Http {
} }
if (e.response != null && e.response!.data != null) { if (e.response != null && e.response!.data != null) {
return HttpResponse(success: false, message: e.response?.data["message"] ?? e.message, code: e.response?.data["code"] ?? 0); return HttpResponse(
success: false,
message: e.response?.data["message"] ?? e.message,
code: e.response?.data["code"] ?? 0);
} else { } else {
return HttpResponse(success: false, message: e.message, code: e.response?.statusCode ?? 0); return HttpResponse(
success: false,
message: e.message,
code: e.response?.statusCode ?? 0);
} }
} }
@@ -223,7 +230,8 @@ class HttpResponse<T> {
late int code; late int code;
T? bean; T? bean;
HttpResponse({required this.success, this.message, required this.code, this.bean}); HttpResponse(
{required this.success, this.message, required this.code, this.bean});
} }
class DeserializeAction<T> { class DeserializeAction<T> {

View File

@@ -7,8 +7,7 @@ import '../userinfo_viewmodel.dart';
class TokenInterceptor extends Interceptor { class TokenInterceptor extends Interceptor {
@override @override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) { void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
options.headers["User-Agent"] = options.headers["User-Agent"] = "qinglong_client";
"qinglong_client";
options.headers["Content-Type"] = "application/json;charset=UTF-8"; options.headers["Content-Type"] = "application/json;charset=UTF-8";

View File

@@ -14,70 +14,159 @@ class Url {
static const updatePassword = "/api/user"; static const updatePassword = "/api/user";
static get tasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons" : "/api/crons"; static get tasks => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons"
: "/api/crons";
static get runTasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/run" : "/api/crons/run"; static get runTasks => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/run"
: "/api/crons/run";
static get stopTasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/stop" : "/api/crons/stop"; static get stopTasks => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/stop"
: "/api/crons/stop";
static get taskDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/" : "/api/crons/"; static get taskDetail => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/"
: "/api/crons/";
static get addTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons" : "/api/crons"; static get addTask => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons"
: "/api/crons";
static get pinTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/pin" : "/api/crons/pin"; static get pinTask => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/pin"
: "/api/crons/pin";
static get unpinTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/unpin" : "/api/crons/unpin"; static get unpinTask => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/unpin"
: "/api/crons/unpin";
static get enableTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/enable" : "/api/crons/enable"; static get enableTask => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/enable"
: "/api/crons/enable";
static get disableTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/disable" : "/api/crons/disable"; static get disableTask => getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/disable"
: "/api/crons/disable";
static get files => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/files" : "/api/configs/files"; static get files => getIt<UserInfoViewModel>().useSecretLogined
? "/open/configs/files"
: "/api/configs/files";
static get configContent => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/" : "/api/configs/"; static get configContent => getIt<UserInfoViewModel>().useSecretLogined
? "/open/configs/"
: "/api/configs/";
static get saveFile => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/save" : "/api/configs/save"; static get saveFile => getIt<UserInfoViewModel>().useSecretLogined
? "/open/configs/save"
: "/api/configs/save";
static get envs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs"; static get envs =>
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
static get addEnv => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs"; static get addEnv =>
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
static get delEnv => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs"; static get delEnv =>
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
static get disableEnvs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/disable" : "/api/envs/disable"; static get disableEnvs => getIt<UserInfoViewModel>().useSecretLogined
? "/open/envs/disable"
: "/api/envs/disable";
static get enableEnvs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/enable" : "/api/envs/enable"; static get enableEnvs => getIt<UserInfoViewModel>().useSecretLogined
? "/open/envs/enable"
: "/api/envs/enable";
static get loginLog => getIt<UserInfoViewModel>().useSecretLogined ? "/open/user/login-log" : "/api/user/login-log"; static get loginLog => getIt<UserInfoViewModel>().useSecretLogined
? "/open/user/login-log"
: "/api/user/login-log";
static get taskLog => getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs" : "/api/logs"; static get taskLog =>
getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs" : "/api/logs";
static get taskLogDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs/" : "/api/logs/"; static get taskLogDetail => getIt<UserInfoViewModel>().useSecretLogined
? "/open/logs/"
: "/api/logs/";
static get scripts => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts/files" : "/api/scripts/files"; static get scripts => getIt<UserInfoViewModel>().useSecretLogined
? "/open/scripts/files"
: "/api/scripts/files";
static get scripts2 => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts"; static get scripts2 => getIt<UserInfoViewModel>().useSecretLogined
? "/open/scripts"
: "/api/scripts";
static get scriptUpdate => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts"; static get scriptUpdate => getIt<UserInfoViewModel>().useSecretLogined
? "/open/scripts"
: "/api/scripts";
static get scriptDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts/" : "/api/scripts/"; static get scriptDetail => getIt<UserInfoViewModel>().useSecretLogined
? "/open/scripts/"
: "/api/scripts/";
static get dependencies => getIt<UserInfoViewModel>().useSecretLogined ? "/open/dependencies" : "/api/dependencies"; static get dependencies => getIt<UserInfoViewModel>().useSecretLogined
? "/open/dependencies"
: "/api/dependencies";
static get addScript => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts"; static get addScript => getIt<UserInfoViewModel>().useSecretLogined
? "/open/scripts"
: "/api/scripts";
static get dependencyReinstall => getIt<UserInfoViewModel>().useSecretLogined ? "/open/dependencies/reinstall" : "/api/dependencies/reinstall"; static get dependencyReinstall => getIt<UserInfoViewModel>().useSecretLogined
? "/open/dependencies/reinstall"
: "/api/dependencies/reinstall";
static intimeLog(String cronId) { static intimeLog(String cronId) {
return getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/$cronId/log" : "/api/crons/$cronId/log"; return getIt<UserInfoViewModel>().useSecretLogined
? "/open/crons/$cronId/log"
: "/api/crons/$cronId/log";
} }
static envMove(String envId) { static envMove(String envId) {
return getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/$envId/move" : "/api/envs/$envId/move"; return getIt<UserInfoViewModel>().useSecretLogined
? "/open/envs/$envId/move"
: "/api/envs/$envId/move";
}
// 运行订阅
static get runSubscriptions => getIt<UserInfoViewModel>().useSecretLogined
? "/open/subscriptions/run"
: "/api/subscriptions/run";
// 停止订阅
static get stopSubscriptions => getIt<UserInfoViewModel>().useSecretLogined
? "/open/subscriptions/stop"
: "/api/subscriptions/stop";
// 启用订阅
static get enableSubscriptions => getIt<UserInfoViewModel>().useSecretLogined
? "/open/subscriptions/enable"
: "/api/subscriptions/enable";
// 禁用订阅
static get disableSubscriptions => getIt<UserInfoViewModel>().useSecretLogined
? "/open/subscriptions/disable"
: "/api/subscriptions/disable";
// GET 获取订阅 POST 提交订阅 PUT 修改订阅 DELETE 删除订阅
static get subscriptions => getIt<UserInfoViewModel>().useSecretLogined
? "/open/subscriptions"
: "/api/subscriptions";
// 获取订阅日志
static subtimeLog(int cronId) {
return getIt<UserInfoViewModel>().useSecretLogined
? "/open/subscriptions/$cronId/log"
: "/api/subscriptions/$cronId/log";
} }
static bool inWhiteList(String path) { static bool inWhiteList(String path) {
if (path == login || path == loginByClientId || path == loginTwo || path == loginOld) { if (path == login ||
path == loginByClientId ||
path == loginTwo ||
path == loginOld) {
return true; return true;
} }
return false; return false;

View File

@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qinglong_app/module/change_account_page.dart';
import 'package:qinglong_app/module/config/config_edit_page.dart'; import 'package:qinglong_app/module/config/config_edit_page.dart';
import 'package:qinglong_app/module/env/add_env_page.dart'; import 'package:qinglong_app/module/env/add_env_page.dart';
import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/env/env_bean.dart';
@@ -7,12 +8,17 @@ import 'package:qinglong_app/module/env/env_detail_page.dart';
import 'package:qinglong_app/module/home/home_page.dart'; import 'package:qinglong_app/module/home/home_page.dart';
import 'package:qinglong_app/module/login/login_page.dart'; import 'package:qinglong_app/module/login/login_page.dart';
import 'package:qinglong_app/module/others/about_page.dart'; import 'package:qinglong_app/module/others/about_page.dart';
import 'package:qinglong_app/module/others/backup/backup_page.dart';
import 'package:qinglong_app/module/others/dependencies/add_dependency_page.dart'; import 'package:qinglong_app/module/others/dependencies/add_dependency_page.dart';
import 'package:qinglong_app/module/others/dependencies/dependency_page.dart'; import 'package:qinglong_app/module/others/dependencies/dependency_page.dart';
import 'package:qinglong_app/module/others/login_log/login_log_page.dart'; import 'package:qinglong_app/module/others/login_log/login_log_page.dart';
import 'package:qinglong_app/module/others/scripts/script_detail_page.dart'; import 'package:qinglong_app/module/others/scripts/script_detail_page.dart';
import 'package:qinglong_app/module/others/scripts/script_edit_page.dart'; import 'package:qinglong_app/module/others/scripts/script_edit_page.dart';
import 'package:qinglong_app/module/others/scripts/script_page.dart'; import 'package:qinglong_app/module/others/scripts/script_page.dart';
import 'package:qinglong_app/module/others/subscription/subscription_add_page.dart';
import 'package:qinglong_app/module/others/subscription/subscription_bean.dart';
import 'package:qinglong_app/module/others/subscription/subscription_detail_page.dart';
import 'package:qinglong_app/module/others/subscription/subscription_page.dart';
import 'package:qinglong_app/module/others/task_log/task_log_detail_page.dart'; import 'package:qinglong_app/module/others/task_log/task_log_detail_page.dart';
import 'package:qinglong_app/module/others/task_log/task_log_page.dart'; import 'package:qinglong_app/module/others/task_log/task_log_page.dart';
import 'package:qinglong_app/module/others/theme_page.dart'; import 'package:qinglong_app/module/others/theme_page.dart';
@@ -21,6 +27,8 @@ import 'package:qinglong_app/module/task/add_task_page.dart';
import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/module/task/task_bean.dart';
import 'package:qinglong_app/module/task/task_detail/task_detail_page.dart'; import 'package:qinglong_app/module/task/task_detail/task_detail_page.dart';
import '../module/others/scripts/script_add_page.dart';
class Routes { class Routes {
static const String routeHomePage = "/home/homepage"; static const String routeHomePage = "/home/homepage";
static const String routeLogin = "/login"; static const String routeLogin = "/login";
@@ -41,6 +49,13 @@ class Routes {
static const String routeUpdatePassword = "/updatePassword"; static const String routeUpdatePassword = "/updatePassword";
static const String routeAbout = "/about"; static const String routeAbout = "/about";
static const String routeTheme = "/theme"; static const String routeTheme = "/theme";
static const String routeChangeAccount = "/changeAccount";
static const String routerAddScript = "/script/add";
static const String routerSubscription = "/subscription";
static const String routerSubscriptionDetail = "/subscription/detail";
static const String routerSubscriptionAdd = "/subscription/add";
static const String routerBackup = "/backup";
static Route<dynamic>? generateRoute(RouteSettings settings) { static Route<dynamic>? generateRoute(RouteSettings settings) {
switch (settings.name) { switch (settings.name) {
@@ -55,97 +70,130 @@ class Routes {
} else { } else {
return MaterialPageRoute(builder: (context) => const LoginPage()); return MaterialPageRoute(builder: (context) => const LoginPage());
} }
case routeChangeAccount:
return MaterialPageRoute(
builder: (context) => const ChangeAccountPage(),
);
case routeAddTask: case routeAddTask:
if (settings.arguments != null) { if (settings.arguments != null) {
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => AddTaskPage( builder: (context) => AddTaskPage(
taskBean: settings.arguments as TaskBean, taskBean: settings.arguments as TaskBean,
)); ));
} else { } else {
return CupertinoPageRoute(builder: (context) => const AddTaskPage()); return MaterialPageRoute(builder: (context) => const AddTaskPage());
} }
case routeAddDependency: case routeAddDependency:
return CupertinoPageRoute( return MaterialPageRoute(builder: (context) => const AddDependencyPage());
builder: (context) => const AddDependencyPage());
case routeAddEnv: case routeAddEnv:
if (settings.arguments != null) { if (settings.arguments != null) {
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => AddEnvPage( builder: (context) => AddEnvPage(
envBean: settings.arguments as EnvBean, envBean: settings.arguments as EnvBean,
)); ));
} else { } else {
return CupertinoPageRoute(builder: (context) => const AddEnvPage()); return MaterialPageRoute(builder: (context) => const AddEnvPage());
} }
case routeConfigEdit: case routeConfigEdit:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => ConfigEditPage( builder: (context) => ConfigEditPage(
(settings.arguments as Map)["title"], (settings.arguments as Map)["title"],
(settings.arguments as Map)["content"], (settings.arguments as Map)["content"],
), ),
); );
case routeLoginLog: case routeLoginLog:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const LoginLogPage(), builder: (context) => const LoginLogPage(),
); );
case routeTaskLog: case routeTaskLog:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const TaskLogPage(), builder: (context) => const TaskLogPage(),
); );
case routeScript: case routeScript:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const ScriptPage(), builder: (context) => const ScriptPage(),
); );
case routeDependency: case routeDependency:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const DependencyPage(), builder: (context) => const DependencyPage(),
); );
case routeTaskLogDetail: case routeTaskLogDetail:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => TaskLogDetailPage( builder: (context) => TaskLogDetailPage(
title: (settings.arguments as Map)['title'], title: (settings.arguments as Map)['title'],
path: (settings.arguments as Map)['path'], path: (settings.arguments as Map)['path'],
), ),
); );
case routeScriptDetail: case routeScriptDetail:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => ScriptDetailPage( builder: (context) => ScriptDetailPage(
title: (settings.arguments as Map)["title"], title: (settings.arguments as Map)["title"],
path: (settings.arguments as Map)["path"], path: (settings.arguments as Map)["path"],
), ),
); );
case routeTaskDetail: case routeTaskDetail:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => TaskDetailPage( builder: (context) => TaskDetailPage(
settings.arguments as TaskBean, settings.arguments as TaskBean,
), ),
); );
case routeEnvDetail: case routeEnvDetail:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => EnvDetailPage( builder: (context) => EnvDetailPage(
settings.arguments as EnvBean, settings.arguments as EnvBean,
), ),
); );
case routeUpdatePassword: case routeUpdatePassword:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const UpdatePasswordPage(), builder: (context) => const UpdatePasswordPage(),
); );
case routeAbout: case routeAbout:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const AboutPage(), builder: (context) => const AboutPage(),
); );
case routeTheme: case routeTheme:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => const ThemePage(), builder: (context) => const ThemePage(),
); );
case routeScriptUpdate: case routeScriptUpdate:
return CupertinoPageRoute( return MaterialPageRoute(
builder: (context) => ScriptEditPage( builder: (context) => ScriptEditPage(
(settings.arguments as Map)["title"], (settings.arguments as Map)["title"],
(settings.arguments as Map)["path"], (settings.arguments as Map)["path"],
(settings.arguments as Map)["content"], (settings.arguments as Map)["content"],
), ),
); );
case routeScriptAdd:
return MaterialPageRoute(
builder: (context) => ScriptAddPage(
(settings.arguments as Map)["title"],
(settings.arguments as Map)["path"],
),
);
case routerSubscription:
//部分低端手机用Cupertino滑动时掉帧,左侧会出现白色空白
return MaterialPageRoute(
builder: (context) => const SubscriptionPage(),
);
case routerSubscriptionDetail:
return MaterialPageRoute(
builder: (context) => SubscriptionDetailPage(
settings.arguments as Subscription,
),
);
case routerSubscriptionAdd:
if (settings.arguments != null) {
return MaterialPageRoute(
builder: (context) => SubscriptionAddPage(
settings.arguments as Subscription,
));
} else {
return MaterialPageRoute(builder: (context) => const SubscriptionAddPage(null));
}
case routerBackup:
return MaterialPageRoute(
builder: (context) => const BackUpPage(),
);
} }
return null; return null;

View File

@@ -6,3 +6,4 @@ String spTheme = "dart_mode";
String spSecretLogined = "secret_logined"; String spSecretLogined = "secret_logined";
String spCustomColor = "customColor"; String spCustomColor = "customColor";
String spLoginHistory = "loginHistory"; String spLoginHistory = "loginHistory";
String spShowLine = "spShowLine";

View File

@@ -24,7 +24,7 @@ class ThemeViewModel extends ChangeNotifier {
ThemeViewModel() { ThemeViewModel() {
_primaryColor = Color(getIt<UserInfoViewModel>().primaryColor); _primaryColor = Color(getIt<UserInfoViewModel>().primaryColor);
primaryColor = Color(getIt<UserInfoViewModel>().primaryColor); primaryColor = Color(getIt<UserInfoViewModel>().primaryColor);
var brightness = SchedulerBinding.instance!.window.platformBrightness; var brightness = SchedulerBinding.instance.window.platformBrightness;
_isInDarkMode = brightness == Brightness.dark; _isInDarkMode = brightness == Brightness.dark;
changeThemeReal(_isInDarkMode, false); changeThemeReal(_isInDarkMode, false);
} }
@@ -69,7 +69,7 @@ class ThemeViewModel extends ChangeNotifier {
secondary: _primaryColor, secondary: _primaryColor,
primary: _primaryColor, primary: _primaryColor,
), ),
scaffoldBackgroundColor: const Color(0xfff5f5f5), scaffoldBackgroundColor: const Color(0xffffffff),
inputDecorationTheme: InputDecorationTheme( inputDecorationTheme: InputDecorationTheme(
labelStyle: TextStyle( labelStyle: TextStyle(
color: _primaryColor, color: _primaryColor,
@@ -223,6 +223,8 @@ abstract class ThemeColors {
Color tabBarColor(); Color tabBarColor();
Color blackAndWhite();
Color pinColor(); Color pinColor();
Color buttonBgColor(); Color buttonBgColor();
@@ -241,6 +243,11 @@ class LightThemeColors extends ThemeColors {
return const Color(0xffF7F7F7); return const Color(0xffF7F7F7);
} }
@override
Color blackAndWhite() {
return Colors.white;
}
@override @override
Map<String, TextStyle> codeEditorTheme() { Map<String, TextStyle> codeEditorTheme() {
return qinglongLightTheme; return qinglongLightTheme;
@@ -288,6 +295,11 @@ class DartThemeColors extends ThemeColors {
return qinglongDarkTheme; return qinglongDarkTheme;
} }
@override
Color blackAndWhite() {
return Colors.black;
}
@override @override
Color descColor() { Color descColor() {
return const Color(0xff999999); return const Color(0xff999999);

View File

@@ -6,7 +6,7 @@ mixin LazyLoadState<T extends StatefulWidget> on State<T> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
var route = ModalRoute.of(context); var route = ModalRoute.of(context);
void handler(status) { void handler(status) {
if (status == AnimationStatus.completed) { if (status == AnimationStatus.completed) {

View File

@@ -5,7 +5,8 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/gestures.dart' show kMinFlingVelocity, kLongPressTimeout; import 'package:flutter/gestures.dart'
show kMinFlingVelocity, kLongPressTimeout;
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
@@ -42,7 +43,8 @@ typedef _ContextMenuPreviewBuilderChildless = Widget Function(
// paintBounds in global coordinates. // paintBounds in global coordinates.
Rect _getRect(GlobalKey globalKey) { Rect _getRect(GlobalKey globalKey) {
assert(globalKey.currentContext != null); assert(globalKey.currentContext != null);
final RenderBox renderBoxContainer = globalKey.currentContext!.findRenderObject()! as RenderBox; final RenderBox renderBoxContainer =
globalKey.currentContext!.findRenderObject()! as RenderBox;
final Offset containerOffset = renderBoxContainer.localToGlobal( final Offset containerOffset = renderBoxContainer.localToGlobal(
renderBoxContainer.paintBounds.topLeft, renderBoxContainer.paintBounds.topLeft,
); );
@@ -87,7 +89,7 @@ enum _ContextMenuLocation {
/// See also: /// See also:
/// ///
/// * [Apple's HIG for Context Menus](https://developer.apple.com/design/human-interface-guidelines/ios/controls/context-menus/) /// * [Apple's HIG for Context Menus](https://developer.apple.com/design/human-interface-guidelines/ios/controls/context-menus/)
class QlCupertinoContextMenu extends StatefulWidget { class QlCupertinoContextMenu<T> extends StatefulWidget {
/// Create a context menu. /// Create a context menu.
/// ///
/// [actions] is required and cannot be null or empty. /// [actions] is required and cannot be null or empty.
@@ -103,7 +105,7 @@ class QlCupertinoContextMenu extends StatefulWidget {
assert(child != null), assert(child != null),
super(key: key); super(key: key);
final TaskBean bean; final T bean;
/// The widget that can be "opened" with the [QlCupertinoContextMenu]. /// The widget that can be "opened" with the [QlCupertinoContextMenu].
/// ///
@@ -194,7 +196,8 @@ class QlCupertinoContextMenu extends StatefulWidget {
State<QlCupertinoContextMenu> createState() => _QlCupertinoContextMenuState(); State<QlCupertinoContextMenu> createState() => _QlCupertinoContextMenuState();
} }
class _QlCupertinoContextMenuState extends State<QlCupertinoContextMenu> with TickerProviderStateMixin { class _QlCupertinoContextMenuState extends State<QlCupertinoContextMenu>
with TickerProviderStateMixin {
final GlobalKey _childGlobalKey = GlobalKey(); final GlobalKey _childGlobalKey = GlobalKey();
bool _childHidden = false; bool _childHidden = false;
@@ -227,7 +230,8 @@ class _QlCupertinoContextMenuState extends State<QlCupertinoContextMenu> with Ti
final double screenWidth = MediaQuery.of(context).size.width; final double screenWidth = MediaQuery.of(context).size.width;
final double center = screenWidth / 2; final double center = screenWidth / 2;
final bool centerDividesChild = childRect.left < center && childRect.right > center; final bool centerDividesChild =
childRect.left < center && childRect.right > center;
final double distanceFromCenter = (center - childRect.center.dx).abs(); final double distanceFromCenter = (center - childRect.center.dx).abs();
if (centerDividesChild && distanceFromCenter <= childRect.width / 4) { if (centerDividesChild && distanceFromCenter <= childRect.width / 4) {
return _ContextMenuLocation.center; return _ContextMenuLocation.center;
@@ -318,7 +322,14 @@ class _QlCupertinoContextMenuState extends State<QlCupertinoContextMenu> with Ti
_openController.reverse(); _openController.reverse();
} else { } else {
if (_openController.isDismissed) { if (_openController.isDismissed) {
Navigator.of(context).pushNamed(Routes.routeTaskDetail, arguments: widget.bean); if (widget.bean is TaskBean){
Navigator.of(context)
.pushNamed(Routes.routeTaskDetail, arguments: widget.bean);
}else{
Navigator.of(context)
.pushNamed(Routes.routerSubscriptionDetail, arguments: widget.bean);
}
} }
} }
} }
@@ -419,7 +430,8 @@ class _DecoyChild extends StatefulWidget {
_DecoyChildState createState() => _DecoyChildState(); _DecoyChildState createState() => _DecoyChildState();
} }
class _DecoyChildState extends State<_DecoyChild> with TickerProviderStateMixin { class _DecoyChildState extends State<_DecoyChild>
with TickerProviderStateMixin {
// TODO(justinmc): Dark mode support. // TODO(justinmc): Dark mode support.
// See https://github.com/flutter/flutter/issues/43211. // See https://github.com/flutter/flutter/issues/43211.
static const Color _lightModeMaskColor = Color(0xFF888888); static const Color _lightModeMaskColor = Color(0xFF888888);
@@ -481,7 +493,9 @@ class _DecoyChildState extends State<_DecoyChild> with TickerProviderStateMixin
} }
Widget _buildAnimation(BuildContext context, Widget? child) { Widget _buildAnimation(BuildContext context, Widget? child) {
final Color color = widget.controller.status == AnimationStatus.reverse ? _masklessColor : _mask.value; final Color color = widget.controller.status == AnimationStatus.reverse
? _masklessColor
: _mask.value;
return Positioned.fromRect( return Positioned.fromRect(
rect: _rect.value!, rect: _rect.value!,
child: ShaderMask( child: ShaderMask(
@@ -538,7 +552,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
// The duration of the transition used when a modal popup is shown. Eyeballed // The duration of the transition used when a modal popup is shown. Eyeballed
// from a physical device running iOS 13.1.2. // from a physical device running iOS 13.1.2.
static const Duration _kModalPopupTransitionDuration = Duration(milliseconds: 335); static const Duration _kModalPopupTransitionDuration =
Duration(milliseconds: 335);
final List<Widget> _actions; final List<Widget> _actions;
final _ContextMenuPreviewBuilderChildless? _builder; final _ContextMenuPreviewBuilderChildless? _builder;
@@ -562,7 +577,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
static final RectTween _rectTween = RectTween(); static final RectTween _rectTween = RectTween();
static final Animatable<Rect?> _rectAnimatable = _rectTween.chain(_curve); static final Animatable<Rect?> _rectAnimatable = _rectTween.chain(_curve);
static final RectTween _rectTweenReverse = RectTween(); static final RectTween _rectTweenReverse = RectTween();
static final Animatable<Rect?> _rectAnimatableReverse = _rectTweenReverse.chain( static final Animatable<Rect?> _rectAnimatableReverse =
_rectTweenReverse.chain(
_curveReverse, _curveReverse,
); );
static final RectTween _sheetRectTween = RectTween(); static final RectTween _sheetRectTween = RectTween();
@@ -573,10 +589,12 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
_curveReverse, _curveReverse,
); );
static final Tween<double> _sheetScaleTween = Tween<double>(); static final Tween<double> _sheetScaleTween = Tween<double>();
static final Animatable<double> _sheetScaleAnimatable = _sheetScaleTween.chain( static final Animatable<double> _sheetScaleAnimatable =
_sheetScaleTween.chain(
_curve, _curve,
); );
static final Animatable<double> _sheetScaleAnimatableReverse = _sheetScaleTween.chain( static final Animatable<double> _sheetScaleAnimatableReverse =
_sheetScaleTween.chain(
_curveReverse, _curveReverse,
); );
final Tween<double> _opacityTween = Tween<double>(begin: 0.0, end: 1.0); final Tween<double> _opacityTween = Tween<double>(begin: 0.0, end: 1.0);
@@ -611,7 +629,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
// Get the alignment for the _ContextMenuSheet's Transform.scale based on the // Get the alignment for the _ContextMenuSheet's Transform.scale based on the
// contextMenuLocation. // contextMenuLocation.
static AlignmentDirectional getSheetAlignment(_ContextMenuLocation contextMenuLocation) { static AlignmentDirectional getSheetAlignment(
_ContextMenuLocation contextMenuLocation) {
switch (contextMenuLocation) { switch (contextMenuLocation) {
case _ContextMenuLocation.center: case _ContextMenuLocation.center:
return AlignmentDirectional.topCenter; return AlignmentDirectional.topCenter;
@@ -623,17 +642,27 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
} }
// The place to start the sheetRect animation from. // The place to start the sheetRect animation from.
static Rect _getSheetRectBegin(Orientation? orientation, _ContextMenuLocation contextMenuLocation, Rect childRect, Rect sheetRect) { static Rect _getSheetRectBegin(
Orientation? orientation,
_ContextMenuLocation contextMenuLocation,
Rect childRect,
Rect sheetRect) {
switch (contextMenuLocation) { switch (contextMenuLocation) {
case _ContextMenuLocation.center: case _ContextMenuLocation.center:
final Offset target = orientation == Orientation.portrait ? childRect.bottomCenter : childRect.topCenter; final Offset target = orientation == Orientation.portrait
? childRect.bottomCenter
: childRect.topCenter;
final Offset centered = target - Offset(sheetRect.width / 2, 0.0); final Offset centered = target - Offset(sheetRect.width / 2, 0.0);
return centered & sheetRect.size; return centered & sheetRect.size;
case _ContextMenuLocation.right: case _ContextMenuLocation.right:
final Offset target = orientation == Orientation.portrait ? childRect.bottomRight : childRect.topRight; final Offset target = orientation == Orientation.portrait
? childRect.bottomRight
: childRect.topRight;
return (target - Offset(sheetRect.width, 0.0)) & sheetRect.size; return (target - Offset(sheetRect.width, 0.0)) & sheetRect.size;
case _ContextMenuLocation.left: case _ContextMenuLocation.left:
final Offset target = orientation == Orientation.portrait ? childRect.bottomLeft : childRect.topLeft; final Offset target = orientation == Orientation.portrait
? childRect.bottomLeft
: childRect.topLeft;
return target & sheetRect.size; return target & sheetRect.size;
} }
} }
@@ -651,7 +680,9 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
// Take measurements on the child and _ContextMenuSheet and update the // Take measurements on the child and _ContextMenuSheet and update the
// animation tweens to match. // animation tweens to match.
void _updateTweenRects() { void _updateTweenRects() {
final Rect childRect = _scale == null ? _getRect(_childGlobalKey) : _getScaledRect(_childGlobalKey, _scale!); final Rect childRect = _scale == null
? _getRect(_childGlobalKey)
: _getScaledRect(_childGlobalKey, _scale!);
_rectTween.begin = _previousChildRect; _rectTween.begin = _previousChildRect;
_rectTween.end = childRect; _rectTween.end = childRect;
@@ -725,7 +756,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
} }
@override @override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
// This is usually used to build the "page", which is then passed to // This is usually used to build the "page", which is then passed to
// buildTransitions as child, the idea being that buildTransitions will // buildTransitions as child, the idea being that buildTransitions will
// animate the entire page into the scene. In the case of _ContextMenuRoute, // animate the entire page into the scene. In the case of _ContextMenuRoute,
@@ -735,7 +767,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
} }
@override @override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return OrientationBuilder( return OrientationBuilder(
builder: (BuildContext context, Orientation orientation) { builder: (BuildContext context, Orientation orientation) {
_lastOrientation = orientation; _lastOrientation = orientation;
@@ -744,9 +777,15 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
// they're movable. // they're movable.
if (!animation.isCompleted) { if (!animation.isCompleted) {
final bool reverse = animation.status == AnimationStatus.reverse; final bool reverse = animation.status == AnimationStatus.reverse;
final Rect rect = reverse ? _rectAnimatableReverse.evaluate(animation)! : _rectAnimatable.evaluate(animation)!; final Rect rect = reverse
final Rect sheetRect = reverse ? _sheetRectAnimatableReverse.evaluate(animation)! : _sheetRectAnimatable.evaluate(animation)!; ? _rectAnimatableReverse.evaluate(animation)!
final double sheetScale = reverse ? _sheetScaleAnimatableReverse.evaluate(animation) : _sheetScaleAnimatable.evaluate(animation); : _rectAnimatable.evaluate(animation)!;
final Rect sheetRect = reverse
? _sheetRectAnimatableReverse.evaluate(animation)!
: _sheetRectAnimatable.evaluate(animation)!;
final double sheetScale = reverse
? _sheetScaleAnimatableReverse.evaluate(animation)
: _sheetScaleAnimatable.evaluate(animation);
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
Positioned.fromRect( Positioned.fromRect(
@@ -818,7 +857,8 @@ class _ContextMenuRouteStatic extends StatefulWidget {
_ContextMenuRouteStaticState createState() => _ContextMenuRouteStaticState(); _ContextMenuRouteStaticState createState() => _ContextMenuRouteStaticState();
} }
class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with TickerProviderStateMixin { class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic>
with TickerProviderStateMixin {
// The child is scaled down as it is dragged down until it hits this minimum // The child is scaled down as it is dragged down until it hits this minimum
// value. // value.
static const double _kMinScale = 0.8; static const double _kMinScale = 0.8;
@@ -838,7 +878,8 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
late Animation<double> _sheetOpacityAnimation; late Animation<double> _sheetOpacityAnimation;
// The scale of the child changes as a function of the distance it is dragged. // The scale of the child changes as a function of the distance it is dragged.
static double _getScale(Orientation orientation, double maxDragDistance, double dy) { static double _getScale(
Orientation orientation, double maxDragDistance, double dy) {
final double dyDirectional = dy <= 0.0 ? dy : -dy; final double dyDirectional = dy <= 0.0 ? dy : -dy;
return math.max( return math.max(
_kMinScale, _kMinScale,
@@ -859,11 +900,13 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
// If flung, animate a bit before handling the potential dismiss. // If flung, animate a bit before handling the potential dismiss.
if (details.velocity.pixelsPerSecond.dy.abs() >= kMinFlingVelocity) { if (details.velocity.pixelsPerSecond.dy.abs() >= kMinFlingVelocity) {
final bool flingIsAway = details.velocity.pixelsPerSecond.dy > 0; final bool flingIsAway = details.velocity.pixelsPerSecond.dy > 0;
final double finalPosition = flingIsAway ? _moveAnimation.value.dy + 100.0 : 0.0; final double finalPosition =
flingIsAway ? _moveAnimation.value.dy + 100.0 : 0.0;
if (flingIsAway && _sheetController.status != AnimationStatus.forward) { if (flingIsAway && _sheetController.status != AnimationStatus.forward) {
_sheetController.forward(); _sheetController.forward();
} else if (!flingIsAway && _sheetController.status != AnimationStatus.reverse) { } else if (!flingIsAway &&
_sheetController.status != AnimationStatus.reverse) {
_sheetController.reverse(); _sheetController.reverse();
} }
@@ -918,21 +961,30 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
widget.onDismiss!(context, _lastScale, _sheetOpacityAnimation.value); widget.onDismiss!(context, _lastScale, _sheetOpacityAnimation.value);
} }
Alignment _getChildAlignment(Orientation orientation, _ContextMenuLocation contextMenuLocation) { Alignment _getChildAlignment(
Orientation orientation, _ContextMenuLocation contextMenuLocation) {
switch (contextMenuLocation) { switch (contextMenuLocation) {
case _ContextMenuLocation.center: case _ContextMenuLocation.center:
return orientation == Orientation.portrait ? Alignment.bottomCenter : Alignment.topRight; return orientation == Orientation.portrait
? Alignment.bottomCenter
: Alignment.topRight;
case _ContextMenuLocation.right: case _ContextMenuLocation.right:
return orientation == Orientation.portrait ? Alignment.bottomCenter : Alignment.topLeft; return orientation == Orientation.portrait
? Alignment.bottomCenter
: Alignment.topLeft;
case _ContextMenuLocation.left: case _ContextMenuLocation.left:
return orientation == Orientation.portrait ? Alignment.bottomCenter : Alignment.topRight; return orientation == Orientation.portrait
? Alignment.bottomCenter
: Alignment.topRight;
} }
} }
void _setDragOffset(Offset dragOffset) { void _setDragOffset(Offset dragOffset) {
// Allow horizontal and negative vertical movement, but damp it. // Allow horizontal and negative vertical movement, but damp it.
final double endX = _kPadding * dragOffset.dx / _kDamping; final double endX = _kPadding * dragOffset.dx / _kDamping;
final double endY = dragOffset.dy >= 0.0 ? dragOffset.dy : _kPadding * dragOffset.dy / _kDamping; final double endY = dragOffset.dy >= 0.0
? dragOffset.dy
: _kPadding * dragOffset.dy / _kDamping;
setState(() { setState(() {
_dragOffset = dragOffset; _dragOffset = dragOffset;
_moveAnimation = Tween<Offset>( _moveAnimation = Tween<Offset>(
@@ -949,9 +1001,13 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
); );
// Fade the _ContextMenuSheet out or in, if needed. // Fade the _ContextMenuSheet out or in, if needed.
if (_lastScale <= _kSheetScaleThreshold && _sheetController.status != AnimationStatus.forward && _sheetScaleAnimation.value != 0.0) { if (_lastScale <= _kSheetScaleThreshold &&
_sheetController.status != AnimationStatus.forward &&
_sheetScaleAnimation.value != 0.0) {
_sheetController.forward(); _sheetController.forward();
} else if (_lastScale > _kSheetScaleThreshold && _sheetController.status != AnimationStatus.reverse && _sheetScaleAnimation.value != 1.0) { } else if (_lastScale > _kSheetScaleThreshold &&
_sheetController.status != AnimationStatus.reverse &&
_sheetScaleAnimation.value != 1.0) {
_sheetController.reverse(); _sheetController.reverse();
} }
}); });
@@ -960,7 +1016,8 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
// The order and alignment of the _ContextMenuSheet and the child depend on // The order and alignment of the _ContextMenuSheet and the child depend on
// both the orientation of the screen as well as the position on the screen of // both the orientation of the screen as well as the position on the screen of
// the original child. // the original child.
List<Widget> _getChildren(Orientation orientation, _ContextMenuLocation contextMenuLocation) { List<Widget> _getChildren(
Orientation orientation, _ContextMenuLocation contextMenuLocation) {
final Expanded child = Expanded( final Expanded child = Expanded(
child: Align( child: Align(
alignment: _getChildAlignment( alignment: _getChildAlignment(
@@ -995,7 +1052,9 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
case _ContextMenuLocation.center: case _ContextMenuLocation.center:
return <Widget>[child, spacer, sheet]; return <Widget>[child, spacer, sheet];
case _ContextMenuLocation.right: case _ContextMenuLocation.right:
return orientation == Orientation.portrait ? <Widget>[child, spacer, sheet] : <Widget>[sheet, spacer, child]; return orientation == Orientation.portrait
? <Widget>[child, spacer, sheet]
: <Widget>[sheet, spacer, child];
case _ContextMenuLocation.left: case _ContextMenuLocation.left:
return <Widget>[child, spacer, sheet]; return <Widget>[child, spacer, sheet];
} }
@@ -1004,7 +1063,8 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
// Build the animation for the _ContextMenuSheet. // Build the animation for the _ContextMenuSheet.
Widget _buildSheetAnimation(BuildContext context, Widget? child) { Widget _buildSheetAnimation(BuildContext context, Widget? child) {
return Transform.scale( return Transform.scale(
alignment: _ContextMenuRoute.getSheetAlignment(widget.contextMenuLocation), alignment:
_ContextMenuRoute.getSheetAlignment(widget.contextMenuLocation),
scale: _sheetScaleAnimation.value, scale: _sheetScaleAnimation.value,
child: FadeTransition( child: FadeTransition(
opacity: _sheetOpacityAnimation, opacity: _sheetOpacityAnimation,

View File

@@ -0,0 +1,66 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../theme.dart';
class SearchCell extends ConsumerStatefulWidget {
final TextEditingController controller;
const SearchCell({
Key? key,
required this.controller,
}) : super(key: key);
@override
ConsumerState createState() => _SearchCellState();
}
class _SearchCellState extends ConsumerState<SearchCell> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return CupertinoSearchTextField(
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.blackAndWhite(),
border: Border.all(width: 1, color: const Color(0xffC0C4CC)),
borderRadius: BorderRadius.circular(
7,
),
),
onSuffixTap: () {
widget.controller.text = "";
setState(() {});
},
controller: widget.controller,
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 5,
),
suffixInsets: const EdgeInsets.only(
right: 15,
),
prefixIcon: Image.asset(
"assets/images/icon_search.png",
width: 18,
fit: BoxFit.cover,
),
prefixInsets: const EdgeInsets.only(
left: 10,
top: 2,
),
placeholderStyle: TextStyle(
fontSize: 14,
color: ref.watch(themeProvider).themeColor.descColor(),
),
style: const TextStyle(
fontSize: 16,
),
placeholder: "请输入内容",
);
}
}

View File

@@ -29,9 +29,8 @@ class SourceCodeView extends StatefulWidget {
this.syntaxHighlighterStyle, this.syntaxHighlighterStyle,
}) : super(key: key); }) : super(key: key);
String? get codeLink => codeLinkPrefix == null String? get codeLink =>
? null codeLinkPrefix == null ? null : '$codeLinkPrefix/$filePath';
: '$codeLinkPrefix/$filePath';
@override @override
_SourceCodeViewState createState() { _SourceCodeViewState createState() {

View File

@@ -17,7 +17,10 @@ class SyntaxHighlighterStyle {
this.constantStyle}); this.constantStyle});
static SyntaxHighlighterStyle lightThemeStyle() => SyntaxHighlighterStyle( static SyntaxHighlighterStyle lightThemeStyle() => SyntaxHighlighterStyle(
baseStyle: const TextStyle(color: const Color(0xFF000000),height: 1,), baseStyle: const TextStyle(
color: const Color(0xFF000000),
height: 1,
),
numberStyle: const TextStyle(color: const Color(0xFF1565C0)), numberStyle: const TextStyle(color: const Color(0xFF1565C0)),
commentStyle: const TextStyle(color: const Color(0xFF9E9E9E)), commentStyle: const TextStyle(color: const Color(0xFF9E9E9E)),
keywordStyle: const TextStyle(color: const Color(0xFF9C27B0)), keywordStyle: const TextStyle(color: const Color(0xFF9C27B0)),

View File

@@ -26,7 +26,8 @@ class UserInfoViewModel {
_useSecertLogined = SpUtil.getBool(spSecretLogined, defValue: false); _useSecertLogined = SpUtil.getBool(spSecretLogined, defValue: false);
_host = SpUtil.getString(spHost, defValue: ''); _host = SpUtil.getString(spHost, defValue: '');
List<dynamic>? tempList = jsonDecode(SpUtil.getString(spLoginHistory, defValue: '[]')); List<dynamic>? tempList =
jsonDecode(SpUtil.getString(spLoginHistory, defValue: '[]'));
if (tempList != null && tempList.isNotEmpty) { if (tempList != null && tempList.isNotEmpty) {
for (Map<String, dynamic> value in tempList) { for (Map<String, dynamic> value in tempList) {
@@ -40,7 +41,8 @@ class UserInfoViewModel {
SpUtil.putString(spUserInfo, token); SpUtil.putString(spUserInfo, token);
} }
void updateUserName(String host, String userName, String password, bool secretLogin) { void updateUserName(
String host, String userName, String password, bool secretLogin) {
updateHost(host); updateHost(host);
_useSecretLogin(secretLogin); _useSecretLogin(secretLogin);
_userName = userName; _userName = userName;
@@ -93,7 +95,13 @@ class UserInfoViewModel {
historyAccounts.removeWhere((element) => element.host == _host); historyAccounts.removeWhere((element) => element.host == _host);
historyAccounts.insert(0, UserInfoBean(userName: _userName, password: _passWord, useSecretLogined: _useSecertLogined, host: _host)); historyAccounts.insert(
0,
UserInfoBean(
userName: _userName,
password: _passWord,
useSecretLogined: _useSecertLogined,
host: _host));
while (historyAccounts.length > 3) { while (historyAccounts.length > 3) {
historyAccounts.removeLast(); historyAccounts.removeLast();
@@ -117,7 +125,8 @@ class UserInfoBean {
bool useSecretLogined = false; bool useSecretLogined = false;
String? host; String? host;
UserInfoBean({this.userName, this.password, this.useSecretLogined = false, this.host}); UserInfoBean(
{this.userName, this.password, this.useSecretLogined = false, this.host});
UserInfoBean.fromJson(Map<String, dynamic> json) { UserInfoBean.fromJson(Map<String, dynamic> json) {
userName = json['userName']; userName = json['userName'];

View File

@@ -8,6 +8,7 @@ import 'package:qinglong_app/module/login/user_bean.dart';
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart'; import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
import 'package:qinglong_app/module/others/login_log/login_log_bean.dart'; import 'package:qinglong_app/module/others/login_log/login_log_bean.dart';
import 'package:qinglong_app/module/others/scripts/script_bean.dart'; import 'package:qinglong_app/module/others/scripts/script_bean.dart';
import 'package:qinglong_app/module/others/subscription/subscription_bean.dart';
import 'package:qinglong_app/module/others/task_log/task_log_bean.dart'; import 'package:qinglong_app/module/others/task_log/task_log_bean.dart';
import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/module/task/task_bean.dart';
@@ -66,6 +67,10 @@ class JsonConversion$Json {
return TaskBean.jsonConversion(json) as M; return TaskBean.jsonConversion(json) as M;
} }
if (type == (Subscription).toString()){
return Subscription.fromJson(json) as M;
}
throw Exception("not found"); throw Exception("not found");
} }
@@ -110,6 +115,10 @@ class JsonConversion$Json {
return data.map<TaskBean>((e) => TaskBean.jsonConversion(e)).toList() as M; return data.map<TaskBean>((e) => TaskBean.jsonConversion(e)).toList() as M;
} }
if (<Subscription>[] is M){
return data.map<Subscription>((e) => Subscription.jsonConversion(e)).toList() as M;
}
throw Exception("not found"); throw Exception("not found");
} }
} }

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:dio_log/overlay_draggable_button.dart'; import 'package:dio_log/overlay_draggable_button.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
@@ -11,6 +12,7 @@ import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/module/login/login_page.dart'; import 'package:qinglong_app/module/login/login_page.dart';
import 'package:qinglong_app/utils/sp_utils.dart'; import 'package:qinglong_app/utils/sp_utils.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'base/routes.dart'; import 'base/routes.dart';
import 'base/userinfo_viewmodel.dart'; import 'base/userinfo_viewmodel.dart';
@@ -54,6 +56,29 @@ class QlApp extends ConsumerStatefulWidget {
} }
class QlAppState extends ConsumerState<QlApp> { class QlAppState extends ConsumerState<QlApp> {
List<DisplayMode> modes = <DisplayMode>[];
DisplayMode? active;
DisplayMode? preferred;
@override
void initState() {
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) {
fetchAll();
});
}
Future<void> fetchAll() async {
try {
modes = await FlutterDisplayMode.supported;
modes.forEach(print);
await FlutterDisplayMode.setHighRefreshRate();
} on PlatformException catch (e) {
print(e);
}
setState(() {});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
@@ -61,37 +86,32 @@ class QlAppState extends ConsumerState<QlApp> {
onTap: () { onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
}, },
child: MediaQuery( child: MaterialApp(
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith( title: "青龙",
textScaleFactor: 1, locale: const Locale('zh', 'CN'),
), navigatorKey: navigatorState,
child: MaterialApp( localizationsDelegates: const [
title: "青龙", GlobalMaterialLocalizations.delegate,
locale: const Locale('zh', 'CN'), GlobalWidgetsLocalizations.delegate,
navigatorKey: navigatorState, GlobalCupertinoLocalizations.delegate,
localizationsDelegates: const [ ],
GlobalMaterialLocalizations.delegate, supportedLocales: const [
GlobalWidgetsLocalizations.delegate, Locale('zh', 'CN'),
GlobalCupertinoLocalizations.delegate, Locale('en', 'US'),
], ],
supportedLocales: const [ theme: ref.watch<ThemeViewModel>(themeProvider).currentTheme,
Locale('zh', 'CN'), onGenerateRoute: (setting) {
Locale('en', 'US'), return Routes.generateRoute(setting);
], },
theme: ref.watch<ThemeViewModel>(themeProvider).currentTheme, home: Builder(
onGenerateRoute: (setting) { builder: (context) {
return Routes.generateRoute(setting); if (!kReleaseMode) {
showDebugBtn(context);
}
return getIt<UserInfoViewModel>().isLogined() ? const HomePage() : const LoginPage();
}, },
home: Builder(
builder: (context) {
if (!kReleaseMode) {
showDebugBtn(context);
}
return getIt<UserInfoViewModel>().isLogined() ? const HomePage() : const LoginPage();
},
),
// home: LoginPage(),
), ),
// home: LoginPage(),
), ),
); );
} }

View File

@@ -0,0 +1,326 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
import 'package:qinglong_app/utils/extension.dart';
import 'package:qinglong_app/utils/login_helper.dart';
import '../../main.dart';
class ChangeAccountPage extends ConsumerStatefulWidget {
const ChangeAccountPage({Key? key}) : super(key: key);
@override
_ChangeAccountPageState createState() => _ChangeAccountPageState();
}
class _ChangeAccountPageState extends ConsumerState<ChangeAccountPage> {
String isLoginingHost = "";
String preHost = "";
@override
void initState() {
super.initState();
preHost = getIt<UserInfoViewModel>().historyAccounts.first.host ?? "";
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: QlAppBar(
canBack: true,
title: "切换账号",
),
body: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: MediaQuery.of(context).size.height / 10,
),
Text(
"轻触账号以切换登录",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 22,
),
),
const SizedBox(
height: 30,
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15,
),
child: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
if (index ==
getIt<UserInfoViewModel>().historyAccounts.length) {
return addAccount();
}
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: ref
.watch(themeProvider)
.themeColor
.settingBordorColor(),
child: buildCell(index),
),
);
},
separatorBuilder: (_, __) {
return const SizedBox(
height: 10,
);
},
itemCount:
getIt<UserInfoViewModel>().historyAccounts.length + 1),
),
],
),
),
),
);
}
Widget buildCell(int index) {
Widget child = ListTile(
title: Text(
getIt<UserInfoViewModel>().historyAccounts[index].host ?? "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 15,
),
minVerticalPadding: 10,
subtitle: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
getIt<UserInfoViewModel>().historyAccounts[index].userName ?? "",
),
),
trailing: index == 0
? Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(
color: ref.watch(themeProvider).primaryColor, width: 1),
),
child: Text(
"已登录",
style: TextStyle(
color: ref.watch(themeProvider).primaryColor, fontSize: 12),
),
)
: (isLoginingHost.isNotEmpty
? SizedBox(
width: 15,
height: 15,
child: CircularProgressIndicator(
strokeWidth: 2,
color: ref.watch(themeProvider).primaryColor,
),
)
: const SizedBox.shrink()),
);
if (getIt<UserInfoViewModel>().historyAccounts[index].host ==
getIt<UserInfoViewModel>().host) {
return child;
}
return Slidable(
key: ValueKey(index),
endActionPane: ActionPane(
motion: const ScrollMotion(),
extentRatio: 0.15,
children: [
SlidableAction(
backgroundColor: Colors.red,
flex: 1,
onPressed: (_) {
getIt<UserInfoViewModel>().removeHistoryAccount(
getIt<UserInfoViewModel>().historyAccounts[index].host);
setState(() {});
},
foregroundColor: Colors.white,
icon: CupertinoIcons.delete,
),
],
),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
loginNewByBean(getIt<UserInfoViewModel>().historyAccounts[index]);
},
child: child),
);
}
LoginHelper? helper;
void loginNewByBean(UserInfoBean historyAccount) async {
isLoginingHost = historyAccount.host ?? "";
setState(() {});
helper = LoginHelper(
historyAccount.useSecretLogined,
historyAccount.host ?? "",
historyAccount.userName ?? "",
historyAccount.password ?? "",
true,
);
var response = await helper!.login();
dealLoginResponse(response);
}
void dealLoginResponse(int response) {
if (response == LoginHelper.success) {
Navigator.of(context)
.pushNamedAndRemoveUntil(Routes.routeHomePage, (_) => false);
} else if (response == LoginHelper.failed) {
loginFailed();
} else {
twoFact();
}
}
void loginFailed() {
isLoginingHost = "";
Http.clear();
getIt<UserInfoViewModel>().updateHost(preHost);
setState(() {});
}
void twoFact() {
String twoFact = "";
showCupertinoDialog(
context: context,
builder: (_) => CupertinoAlertDialog(
title: const Text("两步验证"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Material(
color: Colors.transparent,
child: TextField(
onChanged: (value) {
twoFact = value;
},
maxLines: 1,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入code",
),
autofocus: true,
),
),
],
),
actions: [
CupertinoDialogAction(
child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text(
"确定",
style: TextStyle(
color: ref.watch(themeProvider).primaryColor,
),
),
onPressed: () async {
Navigator.of(context).pop(true);
if (helper != null) {
var response = await helper!.loginTwice(twoFact);
dealLoginResponse(response);
} else {
"状态异常".toast();
}
},
),
],
)).then((value) {
if (value == null) {
isLoginingHost = "";
setState(() {});
}
});
}
Widget addAccount() {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamedAndRemoveUntil(
Routes.routeLogin,
(_) => false,
arguments: true,
);
},
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 15,
),
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.settingBordorColor(),
borderRadius: BorderRadius.circular(15),
),
child: Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(
color: ref.watch(themeProvider).themeColor.descColor(),
),
),
child: Icon(
CupertinoIcons.add,
color: ref.watch(themeProvider).themeColor.descColor(),
),
),
const SizedBox(
width: 15,
),
Text(
"添加账号",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 16,
),
),
],
),
),
),
);
}
}

View File

@@ -1,12 +1,16 @@
import 'package:code_text_field/code_text_field.dart'; import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:highlight/languages/powershell.dart'; import 'package:highlight/languages/powershell.dart';
import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/ql_app_bar.dart'; import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/base/sp_const.dart';
import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/utils/extension.dart'; import 'package:qinglong_app/utils/extension.dart';
import 'package:qinglong_app/utils/sp_utils.dart';
class ConfigEditPage extends ConsumerStatefulWidget { class ConfigEditPage extends ConsumerStatefulWidget {
final String content; final String content;
@@ -21,47 +25,122 @@ class ConfigEditPage extends ConsumerStatefulWidget {
class _ConfigEditPageState extends ConsumerState<ConfigEditPage> { class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
CodeController? _codeController; CodeController? _codeController;
late String result; late String result;
late String preResult;
List<String> operateList = [];
@override @override
void dispose() { void dispose() {
_codeController?.dispose(); _codeController?.dispose();
super.dispose(); super.dispose();
} }
@override @override
void initState() { void initState() {
result = widget.content; result = widget.content;
preResult = widget.content;
super.initState(); super.initState();
generateOperateList();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
focusNode.requestFocus(); focusNode.requestFocus();
checkClipBoard();
}); });
} }
Future<void> notifyICloud(
BuildContext context, String? title, String? content) async {}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_codeController ??= CodeController( _codeController ??= CodeController(
text: widget.content, text: result,
language: powershell, language: powershell,
onChange: (value) { onChange: (value) {
result = value; result = value;
}, },
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(), theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
stringMap: { stringMap: {
"export": const TextStyle(fontWeight: FontWeight.normal, color: Color(0xff6B2375)), "export": const TextStyle(
fontWeight: FontWeight.normal, color: Color(0xff6B2375)),
}, },
); );
return Scaffold( return Scaffold(
appBar: QlAppBar( appBar: QlAppBar(
canBack: true, canBack: true,
backCall: () { backCall: () {
Navigator.of(context).pop(); FocusManager.instance.primaryFocus?.unfocus();
if (preResult == result) {
Navigator.of(context).pop();
} else {
showCupertinoDialog(
context: context,
useRootNavigator: false,
builder: (childContext) => CupertinoAlertDialog(
title: const Text("温馨提示"),
content: const Text("你编辑的内容还没用提交,确定退出吗?"),
actions: [
CupertinoDialogAction(
child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () {
Navigator.of(childContext).pop();
},
),
CupertinoDialogAction(
child: Text(
"确定",
style: TextStyle(
color: ref.watch(themeProvider).primaryColor,
),
),
onPressed: () {
Navigator.of(childContext).pop();
Navigator.of(context).pop();
},
),
],
),
);
}
}, },
title: '编辑${widget.title}', title: '编辑${widget.title}',
actions: [ actions: [
const SizedBox(
width: 15,
),
Material(
color: Colors.transparent,
child: PopupMenuButton<String>(
onSelected: (String result) {
updateValueBykey(result);
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
...operateList
.map(
(e) => PopupMenuItem<String>(
child: Text(e),
value: e,
),
)
.toList(),
],
child: const Center(
child: Icon(
CupertinoIcons.arrow_up_right_diamond,
),
),
),
),
InkWell( InkWell(
onTap: () async { onTap: () async {
HttpResponse<NullResponse> response = await Api.saveFile(widget.title, result); HttpResponse<NullResponse> response =
await Api.saveFile(widget.title, result);
await notifyICloud(context, widget.title, result);
if (response.success) { if (response.success) {
"提交成功".toast(); "提交成功".toast();
Navigator.of(context).pop(widget.title); Navigator.of(context).pop(widget.title);
@@ -88,14 +167,177 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
), ),
body: SafeArea( body: SafeArea(
top: false, top: false,
child: CodeField( child: Padding(
controller: _codeController!, padding: EdgeInsets.symmetric(
expands: true, horizontal: SpUtil.getBool(spShowLine, defValue: false) ? 0 : 10,
background: ref.watch(themeProvider).themeColor.settingBgColor(), ),
child: CodeField(
controller: _codeController!,
expands: true,
background: Colors.white,
wrap: SpUtil.getBool(spShowLine, defValue: false) ? false : true,
hideColumn: !SpUtil.getBool(spShowLine, defValue: false),
lineNumberStyle: LineNumberStyle(
textStyle: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
), ),
), ),
); );
} }
FocusNode focusNode = FocusNode(); FocusNode focusNode = FocusNode();
void generateOperateList() {
operateList.clear();
List<String> array = result.split("\n");
for (String a in array) {
String t = a.replaceAll(" ", "");
if (t.trim().startsWith("export")) {
int i = t.indexOf("export") + 6;
int j = t.indexOf("=");
operateList.add(t.substring(i, j));
}
}
}
void updateValueBykey(String key) async {
String defaultValue = "";
try {
var clipBoard = await Clipboard.getData(Clipboard.kTextPlain);
if (clipBoard != null && clipBoard.text != null) {
String tempText = clipBoard.text!;
if (tempText.trim().contains("export")) {
int i = tempText.trim().indexOf("\"");
int j = tempText.trim().lastIndexOf("\"");
if (i == -1 || j == -1) {
i = tempText.trim().indexOf("'");
j = tempText.trim().lastIndexOf("'");
}
defaultValue = tempText.trim().substring(i, j);
} else {
defaultValue = tempText;
}
}
} catch (e) {}
TextEditingController controller = TextEditingController(
text: defaultValue.replaceAll("\"", "").replaceAll("'", ""));
showCupertinoDialog(
useRootNavigator: false,
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text("编辑$key:"),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
),
child: TextField(
controller: controller,
decoration: const InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(4),
hintText: "请输入值",
hintStyle: TextStyle(
fontSize: 14,
),
),
autofocus: false,
),
),
],
),
actions: [
CupertinoDialogAction(
child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text(
"确定",
style: TextStyle(
color: ref.watch(themeProvider).primaryColor,
),
),
onPressed: () async {
Navigator.of(context).pop();
updateValueByKey(key, controller.text);
},
),
],
),
);
}
void updateValueByKey(String key, String text) {
List<String> array = result.split("\n");
for (String a in array) {
String t = a.replaceAll(" ", "");
if (t.trim().startsWith("export")) {
int i = t.indexOf("export") + 6;
int j = t.indexOf("=");
String tempResult = t.substring(i, j);
if (tempResult == key) {
result = result.replaceAll(a, "\nexport $key = \"$text\" \n\n");
break;
}
}
}
_codeController = null;
setState(() {});
"已修改".toast();
}
void checkClipBoard() async {
try {
String key = "";
String value = "";
var clipBoard = await Clipboard.getData(Clipboard.kTextPlain);
if (clipBoard != null && clipBoard.text != null) {
String tempText = clipBoard.text!;
if (tempText.trim().contains("export")) {
int kI = tempText.trim().indexOf("export");
int kJ = tempText.trim().indexOf("=");
key = tempText.trim().substring(kI + 6, kJ);
int i = tempText.trim().indexOf("\"");
int j = tempText.trim().lastIndexOf("\"");
if (i == -1 || j == -1) {
i = tempText.trim().indexOf("'");
j = tempText.trim().lastIndexOf("'");
}
value = tempText.trim().substring(i, j);
if (key.isNotEmpty && result.contains(key) && value.isNotEmpty) {
WidgetsBinding.instance.endOfFrame.then((value) {
updateValueBykey(key);
});
}
}
}
} catch (e) {}
}
} }

View File

@@ -1,13 +1,18 @@
import 'dart:ui'; import 'dart:ui';
import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:highlight/languages/powershell.dart';
import 'package:qinglong_app/base/base_state_widget.dart'; import 'package:qinglong_app/base/base_state_widget.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/sp_const.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/ui/abs_underline_tabindicator.dart'; import 'package:qinglong_app/base/ui/abs_underline_tabindicator.dart';
import 'package:qinglong_app/base/ui/empty_widget.dart'; import 'package:qinglong_app/base/ui/empty_widget.dart';
import 'package:qinglong_app/main.dart'; import 'package:qinglong_app/main.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:qinglong_app/utils/sp_utils.dart';
import '../../base/ui/syntax_highlighter.dart'; import '../../base/ui/syntax_highlighter.dart';
import 'config_viewmodel.dart'; import 'config_viewmodel.dart';
@@ -105,7 +110,7 @@ class ConfigPageState extends State<ConfigPage>
bool get wantKeepAlive => true; bool get wantKeepAlive => true;
} }
class CodeWidget extends StatefulWidget { class CodeWidget extends ConsumerStatefulWidget {
final String content; final String content;
const CodeWidget({ const CodeWidget({
@@ -114,29 +119,63 @@ class CodeWidget extends StatefulWidget {
}) : super(key: key); }) : super(key: key);
@override @override
State<CodeWidget> createState() => _CodeWidgetState(); ConsumerState<CodeWidget> createState() => _CodeWidgetState();
} }
class _CodeWidgetState extends State<CodeWidget> class _CodeWidgetState extends ConsumerState<CodeWidget>
with AutomaticKeepAliveClientMixin { with AutomaticKeepAliveClientMixin {
CodeController? _codeController;
@override
void dispose() {
_codeController?.dispose();
super.dispose();
}
String result = "";
@override
void initState() {
result = widget.content;
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SelectableText.rich( super.build(context);
TextSpan( _codeController ??= CodeController(
style: GoogleFonts.droidSansMono(fontSize: 14).apply( text: result,
fontSizeFactor: 1, language: powershell,
onChange: (value) {
result = value;
},
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
stringMap: {
"export": const TextStyle(
fontWeight: FontWeight.normal, color: Color(0xff6B2375)),
},
);
return SafeArea(
top: false,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: SpUtil.getBool(spShowLine, defValue: false) ? 0 : 10,
), ),
children: <TextSpan>[ child: CodeField(
DartSyntaxHighlighter(SyntaxHighlighterStyle.lightThemeStyle()) controller: _codeController!,
.format(widget.content) expands: true,
], readOnly: true,
), background: Colors.white,
style: DefaultTextStyle.of(context).style.apply( wrap: SpUtil.getBool(spShowLine, defValue: false) ? false : true,
fontSizeFactor: 1, hideColumn: !SpUtil.getBool(spShowLine, defValue: false),
lineNumberStyle: LineNumberStyle(
textStyle: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
), ),
selectionWidthStyle: BoxWidthStyle.max, ),
selectionHeightStyle: BoxHeightStyle.max, ),
autofocus: true,
); );
} }

View File

@@ -12,7 +12,7 @@ class ConfigViewModel extends BaseViewModel {
Map<String, String> content = {}; Map<String, String> content = {};
Future<void> loadData([isLoading = true]) async { Future<void> loadData([isLoading = true]) async {
if (isLoading) { if (isLoading && list.isEmpty) {
loading(notify: true); loading(notify: true);
} }

View File

@@ -35,7 +35,7 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
} else { } else {
envBean = EnvBean(); envBean = EnvBean();
} }
WidgetsBinding.instance?.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(
(timeStamp) { (timeStamp) {
focusNode.requestFocus(); focusNode.requestFocus();
}, },
@@ -186,8 +186,12 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
envBean.value = _valueController.text; envBean.value = _valueController.text;
envBean.remarks = _remarkController.text; envBean.remarks = _remarkController.text;
HttpResponse<NullResponse> response = await Api.addEnv( HttpResponse<NullResponse> response = await Api.addEnv(
_nameController.text, _valueController.text, _remarkController.text, _nameController.text,
id: envBean.id,nId: envBean.nId,); _valueController.text,
_remarkController.text,
id: envBean.id,
nId: envBean.nId,
);
if (response.success) { if (response.success) {
(envBean.sId == null) ? "新增成功" : "修改成功".toast(); (envBean.sId == null) ? "新增成功" : "修改成功".toast();

View File

@@ -12,7 +12,14 @@ class EnvBean {
String? name; String? name;
String? remarks; String? remarks;
EnvBean({this.value, this.sId, this.created, this.status, this.timestamp, this.name, this.remarks}); EnvBean(
{this.value,
this.sId,
this.created,
this.status,
this.timestamp,
this.name,
this.remarks});
get nId => _id; get nId => _id;
@@ -20,7 +27,9 @@ class EnvBean {
value = json['value']; value = json['value'];
id = json['id']; id = json['id'];
_id = json['_id']; _id = json['_id'];
sId = json.containsKey('_id') ? json['_id'].toString() : (json.containsKey('id') ? json['id'].toString() : ""); sId = json.containsKey('_id')
? json['_id'].toString()
: (json.containsKey('id') ? json['id'].toString() : "");
created = int.tryParse(json['created'].toString()); created = int.tryParse(json['created'].toString());
status = json['status']; status = json['status'];
timestamp = json['timestamp']; timestamp = json['timestamp'];

View File

@@ -36,7 +36,8 @@ class _TaskDetailPageState extends ConsumerState<EnvDetailPage> {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: widget.envBean); Navigator.of(context)
.pushNamed(Routes.routeAddEnv, arguments: widget.envBean);
}, },
child: Container( child: Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@@ -225,7 +226,9 @@ class _TaskDetailPageState extends ConsumerState<EnvDetailPage> {
} }
void enableTask() async { void enableTask() async {
await ref.read(envProvider).enableEnv(widget.envBean.sId!, widget.envBean.status!); await ref
.read(envProvider)
.enableEnv(widget.envBean.sId!, widget.envBean.status!);
setState(() {}); setState(() {});
} }
@@ -322,14 +325,16 @@ class EnvDetailCell extends ConsumerWidget {
} }
}, },
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(), color:
ref.watch(themeProvider).themeColor.descColor(),
fontSize: 14, fontSize: 14,
), ),
), ),
), ),
) )
: Expanded( : Expanded(
child: Align(alignment: Alignment.centerRight, child: icon!), child:
Align(alignment: Alignment.centerRight, child: icon!),
), ),
], ],
), ),

View File

@@ -8,6 +8,7 @@ import 'package:qinglong_app/base/base_state_widget.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/ui/empty_widget.dart'; import 'package:qinglong_app/base/ui/empty_widget.dart';
import 'package:qinglong_app/base/ui/search_cell.dart';
import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/env/env_bean.dart';
import 'package:qinglong_app/module/env/env_viewmodel.dart'; import 'package:qinglong_app/module/env/env_viewmodel.dart';
import 'package:qinglong_app/utils/extension.dart'; import 'package:qinglong_app/utils/extension.dart';
@@ -22,6 +23,7 @@ class EnvPage extends StatefulWidget {
class _EnvPageState extends State<EnvPage> { class _EnvPageState extends State<EnvPage> {
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
String currentState = EnvViewModel.allStr;
@override @override
void initState() { void initState() {
@@ -35,100 +37,166 @@ class _EnvPageState extends State<EnvPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BaseStateWidget<EnvViewModel>( return BaseStateWidget<EnvViewModel>(
builder: (ref, model, child) { builder: (ref, model, child) {
List<EnvBean> prepareList = [];
List<EnvItemCell> list = []; List<EnvItemCell> list = [];
if (currentState == EnvViewModel.allStr) {
prepareList = model.list;
} else if (currentState == EnvViewModel.enabledStr) {
prepareList = model.enabledList;
} else {
prepareList = model.disabledList;
}
for (int i = 0; i < model.list.length; i++) { for (int i = 0; i < prepareList.length; i++) {
EnvBean value = model.list[i]; EnvBean value = prepareList[i];
if (_searchController.text.isEmpty || if (_searchController.text.isEmpty ||
(value.name?.contains(_searchController.text) ?? false) || (value.name?.contains(_searchController.text) ?? false) ||
(value.value?.contains(_searchController.text) ?? false) || (value.value?.contains(_searchController.text) ?? false) ||
(value.remarks?.contains(_searchController.text) ?? false)) { (value.remarks?.contains(_searchController.text) ?? false)) {
list.add(EnvItemCell( list.add(
value, EnvItemCell(
i, value,
ref, i,
key: ValueKey(value.sId), ref,
)); key: ValueKey(value.sId),
),
);
} }
} }
return model.list.isEmpty return model.list.isEmpty
? const EmptyWidget() ? const EmptyWidget()
: RefreshIndicator( : RefreshIndicator(
notificationPredicate: (_) {
return true;
},
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
onRefresh: () async { onRefresh: () async {
return model.loadData(false); return model.loadData(false);
}, },
child: SlidableAutoCloseBehavior( child: SlidableAutoCloseBehavior(
child: ReorderableListView( child: currentState == EnvViewModel.disabledStr
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, ? ListView(
header: searchCell(ref), children: [
onReorder: (int oldIndex, int newIndex) { searchCell(context, ref),
if (list.length != model.list.length) { ...list,
"请先清空搜索关键词".toast(); ],
return; )
} : ReorderableListView(
keyboardDismissBehavior:
ScrollViewKeyboardDismissBehavior.onDrag,
header: searchCell(context, ref),
onReorder: (int oldIndex, int newIndex) {
if (list.length != model.list.length) {
"请先清空搜索关键词".toast();
return;
}
setState(() { setState(
//交换数据 () {
if (newIndex > oldIndex) { //交换数据
newIndex -= 1; if (newIndex > oldIndex) {
} newIndex -= 1;
final EnvBean item = model.list.removeAt(oldIndex); }
model.list.insert(newIndex, item); final EnvBean item =
model.update(item.sId ?? "", newIndex, oldIndex); model.list.removeAt(oldIndex);
}); model.list.insert(newIndex, item);
}, model.update(
children: list, item.sId ?? "", newIndex, oldIndex);
), },
);
},
children: list,
),
), ),
); );
}, },
model: envProvider, model: envProvider,
onReady: (viewModel) { onReady: (viewModel) {
viewModel.loadData(); viewModel.loadData(true);
}, },
); );
} }
Widget searchCell(WidgetRef context) { Widget searchCell(BuildContext context, WidgetRef ref) {
return Container( return Container(
padding: const EdgeInsets.symmetric( color: ref.watch(themeProvider).themeColor.settingBgColor(),
horizontal: 15, padding: const EdgeInsets.only(
vertical: 10, left: 15,
), ),
child: CupertinoSearchTextField( child: Row(
onSubmitted: (value) { children: [
setState(() {}); Expanded(
}, child: Padding(
onSuffixTap: () { padding: const EdgeInsets.symmetric(
_searchController.text = ""; vertical: 10,
setState(() {}); ),
}, child: SearchCell(
controller: _searchController, controller: _searchController,
borderRadius: BorderRadius.circular( ),
30, ),
), ),
padding: const EdgeInsets.symmetric( Material(
horizontal: 5, color: Colors.transparent,
vertical: 5, child: PopupMenuButton<String>(
), onSelected: (String result) {
suffixInsets: const EdgeInsets.only( currentState = result;
right: 15, setState(() {});
), },
prefixInsets: EdgeInsets.only( itemBuilder: (BuildContext context) => [
top: Platform.isAndroid ? 10 : 6, PopupMenuItem(
bottom: 6, child: Text(
left: 15, EnvViewModel.allStr,
), style: TextStyle(
placeholderStyle: TextStyle( color: currentState == EnvViewModel.allStr
fontSize: 16, ? ref.watch(themeProvider).primaryColor
color: context.watch(themeProvider).themeColor.descColor(), : ref.watch(themeProvider).themeColor.titleColor(),
), fontSize: 14,
style: const TextStyle( ),
fontSize: 16, ),
), value: EnvViewModel.allStr,
placeholder: "搜索", ),
PopupMenuItem(
child: Text(
EnvViewModel.enabledStr,
style: TextStyle(
color: currentState == EnvViewModel.enabledStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
value: EnvViewModel.enabledStr,
),
PopupMenuItem(
child: Text(
EnvViewModel.disabledStr,
style: TextStyle(
color: currentState == EnvViewModel.disabledStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
value: EnvViewModel.disabledStr,
),
],
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 10,
),
child: Text(
"筛选",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 14,
),
),
),
),
),
],
), ),
); );
} }
@@ -139,173 +207,222 @@ class EnvItemCell extends StatelessWidget {
final int index; final int index;
final WidgetRef ref; final WidgetRef ref;
const EnvItemCell(this.bean, this.index, this.ref, {Key? key}) : super(key: key); const EnvItemCell(this.bean, this.index, this.ref, {Key? key})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ColoredBox( return Slidable(
color: ref.watch(themeProvider).themeColor.settingBgColor(), key: ValueKey(bean.sId),
child: Slidable( endActionPane: ActionPane(
key: ValueKey(bean.sId), motion: const StretchMotion(),
endActionPane: ActionPane( extentRatio: 0.5,
motion: const StretchMotion(), children: [
extentRatio: 0.5, SlidableAction(
backgroundColor: const Color(0xff5D5E70),
onPressed: (_) {
Navigator.of(context)
.pushNamed(Routes.routeAddEnv, arguments: bean);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.pencil_outline,
),
SlidableAction(
backgroundColor: const Color(0xffA356D6),
onPressed: (_) {
enableEnv(context);
},
foregroundColor: Colors.white,
icon: bean.status == 0
? Icons.dnd_forwardslash
: Icons.check_circle_outline_sharp,
),
SlidableAction(
backgroundColor: const Color(0xffEA4D3E),
onPressed: (_) {
delEnv(context, ref);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.delete,
),
],
),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SlidableAction( Material(
backgroundColor: const Color(0xff5D5E70), color: ref.watch(themeProvider).themeColor.settingBgColor(),
onPressed: (_) { child: InkWell(
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean); onTap: () {
}, Navigator.of(context)
foregroundColor: Colors.white, .pushNamed(Routes.routeEnvDetail, arguments: bean);
icon: CupertinoIcons.pencil_outline, },
), child: Container(
SlidableAction( padding: const EdgeInsets.symmetric(
backgroundColor: const Color(0xffA356D6), horizontal: 15,
onPressed: (_) { vertical: 8,
enableEnv(context); ),
}, child: Column(
foregroundColor: Colors.white, mainAxisSize: MainAxisSize.min,
icon: bean.status == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp, mainAxisAlignment: MainAxisAlignment.start,
), crossAxisAlignment: CrossAxisAlignment.start,
SlidableAction( children: [
backgroundColor: const Color(0xffEA4D3E), Row(
onPressed: (_) { mainAxisAlignment: MainAxisAlignment.start,
delEnv(context, ref); children: [
}, Expanded(
foregroundColor: Colors.white, child: Row(
icon: CupertinoIcons.delete, children: [
), bean.status == 1
], ? const SizedBox(
), width: 18,
child: SizedBox( )
width: MediaQuery.of(context).size.width, : Container(
child: Column( padding: const EdgeInsets.symmetric(
mainAxisSize: MainAxisSize.min, horizontal: 5,
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ decoration: BoxDecoration(
Material( borderRadius:
color: ref.watch(themeProvider).themeColor.settingBgColor(), BorderRadius.circular(3),
child: InkWell( border: Border.all(
onTap: () { color: ref
Navigator.of(context).pushNamed(Routes.routeEnvDetail, arguments: bean); .watch(themeProvider)
}, .themeColor
child: Container( .descColor(),
padding: const EdgeInsets.symmetric( width: 1),
horizontal: 15, ),
vertical: 8, child: Text(
), "${getIndexByIndex(context, index)}",
child: Column( style: TextStyle(
mainAxisSize: MainAxisSize.min, color: ref
mainAxisAlignment: MainAxisAlignment.start, .watch(themeProvider)
crossAxisAlignment: CrossAxisAlignment.start, .themeColor
children: [ .descColor(),
Row( fontSize: 12,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
children: [
bean.status == 1
? const Icon(
Icons.dnd_forwardslash,
size: 18,
color: Color(0xffEA4D3E),
)
: Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
),
child: Text(
"${getIndexByIndex(context, index)}",
style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12),
), ),
), ),
const SizedBox( ),
width: 5, const SizedBox(
width: 5,
),
ConstrainedBox(
constraints: BoxConstraints.loose(
Size.fromWidth(
MediaQuery.of(context).size.width / 2,
),
), ),
Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: Text( child: Text(
bean.name ?? "", bean.name ?? "",
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
), ),
const SizedBox( ),
width: 5, const SizedBox(
width: 5,
),
ConstrainedBox(
constraints: BoxConstraints.loose(
Size.fromWidth(
MediaQuery.of(context).size.width / 3,
),
), ),
Expanded( child: Visibility(
child: Visibility( visible: bean.remarks != null &&
visible: bean.remarks != null && bean.remarks!.isNotEmpty, bean.remarks!.isNotEmpty,
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: Text( child: Text(
"(${bean.remarks})", "(${bean.remarks})",
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
height: 1, height: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(), color: ref
fontSize: 12, .watch(themeProvider)
), .themeColor
.descColor(),
fontSize: 12,
), ),
), ),
), ),
), ),
],
),
),
const SizedBox(
width: 15,
),
Material(
color: Colors.transparent,
child: Text(
Utils.formatGMTTime(bean.timestamp ?? ""),
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
), ),
), const SizedBox(
), width: 7,
], ),
), bean.status == 1
const SizedBox( ? Image.asset(
height: 15, "assets/images/icon_disabled.png",
), fit: BoxFit.cover,
Material( width: 35,
color: Colors.transparent, )
child: Text( : Image.asset(
bean.value ?? "", "assets/images/icon_enable.png",
maxLines: 1, fit: BoxFit.cover,
style: TextStyle( width: 35,
overflow: TextOverflow.ellipsis, )
color: ref.watch(themeProvider).themeColor.descColor(), ],
fontSize: 12,
), ),
), ),
const SizedBox(
width: 15,
),
Material(
color: Colors.transparent,
child: Text(
Utils.formatGMTTime(bean.timestamp ?? ""),
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref
.watch(themeProvider)
.themeColor
.descColor(),
fontSize: 12,
),
),
),
],
),
const SizedBox(
height: 15,
),
Material(
color: Colors.transparent,
child: Text(
bean.value ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color:
ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
), ),
], ),
), ],
), ),
), ),
), ),
const Divider( ),
height: 1, const Divider(
indent: 15, height: 1,
), indent: 15,
], ),
), ],
), ),
), ),
); );

View File

@@ -8,10 +8,15 @@ import 'package:qinglong_app/utils/extension.dart';
var envProvider = ChangeNotifierProvider((ref) => EnvViewModel()); var envProvider = ChangeNotifierProvider((ref) => EnvViewModel());
class EnvViewModel extends BaseViewModel { class EnvViewModel extends BaseViewModel {
static const String allStr = "全部";
static const String disabledStr = "已禁用";
static const String enabledStr = "已启用";
List<EnvBean> list = []; List<EnvBean> list = [];
List<EnvBean> disabledList = [];
List<EnvBean> enabledList = [];
Future<void> loadData([isLoading = true]) async { Future<void> loadData([isLoading = true]) async {
if (isLoading) { if (isLoading && list.isEmpty) {
loading(notify: true); loading(notify: true);
} }
@@ -20,9 +25,16 @@ class EnvViewModel extends BaseViewModel {
if (result.success && result.bean != null) { if (result.success && result.bean != null) {
list.clear(); list.clear();
list.addAll(result.bean!); list.addAll(result.bean!);
disabledList.clear();
disabledList
.addAll(list.where((element) => element.status == 1).toList());
enabledList.clear();
enabledList.addAll(list.where((element) => element.status == 0).toList());
success(); success();
} else { } else {
list.clear(); list.clear();
disabledList.clear();
enabledList.clear();
failed(result.message, notify: true); failed(result.message, notify: true);
} }
} }
@@ -31,23 +43,14 @@ class EnvViewModel extends BaseViewModel {
HttpResponse<NullResponse> result = await Api.delEnv(id); HttpResponse<NullResponse> result = await Api.delEnv(id);
if (result.success) { if (result.success) {
"删除成功".toast(); "删除成功".toast();
list.removeWhere((element) => element.sId == id); loadData(false);
notifyListeners();
} else { } else {
failed(result.message, notify: true); failed(result.message, notify: true);
} }
} }
void updateEnv(EnvBean result) { void updateEnv(EnvBean result) {
if (result.sId == null) { loadData(false);
loadData(false);
return;
}
EnvBean bean = list.firstWhere((element) => element.sId == result.sId);
bean.name = result.name;
bean.remarks = result.remarks;
bean.value = result.value;
notifyListeners();
} }
Future<void> enableEnv(String sId, int status) async { Future<void> enableEnv(String sId, int status) async {
@@ -56,8 +59,7 @@ class EnvViewModel extends BaseViewModel {
if (response.success) { if (response.success) {
"启用成功".toast(); "启用成功".toast();
list.firstWhere((element) => element.sId == sId).status = 0; loadData(false);
success();
} else { } else {
failToast(response.message, notify: true); failToast(response.message, notify: true);
} }
@@ -66,8 +68,7 @@ class EnvViewModel extends BaseViewModel {
if (response.success) { if (response.success) {
"禁用成功".toast(); "禁用成功".toast();
list.firstWhere((element) => element.sId == sId).status = 1; loadData(false);
success();
} else { } else {
failToast(response.message, notify: true); failToast(response.message, notify: true);
} }

View File

@@ -44,7 +44,7 @@ class _HomePageState extends ConsumerState<HomePage>
initTitles(); initTitles();
_title = titles[0].title; _title = titles[0].title;
super.initState(); super.initState();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
getSystemBean(); getSystemBean();
}); });
} }

View File

@@ -2,6 +2,7 @@ import 'package:dio_log/dio_log.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_animator/flutter_animator.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
@@ -43,7 +44,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
if (!widget.doNotLoadLocalData) { if (!widget.doNotLoadLocalData) {
_hostController.text = getIt<UserInfoViewModel>().host ?? ""; _hostController.text = getIt<UserInfoViewModel>().host ?? "";
useSecretLogin = getIt<UserInfoViewModel>().useSecretLogined; useSecretLogin = getIt<UserInfoViewModel>().useSecretLogined;
if (getIt<UserInfoViewModel>().userName != null && getIt<UserInfoViewModel>().userName!.isNotEmpty) { if (getIt<UserInfoViewModel>().userName != null &&
getIt<UserInfoViewModel>().userName!.isNotEmpty) {
if (getIt<UserInfoViewModel>().useSecretLogined) { if (getIt<UserInfoViewModel>().useSecretLogined) {
_cIdController.text = getIt<UserInfoViewModel>().userName!; _cIdController.text = getIt<UserInfoViewModel>().userName!;
} else { } else {
@@ -53,7 +55,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
} else { } else {
rememberPassword = false; rememberPassword = false;
} }
if (getIt<UserInfoViewModel>().passWord != null && getIt<UserInfoViewModel>().passWord!.isNotEmpty) { if (getIt<UserInfoViewModel>().passWord != null &&
getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
if (getIt<UserInfoViewModel>().useSecretLogined) { if (getIt<UserInfoViewModel>().useSecretLogined) {
_cSecretController.text = getIt<UserInfoViewModel>().passWord!; _cSecretController.text = getIt<UserInfoViewModel>().passWord!;
} else { } else {
@@ -62,311 +65,459 @@ class _LoginPageState extends ConsumerState<LoginPage> {
} }
} }
getIt<UserInfoViewModel>().updateToken(""); getIt<UserInfoViewModel>().updateToken("");
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (useSecretLogin) { if (useSecretLogin) {
cardKey.currentState?.toggleCard(); cardKey.currentState?.toggleCard();
} }
}); });
} }
GlobalKey<AnimatorWidgetState> loginKey = GlobalKey<AnimatorWidgetState>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>( body: AnnotatedRegion<SystemUiOverlayStyle>(
value: ref.watch(themeProvider).darkMode == true ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark, value: ref.watch(themeProvider).darkMode == true
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
child: ColoredBox( child: ColoredBox(
color: ref.watch(themeProvider).themeColor.settingBgColor(), color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: SizedBox( child: SingleChildScrollView(
height: MediaQuery.of(context).size.height, child: Column(
child: Stack( mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Positioned( Padding(
bottom: 0, padding: const EdgeInsets.symmetric(
child: Image.asset( horizontal: 40,
"assets/images/login_bg.png",
width: MediaQuery.of(context).size.width,
), ),
), child: Column(
Scaffold( mainAxisAlignment: MainAxisAlignment.start,
backgroundColor: Colors.transparent, crossAxisAlignment: CrossAxisAlignment.start,
body: SingleChildScrollView( children: [
child: Column( SizedBox(
mainAxisAlignment: MainAxisAlignment.start, height: MediaQuery.of(context).size.height / 8,
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ Row(
Padding( children: [
padding: const EdgeInsets.symmetric( Expanded(
horizontal: 40, child: Align(
alignment: Alignment.centerLeft,
child: Text(
useSecretLogin ? "client_id登录" : "账号登录",
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
),
),
),
), ),
GestureDetector(
onDoubleTap: () {
if (debugBtnIsShow()) {
dismissDebugBtn();
} else {
showDebugBtn(context,
btnColor:
ref.watch(themeProvider).primaryColor);
}
WidgetsBinding.instance.endOfFrame;
},
child: Image.asset(
"assets/images/ql.png",
height: 45,
),
),
],
),
SizedBox(
height: MediaQuery.of(context).size.height / 15,
),
Row(
children: [
const SizedBox(
width: 40,
child: Text(
"域名",
style: TextStyle(
fontSize: 16,
),
),
),
const SizedBox(
width: 30,
),
Expanded(
child: TextField(
onChanged: (_) {
setState(() {});
},
controller: _hostController,
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.all(4),
hintText: "http://1.1.1.1:5700",
hintStyle: TextStyle(
fontSize: 16,
color: ref
.watch(themeProvider)
.themeColor
.descColor(),
),
),
autofocus: false,
),
),
],
),
const Divider(
color: Color(0xff999999),
),
const SizedBox(
height: 10,
),
FlipCard(
key: cardKey,
flipOnTouch: false,
onFlipDone: (back) {
useSecretLogin = back;
setState(() {});
},
direction: FlipDirection.HORIZONTAL,
front: SizedBox(
height: 110,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox(
height: MediaQuery.of(context).size.height / 10,
),
Row( Row(
children: [ children: [
Expanded( const SizedBox(
child: Align( child: Text(
alignment: Alignment.centerLeft, "账户",
child: Image.asset( style: TextStyle(
"assets/images/login_tip.png", fontSize: 16,
height: 45,
), ),
), ),
width: 40,
), ),
GestureDetector( const SizedBox(
onDoubleTap: () { width: 30,
if (debugBtnIsShow()) { ),
dismissDebugBtn(); Expanded(
} else { child: TextField(
showDebugBtn(context, btnColor: ref.watch(themeProvider).primaryColor); onChanged: (_) {
} setState(() {});
WidgetsBinding.instance?.endOfFrame; },
}, controller: _userNameController,
child: Image.asset( decoration: InputDecoration(
"assets/images/ql.png", border: InputBorder.none,
height: 45, enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.all(4),
hintText: "请输入账户",
hintStyle: TextStyle(
fontSize: 16,
color: ref
.watch(themeProvider)
.themeColor
.descColor(),
),
),
autofocus: false,
), ),
), ),
], ],
), ),
SizedBox( const Divider(
height: MediaQuery.of(context).size.height / 15, color: Color(0xff999999),
),
const Text(
"域名:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _hostController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "http://1.1.1.1:5700",
),
autofocus: false,
),
FlipCard(
key: cardKey,
flipOnTouch: false,
onFlipDone: (back) {
useSecretLogin = back;
setState(() {});
},
direction: FlipDirection.HORIZONTAL,
front: SizedBox(
height: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 15,
),
const Text(
"用户名:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _userNameController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入用户名",
),
autofocus: false,
),
const SizedBox(
height: 15,
),
const Text(
"密码:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入密码",
),
autofocus: false,
),
const SizedBox(
height: 10,
),
],
),
),
back: SizedBox(
height: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 15,
),
const Text(
"client_id:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _cIdController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_id",
),
autofocus: false,
),
const SizedBox(
height: 15,
),
const Text(
"client_secret:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _cSecretController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_secret",
),
autofocus: false,
),
const SizedBox(
height: 10,
),
],
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 25,
),
child: Row(
children: [
Checkbox(
value: rememberPassword,
onChanged: (checked) {
rememberPassword = checked ?? false;
setState(() {});
},
),
const Text(
"记住密码/client",
style: TextStyle(
fontSize: 14,
),
),
const Spacer(),
GestureDetector(
onTap: () {
cardKey.currentState?.toggleCard();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
setState(() {});
});
},
child: Text(
loginByUserName() ? "client_id登录" : "账号登录",
style: const TextStyle(
fontSize: 14,
),
),
), ),
const SizedBox( const SizedBox(
width: 10, height: 10,
),
Row(
children: [
const SizedBox(
width: 40,
child: Text(
"密码",
style: TextStyle(
fontSize: 16,
),
),
),
const SizedBox(
width: 30,
),
Expanded(
child: TextField(
onChanged: (_) {
setState(() {});
},
controller: _passwordController,
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.all(4),
hintText: "请输入密码",
hintStyle: TextStyle(
fontSize: 16,
color: ref
.watch(themeProvider)
.themeColor
.descColor(),
),
),
autofocus: false,
),
),
],
),
const Divider(
color: Color(0xff999999),
), ),
], ],
), ),
), ),
const SizedBox( back: SizedBox(
height: 30, height: 110,
), child: Column(
Container( mainAxisSize: MainAxisSize.min,
alignment: Alignment.center, mainAxisAlignment: MainAxisAlignment.start,
padding: const EdgeInsets.symmetric( crossAxisAlignment: CrossAxisAlignment.start,
horizontal: 40, children: [
Row(
children: [
const SizedBox(
width: 40,
child: Text(
"id",
style: TextStyle(
fontSize: 16,
),
),
),
const SizedBox(
width: 30,
),
Expanded(
child: TextField(
onChanged: (_) {
setState(() {});
},
controller: _cIdController,
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.all(4),
hintText: "请输入client_id",
hintStyle: TextStyle(
fontSize: 16,
color: ref
.watch(themeProvider)
.themeColor
.descColor(),
),
),
autofocus: false,
),
),
],
),
const Divider(
color: Color(0xff999999),
),
const SizedBox(
height: 10,
),
Row(
children: [
const SizedBox(
width: 50,
child: Text(
"secret",
style: TextStyle(
fontSize: 16,
),
),
),
const SizedBox(
width: 20,
),
Expanded(
child: TextField(
onChanged: (_) {
setState(() {});
},
controller: _cSecretController,
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.all(4),
hintText: "请输入client_secret",
hintStyle: TextStyle(
fontSize: 16,
color: ref
.watch(themeProvider)
.themeColor
.descColor(),
),
),
autofocus: false,
),
),
],
),
const Divider(
color: Color(0xff999999),
),
],
), ),
child: SizedBox( ),
width: MediaQuery.of(context).size.width - 80, ),
child: IgnorePointer( const SizedBox(
ignoring: !canClickLoginBtn(), height: 10,
child: CupertinoButton( ),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 25,
),
child: Row(
children: [
Checkbox(
value: rememberPassword,
onChanged: (checked) {
rememberPassword = checked ?? false;
setState(() {});
},
),
const Text(
"记住密码",
style: TextStyle(
color: Color(0xff555555),
fontSize: 14,
),
),
const Spacer(),
GestureDetector(
onTap: () {
cardKey.currentState?.toggleCard();
WidgetsBinding.instance
.addPostFrameCallback((timeStamp) {
setState(() {});
});
},
child: Text(
loginByUserName() ? "client_id登录" : "账号登录",
style: const TextStyle(
color: Color(0xff555555),
fontSize: 14,
),
),
),
const SizedBox(
width: 10,
),
],
),
),
const SizedBox(
height: 30,
),
Shake(
preferences: const AnimationPreferences(
autoPlay: AnimationPlayStates.None),
key: loginKey,
child: Center(
child: Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width * 0.8,
padding: const EdgeInsets.symmetric(
horizontal: 40,
),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: canClickLoginBtn()
? [
const Color(0xff5DD16F),
const Color(0xff089556),
]
: [
const Color(0xff5DD16F).withOpacity(0.6),
const Color(0xff089556).withOpacity(0.6),
],
),
borderRadius: const BorderRadius.all(
Radius.circular(10),
),
),
child: SizedBox(
width: MediaQuery.of(context).size.width - 80,
child: IgnorePointer(
ignoring: !canClickLoginBtn(),
child: Builder(
builder: (context) {
return CupertinoButton(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 5, vertical: 5,
), ),
color: canClickLoginBtn() ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).primaryColor.withOpacity(0.4),
child: isLoading child: isLoading
? const CupertinoActivityIndicator() ? const CupertinoActivityIndicator()
: const Text( : const Text(
"登 录", "登 录",
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 18,
color: Colors.white,
), ),
), ),
onPressed: () { onPressed: () async {
Http.pushedLoginPage = false; Http.pushedLoginPage = false;
Utils.hideKeyBoard(context); Utils.hideKeyBoard(context);
if (loginByUserName()) { if (loginByUserName()) {
login(_userNameController.text, _passwordController.text); login(_userNameController.text,
_passwordController.text);
} else { } else {
login(_cIdController.text, _cSecretController.text); login(_cIdController.text,
_cSecretController.text);
} }
}, },
), );
), },
), ),
), ),
const SizedBox( ),
height: 30,
),
],
), ),
), ),
), ),
Positioned( const SizedBox(
bottom: 10, height: 30,
child: (getIt<UserInfoViewModel>().historyAccounts.isEmpty) ),
? const SizedBox.shrink() (getIt<UserInfoViewModel>().historyAccounts.isEmpty)
: SizedBox( ? const SizedBox.shrink()
: SafeArea(
top: false,
child: SizedBox(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: Center( child: Center(
child: Material( child: Material(
@@ -375,27 +526,43 @@ class _LoginPageState extends ConsumerState<LoginPage> {
onSelected: (UserInfoBean result) { onSelected: (UserInfoBean result) {
selected(result); selected(result);
}, },
itemBuilder: (BuildContext context) => <PopupMenuEntry<UserInfoBean>>[ itemBuilder: (BuildContext context) =>
<PopupMenuEntry<UserInfoBean>>[
...getIt<UserInfoViewModel>() ...getIt<UserInfoViewModel>()
.historyAccounts .historyAccounts
.map((e) => PopupMenuItem<UserInfoBean>( .map(
value: e, (e) => PopupMenuItem<UserInfoBean>(
child: buildCell(e), value: e,
)) child: buildCell(context, e),
),
)
.toList(), .toList(),
], ],
child: Text( child: Row(
"切换账号", mainAxisSize: MainAxisSize.min,
style: TextStyle( children: [
color: ref.watch(themeProvider).primaryColor, Image.asset(
fontSize: 14, "assets/images/icon_history.png",
), fit: BoxFit.cover,
width: 16,
),
const SizedBox(
width: 5,
),
const Text(
"历史账号",
style: TextStyle(
color: Color(0xff555555),
fontSize: 14,
),
),
],
), ),
), ),
), ),
), ),
), ),
), ),
], ],
), ),
), ),
@@ -416,7 +583,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
isLoading = true; isLoading = true;
setState(() {}); setState(() {});
helper = LoginHelper(useSecretLogin, _hostController.text, userName, password, rememberPassword); helper = LoginHelper(useSecretLogin, _hostController.text, userName,
password, rememberPassword);
var response = await helper!.login(); var response = await helper!.login();
dealLoginResponse(response); dealLoginResponse(response);
} }
@@ -434,6 +602,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
void loginFailed() { void loginFailed() {
isLoading = false; isLoading = false;
loginKey.currentState?.forward();
setState(() {}); setState(() {});
} }
@@ -442,9 +611,11 @@ class _LoginPageState extends ConsumerState<LoginPage> {
if (_hostController.text.isEmpty) return false; if (_hostController.text.isEmpty) return false;
if (!loginByUserName()) { if (!loginByUserName()) {
return _cIdController.text.isNotEmpty && _cSecretController.text.isNotEmpty; return _cIdController.text.isNotEmpty &&
_cSecretController.text.isNotEmpty;
} else { } else {
return _userNameController.text.isNotEmpty && _passwordController.text.isNotEmpty; return _userNameController.text.isNotEmpty &&
_passwordController.text.isNotEmpty;
} }
} }
@@ -512,7 +683,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
}); });
} }
Widget buildCell(UserInfoBean bean) { Widget buildCell(BuildContext context, UserInfoBean bean) {
return ListTile( return ListTile(
title: Text( title: Text(
bean.host ?? "", bean.host ?? "",
@@ -525,6 +696,19 @@ class _LoginPageState extends ConsumerState<LoginPage> {
bean.userName ?? "", bean.userName ?? "",
), ),
), ),
contentPadding: EdgeInsets.zero,
trailing: GestureDetector(
onTap: () {
getIt<UserInfoViewModel>().removeHistoryAccount(bean.host);
Navigator.pop(context);
setState(() {});
},
child: const Icon(
CupertinoIcons.clear_thick,
size: 20,
),
),
); );
} }
@@ -534,7 +718,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
_cIdController.text = result.userName ?? ""; _cIdController.text = result.userName ?? "";
_cSecretController.text = result.password ?? ""; _cSecretController.text = result.password ?? "";
if (cardKey.currentState?.isFront ?? false) { if (cardKey.currentState?.isFront ?? false) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
cardKey.currentState?.toggleCard(); cardKey.currentState?.toggleCard();
}); });
} }
@@ -542,7 +726,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
_userNameController.text = result.userName ?? ""; _userNameController.text = result.userName ?? "";
_passwordController.text = result.password ?? ""; _passwordController.text = result.password ?? "";
if (!(cardKey.currentState?.isFront ?? false)) { if (!(cardKey.currentState?.isFront ?? false)) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
cardKey.currentState?.toggleCard(); cardKey.currentState?.toggleCard();
}); });
} }

View File

@@ -19,6 +19,7 @@ class UserBean {
data['twoFactorActivated'] = this.twoFactorActivated; data['twoFactorActivated'] = this.twoFactorActivated;
return data; return data;
} }
static UserBean jsonConversion(Map<String, dynamic> json) { static UserBean jsonConversion(Map<String, dynamic> json) {
return UserBean.fromJson(json); return UserBean.fromJson(json);
} }

View File

@@ -23,7 +23,6 @@ class _AboutPageState extends ConsumerState<AboutPage> {
void initState() { void initState() {
super.initState(); super.initState();
getInfo(); getInfo();
} }
@override @override
@@ -88,7 +87,8 @@ class _AboutPageState extends ConsumerState<AboutPage> {
const Spacer(), const Spacer(),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
_launchURL("https://github.com/qinglong-app/qinglong_app/releases"); _launchURL(
"https://github.com/qinglong-app/qinglong_app/releases");
}, },
child: Text( child: Text(
"版本更新", "版本更新",

View File

@@ -0,0 +1,278 @@
import 'dart:convert';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:path_provider/path_provider.dart';
import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/json.jc.dart';
import 'package:qinglong_app/module/env/env_bean.dart';
import 'package:qinglong_app/utils/extension.dart';
import 'package:share_plus/share_plus.dart';
import '../../../base/theme.dart';
import '../../../base/userinfo_viewmodel.dart';
import '../../../main.dart';
class BackUpPage extends ConsumerStatefulWidget {
const BackUpPage({Key? key}) : super(key: key);
@override
_BackUpPageState createState() => _BackUpPageState();
}
class _BackUpPageState extends ConsumerState<BackUpPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: QlAppBar(
canBack: true,
title: '数据备份',
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15,
),
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.settingBordorColor(),
borderRadius: const BorderRadius.all(
Radius.circular(15),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
getEnv();
},
child: Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 5,
left: 15,
right: 15,
),
child: Row(
children: [
Text(
"环境变量备份到本地",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
uploadEnv(context);
},
child: Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 5,
left: 15,
right: 15,
),
child: Row(
children: [
Text(
"从本地导入环境变量",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
uploadEnvFromFile();
},
child: Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 5,
left: 15,
right: 15,
),
child: Row(
children: [
Text(
"从文件导入环境变量",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
shareEnvs();
},
child: Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 5,
left: 15,
right: 15,
),
child: Row(
children: [
Text(
"导出环境变量",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
]),
)
],
),
);
}
Future<void> shareEnvs() async {
Directory appDocDir = await getApplicationDocumentsDirectory();
var dir = Directory("${appDocDir.path}/backup/");
var fileList = await dir.list().toList();
List<String> paths = [];
for(var i=0;i<fileList.length;i++){
paths.add(fileList[i].path);
}
await Share.shareFiles(paths);
}
void getEnv() async {
var envs = await Api.envs("");
var data = json.encode(envs.bean);
Directory appDocDir = await getApplicationDocumentsDirectory();
// String? path = await FilePicker.platform.getDirectoryPath(initialDirectory:appDocDir.path,dialogTitle: "请选择保存的文件夹");
Directory("${appDocDir.path}/backup/").create();
Uri uri = Uri.parse(getIt<UserInfoViewModel>().host!);
File file = File("${appDocDir.path}/backup/${uri.host}-${uri.port}.env");
file = await file.writeAsString(data, flush: true);
"备份成功".toast();
}
void uploadEnvFromFile()async{
var result = await FilePicker.platform.pickFiles(dialogTitle: "请选择env文件");
if (result == null)return;
File f = File(result.paths[0]!);
var data = await f.readAsString();
var content = jsonDecode(data) as List<dynamic>;
for (var j = 0; j < content.length; j++) {
var bean = JsonConversion$Json.fromJson<EnvBean>(content[j]);
var resp = await Api.addEnv(bean.name!, bean.value!, bean.remarks!);
if (!resp.success){
resp.message.toast();
}
}
"备份完成".toast();
}
}
void uploadEnv(BuildContext context) async {
Directory appDocDir = await getApplicationDocumentsDirectory();
List<Widget> widgets = [];
var dir = Directory("${appDocDir.path}/backup/");
var fileList = await dir.list().toList();
for (var i = 0; i < fileList.length; i++) {
var paths = fileList[i].path.split("/");
widgets.add(
ListTile(
title: Text(paths[paths.length - 1]),
onTap: () async {
File f = File(fileList[i].path);
var data = await f.readAsString();
var content = jsonDecode(data) as List<dynamic>;
for (var j = 0; j < content.length; j++) {
var bean = JsonConversion$Json.fromJson<EnvBean>(content[j]);
var resp = await Api.addEnv(bean.name!, bean.value!, bean.remarks!);
if (!resp.success){
resp.message.toast();
}
}
"备份完成".toast();
},
));
}
var dialog = SimpleDialog(title: const Text("请选择备份文件"), children: widgets);
await showDialog(
context: context,
builder: (BuildContext context) {
return dialog;
});
}

View File

@@ -129,6 +129,8 @@ class _AddDependencyPageState extends ConsumerState<AddDependencyPage> {
), ),
TextField( TextField(
controller: _nameController, controller: _nameController,
maxLines: 10,
minLines: 1,
decoration: const InputDecoration( decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入名称", hintText: "请输入名称",
@@ -149,10 +151,18 @@ class _AddDependencyPageState extends ConsumerState<AddDependencyPage> {
return; return;
} }
HttpResponse<NullResponse> response = await Api.addDependency( List<Map<String, dynamic>> list = [];
_nameController.text,
depedencyType.index, List<String> names = _nameController.text.split("\n");
); list.addAll(names
.map(
(e) => {
"name": e,
"type": depedencyType.index,
},
)
.toList());
HttpResponse<NullResponse> response = await Api.addDependency(list);
if (response.success) { if (response.success) {
"新增成功".toast(); "新增成功".toast();

View File

@@ -21,7 +21,8 @@ class DependencyPage extends StatefulWidget {
_DependcyPageState createState() => _DependcyPageState(); _DependcyPageState createState() => _DependcyPageState();
} }
class _DependcyPageState extends State<DependencyPage> with TickerProviderStateMixin { class _DependcyPageState extends State<DependencyPage>
with TickerProviderStateMixin {
List<DepedencyEnum> types = []; List<DepedencyEnum> types = [];
TabController? _tabController; TabController? _tabController;
@@ -125,7 +126,9 @@ class _DependcyPageState extends State<DependencyPage> with TickerProviderStateM
itemCount: list.length, itemCount: list.length,
), ),
onRefresh: () { onRefresh: () {
return model.loadData(types[_tabController!.index].name.toLowerCase(), false); return model.loadData(
types[_tabController!.index].name.toLowerCase(),
false);
}, },
); );
}, },
@@ -222,7 +225,10 @@ class DependencyCell extends ConsumerWidget {
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 18, fontSize: 18,
), ),
), ),
@@ -255,11 +261,16 @@ class DependencyCell extends ConsumerWidget {
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: Text( child: Text(
(bean.created == null || bean.created == 0) ? "-" : Utils.formatMessageTime(bean.created!), (bean.created == null || bean.created == 0)
? "-"
: Utils.formatMessageTime(bean.created!),
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(), color: ref
.watch(themeProvider)
.themeColor
.descColor(),
fontSize: 12, fontSize: 12,
), ),
), ),
@@ -283,7 +294,7 @@ class DependencyCell extends ConsumerWidget {
} }
void showLog(WidgetRef ref, String? sId) { void showLog(WidgetRef ref, String? sId) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
showCupertinoDialog( showCupertinoDialog(
builder: (BuildContext context) { builder: (BuildContext context) {
return CupertinoAlertDialog( return CupertinoAlertDialog(
@@ -357,7 +368,9 @@ class DependencyCell extends ConsumerWidget {
), ),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
ref.read(dependencyProvider).del(type.name.toLowerCase(), sId ?? ""); ref
.read(dependencyProvider)
.del(type.name.toLowerCase(), sId ?? "");
}, },
), ),
], ],

View File

@@ -15,7 +15,10 @@ class DependencyViewModel extends BaseViewModel {
List<DependencyBean> linuxList = []; List<DependencyBean> linuxList = [];
Future<void> loadData(String type, [bool showLoading = true]) async { Future<void> loadData(String type, [bool showLoading = true]) async {
if (showLoading) { if (showLoading &&
((type == "nodejs" && nodeJsList.isEmpty) ||
(type == "python3" && python3List.isEmpty) ||
(type == "linux" && linuxList.isEmpty))) {
loading(notify: true); loading(notify: true);
} }

View File

@@ -39,40 +39,53 @@ class _LoginLogPageState extends ConsumerState<LoginLogPage>
? const Center( ? const Center(
child: CupertinoActivityIndicator(), child: CupertinoActivityIndicator(),
) )
: ListView.builder( : ListView.separated(
itemBuilder: (context, index) { itemBuilder: (context, index) {
LoginLogBean item = list[index]; LoginLogBean item = list[index];
return ColoredBox( return Row(
color: ref.watch(themeProvider).themeColor.settingBgColor(), children: [
child: ListTile( const SizedBox(
isThreeLine: true, width: 15,
title: Text(
Utils.formatMessageTime(item.timestamp ?? 0),
style: TextStyle(
fontSize: 16,
color: ref.watch(themeProvider).themeColor.titleColor(),
),
), ),
subtitle: Column( Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const SizedBox( const SizedBox(
height: 5, height: 10,
), ),
SelectableText( Row(
"${item.address}", crossAxisAlignment: CrossAxisAlignment.start,
selectionWidthStyle: BoxWidthStyle.max, children: [
selectionHeightStyle: BoxHeightStyle.max, Text(
style: TextStyle( "${item.address}",
color: style: TextStyle(
ref.watch(themeProvider).themeColor.descColor(), color: ref
fontSize: 14, .watch(themeProvider)
), .themeColor
.titleColor(),
fontSize: 14,
),
),
const SizedBox(
width: 5,
),
Padding(
padding: const EdgeInsets.only(
top: 2,
),
child: Image.asset(
item.status == 0
? "assets/images/icon_success.png"
: "assets/images/icon_fail.png",
width: 30,
fit: BoxFit.cover,
),
),
],
), ),
const SizedBox( const SizedBox(
height: 5, height: 10,
), ),
SelectableText( SelectableText(
"${item.ip}", "${item.ip}",
@@ -84,23 +97,32 @@ class _LoginLogPageState extends ConsumerState<LoginLogPage>
fontSize: 14, fontSize: 14,
), ),
), ),
const SizedBox(
height: 10,
),
], ],
), ),
trailing: item.status == 0 const Spacer(),
? Icon( Text(
CupertinoIcons.checkmark_circle, Utils.formatMessageTime(item.timestamp ?? 0),
color: ref.watch(themeProvider).primaryColor, style: TextStyle(
size: 16, fontSize: 12,
) color: ref.watch(themeProvider).themeColor.descColor(),
: const Icon( ),
CupertinoIcons.clear_circled, ),
color: Colors.red, const SizedBox(
size: 16, width: 15,
), ),
), ],
); );
}, },
itemCount: list.length, itemCount: list.length,
separatorBuilder: (BuildContext context, int index) {
return const Divider(
indent: 15,
height: 1,
);
},
), ),
); );
} }

View File

@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/theme.dart';
@@ -58,7 +58,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"脚本管理", "脚本管理",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -91,7 +94,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"依赖管理", "依赖管理",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -126,7 +132,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"任务日志", "任务日志",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -166,7 +175,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"登录日志", "登录日志",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -207,7 +219,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"修改密码", "修改密码",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -220,6 +235,89 @@ class _OtherPageState extends ConsumerState<OtherPage> {
), ),
), ),
), ),
const Divider(
indent: 15,
),
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
Routes.routerSubscription,
);
},
behavior: HitTestBehavior.opaque,
child: Padding(
padding: const EdgeInsets.only(
top: 5,
bottom: 10,
left: 15,
right: 15,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"订阅管理",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
Routes.routerBackup,
);
},
behavior: HitTestBehavior.opaque,
child: Padding(
padding: const EdgeInsets.only(
top: 5,
bottom: 10,
left: 15,
right: 15,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"数据备份",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
], ],
), ),
), ),
@@ -251,7 +349,8 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"夜间模式", "夜间模式",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color:
ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -265,7 +364,6 @@ class _OtherPageState extends ConsumerState<OtherPage> {
], ],
), ),
), ),
const Divider( const Divider(
indent: 15, indent: 15,
), ),
@@ -288,7 +386,48 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"主题设置", "主题设置",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
size: 16,
),
],
),
),
),
const Divider(
indent: 15,
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(Routes.routeChangeAccount);
},
child: Padding(
padding: const EdgeInsets.only(
left: 15,
right: 15,
top: 5,
bottom: 5,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"切换账号",
style: TextStyle(
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -325,7 +464,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
Text( Text(
"关于", "关于",
style: TextStyle( style: TextStyle(
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16, fontSize: 16,
), ),
), ),
@@ -384,7 +526,8 @@ class _OtherPageState extends ConsumerState<OtherPage> {
), ),
onPressed: () { onPressed: () {
getIt<UserInfoViewModel>().updateToken(""); getIt<UserInfoViewModel>().updateToken("");
Navigator.of(context).pushReplacementNamed(Routes.routeLogin); Navigator.of(context)
.pushReplacementNamed(Routes.routeLogin);
}, },
), ),
], ],

View File

@@ -0,0 +1,186 @@
import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:highlight/languages/json.dart';
import 'package:highlight/languages/powershell.dart';
import 'package:highlight/languages/python.dart';
import 'package:highlight/languages/vbscript-html.dart';
import 'package:highlight/languages/yaml.dart';
import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/base/sp_const.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/utils/extension.dart';
import 'package:qinglong_app/utils/sp_utils.dart';
class ScriptAddPage extends ConsumerStatefulWidget {
final String title;
final String path;
const ScriptAddPage(this.title, this.path, {Key? key}) : super(key: key);
@override
ConsumerState createState() => _ScriptAddPageState();
}
class _ScriptAddPageState extends ConsumerState<ScriptAddPage> {
CodeController? _codeController;
late String result;
FocusNode focusNode = FocusNode();
late String preResult;
@override
void dispose() {
_codeController?.dispose();
super.dispose();
}
@override
void initState() {
result = "## created by 青龙客户端 ${DateTime.now().toString()}\n\n";
preResult = result;
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
focusNode.requestFocus();
});
}
getLanguageType(String title) {
if (title.endsWith(".js")) {
return javascript;
}
if (title.endsWith(".sh")) {
return powershell;
}
if (title.endsWith(".py")) {
return python;
}
if (title.endsWith(".json")) {
return json;
}
if (title.endsWith(".yaml")) {
return yaml;
}
return vbscriptHtml;
}
@override
Widget build(BuildContext context) {
_codeController ??= CodeController(
text: result,
language: getLanguageType(widget.title),
onChange: (value) {
result = value;
},
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
stringMap: {
"export": const TextStyle(fontWeight: FontWeight.normal, color: Color(0xff6B2375)),
},
);
return Scaffold(
appBar: QlAppBar(
canBack: true,
backCall: () {
FocusManager.instance.primaryFocus?.unfocus();
if (preResult == result) {
Navigator.of(context).pop();
} else {
showCupertinoDialog(
context: context,
useRootNavigator: false,
builder: (childContext) => CupertinoAlertDialog(
title: const Text("温馨提示"),
content: const Text("你新增的内容还没用提交,确定退出吗?"),
actions: [
CupertinoDialogAction(
child: const Text(
"取消",
style: TextStyle(
color: Color(0xff999999),
),
),
onPressed: () {
Navigator.of(childContext).pop();
},
),
CupertinoDialogAction(
child: Text(
"确定",
style: TextStyle(
color: ref.watch(themeProvider).primaryColor,
),
),
onPressed: () {
Navigator.of(childContext).pop();
Navigator.of(context).pop();
},
),
],
),
);
}
},
title: '新增${widget.title}',
actions: [
InkWell(
onTap: () async {
try {
HttpResponse<NullResponse> response = await Api.addScript(
widget.title,
widget.path,
result,
);
if (response.success) {
"提交成功".toast();
Navigator.of(context).pop(true);
} else {
(response.message ?? "").toast();
}
} catch (e) {}
},
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 15,
),
child: Center(
child: Text(
"提交",
style: TextStyle(
fontSize: 16,
),
),
),
),
)
],
),
body: SafeArea(
top: false,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: SpUtil.getBool(spShowLine, defValue: false) ? 0 : 10,
),
child: CodeField(
controller: _codeController!,
expands: true,
wrap: SpUtil.getBool(spShowLine, defValue: false) ? false : true,
hideColumn: !SpUtil.getBool(spShowLine, defValue: false),
lineNumberStyle: LineNumberStyle(
textStyle: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,154 @@
import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:highlight/languages/json.dart';
import 'package:highlight/languages/powershell.dart';
import 'package:highlight/languages/python.dart';
import 'package:highlight/languages/vbscript-html.dart';
import 'package:highlight/languages/yaml.dart';
import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/base/sp_const.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/utils/sp_utils.dart';
/// @author NewTab
class ScriptCodeDetailPage extends ConsumerStatefulWidget {
final String title;
final String content;
const ScriptCodeDetailPage({
Key? key,
required this.title,
required this.content,
}) : super(key: key);
@override
ScriptCodeDetailPageState createState() => ScriptCodeDetailPageState();
}
class ScriptCodeDetailPageState extends ConsumerState<ScriptCodeDetailPage> {
CodeController? _codeController;
GlobalKey<CodeFieldState> codeFieldKey = GlobalKey();
bool buttonshow = false;
void scrollToTop() {
codeFieldKey.currentState?.getCodeScroll()?.animateTo(0,
duration: const Duration(milliseconds: 200), curve: Curves.linear);
}
void floatingButtonVisibility() {
double y = codeFieldKey.currentState?.getCodeScroll()?.offset ?? 0;
if (y > MediaQuery.of(context).size.height / 2) {
if (buttonshow == true) return;
setState(() {
buttonshow = true;
});
} else {
if (buttonshow == false) return;
setState(() {
buttonshow = false;
});
}
}
String suffix = "\n\n\n";
@override
void dispose() {
_codeController?.dispose();
_codeController = null;
super.dispose();
}
getLanguageType(String title) {
if (title.endsWith(".js")) {
return javascript;
}
if (title.endsWith(".sh")) {
return powershell;
}
if (title.endsWith(".py")) {
return python;
}
if (title.endsWith(".json")) {
return json;
}
if (title.endsWith(".yaml")) {
return yaml;
}
return vbscriptHtml;
}
late String content;
@override
void initState() {
content = widget.content;
super.initState();
}
@override
Widget build(BuildContext context) {
_codeController ??= CodeController(
text: (content) + suffix,
language: getLanguageType(widget.title),
onChange: (value) {
content = value + suffix;
},
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
stringMap: {
"export": const TextStyle(
fontWeight: FontWeight.normal, color: Color(0xff6B2375)),
},
);
return Scaffold(
floatingActionButton: Visibility(
visible: buttonshow,
child: FloatingActionButton(
mini: true,
onPressed: () {
scrollToTop();
},
elevation: 2,
backgroundColor: Colors.white,
child: const Icon(CupertinoIcons.up_arrow),
),
),
appBar: QlAppBar(
canBack: true,
backCall: () {
Navigator.of(context).pop();
},
title: widget.title,
),
body: SafeArea(
top: false,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: SpUtil.getBool(spShowLine, defValue: false) ? 0 : 10,
),
child: CodeField(
key: codeFieldKey,
controller: _codeController!,
expands: true,
readOnly: true,
wrap: SpUtil.getBool(spShowLine, defValue: false) ? false : true,
hideColumn: !SpUtil.getBool(spShowLine, defValue: false),
lineNumberStyle: LineNumberStyle(
textStyle: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
background: Colors.white,
),
),
),
);
}
}

View File

@@ -1,20 +1,22 @@
import 'dart:ui'; import 'package:code_text_field/code_text_field.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:highlight/languages/json.dart';
import 'package:highlight/languages/powershell.dart';
import 'package:highlight/languages/python.dart';
import 'package:highlight/languages/vbscript-html.dart';
import 'package:highlight/languages/yaml.dart';
import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/ql_app_bar.dart'; import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/sp_const.dart';
import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/theme.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:qinglong_app/base/ui/lazy_load_state.dart'; import 'package:qinglong_app/base/ui/lazy_load_state.dart';
import 'package:qinglong_app/utils/extension.dart'; import 'package:qinglong_app/utils/extension.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:qinglong_app/utils/sp_utils.dart';
import '../../../base/ui/syntax_highlighter.dart';
import '../../config/config_page.dart';
/// @author NewTab /// @author NewTab
class ScriptDetailPage extends ConsumerStatefulWidget { class ScriptDetailPage extends ConsumerStatefulWidget {
@@ -34,8 +36,61 @@ class ScriptDetailPage extends ConsumerStatefulWidget {
class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage> class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
with LazyLoadState<ScriptDetailPage> { with LazyLoadState<ScriptDetailPage> {
String? content; String? content;
CodeController? _codeController;
GlobalKey<CodeFieldState> codeFieldKey = GlobalKey();
List<Widget> actions = []; List<Widget> actions = [];
bool buttonshow = false;
void scrollToTop() {
codeFieldKey.currentState?.getCodeScroll()?.animateTo(0,
duration: const Duration(milliseconds: 200), curve: Curves.linear);
}
void floatingButtonVisibility() {
double y = codeFieldKey.currentState?.getCodeScroll()?.offset ?? 0;
if (y > MediaQuery.of(context).size.height / 2) {
if (buttonshow == true) return;
setState(() {
buttonshow = true;
});
} else {
if (buttonshow == false) return;
setState(() {
buttonshow = false;
});
}
}
String suffix = "\n\n\n";
@override
void dispose() {
_codeController?.dispose();
_codeController = null;
super.dispose();
}
getLanguageType(String title) {
if (title.endsWith(".js")) {
return javascript;
}
if (title.endsWith(".sh")) {
return powershell;
}
if (title.endsWith(".py")) {
return python;
}
if (title.endsWith(".json")) {
return json;
}
if (title.endsWith(".yaml")) {
return yaml;
}
return vbscriptHtml;
}
@override @override
void initState() { void initState() {
@@ -85,6 +140,7 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
Navigator.of(context).pop(); Navigator.of(context).pop();
showCupertinoDialog( showCupertinoDialog(
useRootNavigator: false,
context: context, context: context,
builder: (context) => CupertinoAlertDialog( builder: (context) => CupertinoAlertDialog(
title: const Text("确认删除"), title: const Text("确认删除"),
@@ -147,18 +203,45 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (content != null) {
_codeController ??= CodeController(
text: (content ?? "") + suffix,
language: getLanguageType(widget.title),
onChange: (value) {
content = value + suffix;
},
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
stringMap: {
"export": const TextStyle(
fontWeight: FontWeight.normal, color: Color(0xff6B2375)),
},
);
}
return Scaffold( return Scaffold(
floatingActionButton: Visibility(
visible: buttonshow,
child: FloatingActionButton(
mini: true,
onPressed: () {
scrollToTop();
},
elevation: 2,
backgroundColor: Colors.white,
child: const Icon(CupertinoIcons.up_arrow),
),
),
appBar: QlAppBar( appBar: QlAppBar(
canBack: true, canBack: true,
backCall: () { backCall: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
title: "脚本详情", title: widget.title,
actions: [ actions: [
InkWell( InkWell(
onTap: () { onTap: () {
showCupertinoModalPopup( showCupertinoModalPopup(
context: context, context: context,
useRootNavigator: false,
builder: (context) { builder: (context) {
return CupertinoActionSheet( return CupertinoActionSheet(
title: Container( title: Container(
@@ -219,8 +302,31 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
? const Center( ? const Center(
child: CupertinoActivityIndicator(), child: CupertinoActivityIndicator(),
) )
: CodeWidget( : SafeArea(
content: content ?? "", top: false,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal:
SpUtil.getBool(spShowLine, defValue: false) ? 0 : 10,
),
child: CodeField(
key: codeFieldKey,
controller: _codeController!,
expands: true,
readOnly: true,
wrap: SpUtil.getBool(spShowLine, defValue: false)
? false
: true,
hideColumn: !SpUtil.getBool(spShowLine, defValue: false),
lineNumberStyle: LineNumberStyle(
textStyle: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
background: Colors.white,
),
),
), ),
); );
} }
@@ -234,32 +340,21 @@ class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
if (response.success) { if (response.success) {
content = response.bean; content = response.bean;
setState(() {}); setState(() {});
Future.delayed(
const Duration(
seconds: 1,
),
() {
codeFieldKey.currentState
?.getCodeScroll()
?.addListener(floatingButtonVisibility);
},
);
} else { } else {
response.message?.toast(); response.message?.toast();
} }
} }
getLanguageType(String title) {
if (title.endsWith(".js")) {
return "js";
}
if (title.endsWith(".sh")) {
return "sh";
}
if (title.endsWith(".py")) {
return "py";
}
if (title.endsWith(".json")) {
return "json";
}
if (title.endsWith(".yaml")) {
return "yaml";
}
return "html";
}
@override @override
void onLazyLoad() { void onLazyLoad() {
loadData(); loadData();

Some files were not shown because too many files have changed in this diff Show More