优化暗黑体验

This commit is contained in:
jyuesong
2022-01-19 16:38:02 +08:00
parent 4fe730d414
commit fe3e0f1d50
4 changed files with 147 additions and 130 deletions

View File

@@ -5,6 +5,7 @@
* 环境变量列表使用体验优化 * 环境变量列表使用体验优化
* 部分页面进入卡顿优化 * 部分页面进入卡顿优化
* 扩大任务的搜索范围 * 扩大任务的搜索范围
* 优化暗黑主题
## 1.0.0 ## 1.0.0

View File

@@ -13,13 +13,14 @@ get primaryColor => _primaryColor;
class ThemeViewModel extends ChangeNotifier { class ThemeViewModel extends ChangeNotifier {
ThemeData currentTheme = lightTheme; ThemeData currentTheme = lightTheme;
bool _isInDarkMode = false;
ThemeColors themeColor = LightThemeColors(); ThemeColors themeColor = LightThemeColors();
ThemeViewModel() { ThemeViewModel() {
var brightness = SchedulerBinding.instance!.window.platformBrightness; var brightness = SchedulerBinding.instance!.window.platformBrightness;
bool isDarkMode = brightness == Brightness.dark; _isInDarkMode = brightness == Brightness.dark;
changeThemeReal(isDarkMode, false); changeThemeReal(_isInDarkMode, false);
} }
bool isInDartMode() { bool isInDartMode() {
@@ -27,6 +28,7 @@ class ThemeViewModel extends ChangeNotifier {
} }
void changeThemeReal(bool dark, [bool notify = true]) { void changeThemeReal(bool dark, [bool notify = true]) {
_isInDarkMode = dark;
SpUtil.putBool(spTheme, dark); SpUtil.putBool(spTheme, dark);
if (!dark) { if (!dark) {
currentTheme = lightTheme; currentTheme = lightTheme;
@@ -40,6 +42,8 @@ class ThemeViewModel extends ChangeNotifier {
} }
} }
get darkMode => _isInDarkMode;
void changeTheme() { void changeTheme() {
changeThemeReal(!SpUtil.getBool(spTheme, defValue: false), true); changeThemeReal(!SpUtil.getBool(spTheme, defValue: false), true);
} }
@@ -243,7 +247,7 @@ class DartThemeColors extends ThemeColors {
@override @override
Color settingBgColor() { Color settingBgColor() {
return Colors.black12; return Colors.black;
} }
@override @override

View File

@@ -12,8 +12,9 @@ import '../task_viewmodel.dart';
class TaskDetailPage extends ConsumerStatefulWidget { class TaskDetailPage extends ConsumerStatefulWidget {
final TaskBean taskBean; final TaskBean taskBean;
final bool hideAppbar;
const TaskDetailPage(this.taskBean, {Key? key}) : super(key: key); const TaskDetailPage(this.taskBean, {Key? key, this.hideAppbar = false}) : super(key: key);
@override @override
_TaskDetailPageState createState() => _TaskDetailPageState(); _TaskDetailPageState createState() => _TaskDetailPageState();
@@ -29,6 +30,123 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget body = Material(
color: Colors.transparent,
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: SingleChildScrollView(
child: Column(
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15,
),
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
),
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
borderRadius: BorderRadius.circular(15),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TaskDetailCell(
title: "名称",
desc: widget.taskBean.name ?? "",
),
TaskDetailCell(
title: "ID",
desc: widget.taskBean.sId ?? "",
),
TaskDetailCell(
title: "任务",
desc: widget.taskBean.command ?? "",
),
TaskDetailCell(
title: "创建时间",
desc: Utils.formatMessageTime(widget.taskBean.created ?? 0),
),
TaskDetailCell(
title: "更新时间",
desc: Utils.formatGMTTime(widget.taskBean.timestamp ?? ""),
),
TaskDetailCell(
title: "任务定时",
desc: widget.taskBean.schedule ?? "",
),
TaskDetailCell(
title: "最后运行时间",
desc: Utils.formatMessageTime(widget.taskBean.lastExecutionTime ?? 0),
),
TaskDetailCell(
title: "最后运行时长",
desc: widget.taskBean.lastRunningTime == null ? "-" : "${widget.taskBean.lastRunningTime ?? "-"}",
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
showLog();
},
child: TaskDetailCell(
title: "日志路径",
desc: widget.taskBean.logPath ?? "-",
taped: () {
showLog();
},
),
),
TaskDetailCell(
title: "运行状态",
desc: widget.taskBean.status == 0 ? "正在运行" : "空闲",
),
TaskDetailCell(
title: "脚本状态",
desc: widget.taskBean.isDisabled == 1 ? "已禁用" : "已启用",
),
TaskDetailCell(
title: "是否置顶",
desc: widget.taskBean.isPinned == 1 ? "已置顶" : "未置顶",
hideDivide: true,
),
],
),
),
widget.hideAppbar
? const SizedBox.shrink()
: SizedBox(
width: MediaQuery.of(context).size.width - 80,
child: CupertinoButton(
padding: const EdgeInsets.symmetric(
vertical: 5,
),
color: Colors.red,
child: const Text(
"删 除",
style: TextStyle(
fontSize: 16,
),
),
onPressed: () {
delTask(context, ref);
}),
),
const SizedBox(
height: 15,
),
],
),
),
),
);
if (widget.hideAppbar) {
return body;
}
actions.clear(); actions.clear();
actions.addAll( actions.addAll(
[ [
@@ -146,6 +264,7 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
), ),
], ],
); );
return Scaffold( return Scaffold(
appBar: QlAppBar( appBar: QlAppBar(
canBack: true, canBack: true,
@@ -213,106 +332,7 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
) )
], ],
), ),
body: SingleChildScrollView( body: body,
child: Column(
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 15,
),
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
),
decoration: BoxDecoration(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
borderRadius: BorderRadius.circular(15),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TaskDetailCell(
title: "ID",
desc: widget.taskBean.sId ?? "",
),
TaskDetailCell(
title: "任务",
desc: widget.taskBean.command ?? "",
),
TaskDetailCell(
title: "创建时间",
desc: Utils.formatMessageTime(widget.taskBean.created ?? 0),
),
TaskDetailCell(
title: "更新时间",
desc: Utils.formatGMTTime(widget.taskBean.timestamp ?? ""),
),
TaskDetailCell(
title: "任务定时",
desc: widget.taskBean.schedule ?? "",
),
TaskDetailCell(
title: "最后运行时间",
desc: Utils.formatMessageTime(widget.taskBean.lastExecutionTime ?? 0),
),
TaskDetailCell(
title: "最后运行时长",
desc: widget.taskBean.lastRunningTime == null ? "-" : "${widget.taskBean.lastRunningTime ?? "-"}",
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
showLog();
},
child: TaskDetailCell(
title: "日志路径",
desc: widget.taskBean.logPath ?? "-",
taped: () {
showLog();
},
),
),
TaskDetailCell(
title: "运行状态",
desc: widget.taskBean.status == 0 ? "正在运行" : "空闲",
),
TaskDetailCell(
title: "脚本状态",
desc: widget.taskBean.isDisabled == 1 ? "已禁用" : "已启用",
),
TaskDetailCell(
title: "是否置顶",
desc: widget.taskBean.isPinned == 1 ? "已置顶" : "未置顶",
hideDivide: true,
),
],
),
),
SizedBox(
width: MediaQuery.of(context).size.width - 80,
child: CupertinoButton(
padding: const EdgeInsets.symmetric(
vertical: 5,
),
color: Colors.red,
child: const Text(
"删 除",
style: TextStyle(
fontSize: 16,
),
),
onPressed: () {
delTask(context, ref);
}),
),
const SizedBox(
height: 15,
),
],
),
),
); );
} }

View File

@@ -12,6 +12,7 @@ import 'package:qinglong_app/base/ui/menu.dart';
import 'package:qinglong_app/base/ui/ql_context_menu.dart'; import 'package:qinglong_app/base/ui/ql_context_menu.dart';
import 'package:qinglong_app/module/task/intime_log/intime_log_page.dart'; import 'package:qinglong_app/module/task/intime_log/intime_log_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_viewmodel.dart'; import 'package:qinglong_app/module/task/task_viewmodel.dart';
import 'package:qinglong_app/utils/utils.dart'; import 'package:qinglong_app/utils/utils.dart';
@@ -224,33 +225,24 @@ class TaskItemCell extends StatelessWidget {
), ),
], ],
previewBuilder: (context, anima, child) { previewBuilder: (context, anima, child) {
return IntrinsicWidth( bool isDark = ref.watch(themeProvider).darkMode;
child: Row( return ClipRRect(
mainAxisSize: MainAxisSize.min, borderRadius: BorderRadius.circular(15),
children: [ child: Container(
Material( color: isDark ? const Color(0xff333333) : Theme.of(context).scaffoldBackgroundColor,
color: Colors.transparent, padding: EdgeInsets.only(
child: Text( left: 5,
bean.name ?? "", right: 5,
maxLines: 1, top: 5,
style: TextStyle( bottom: isDark ? 5 : 20,
overflow: TextOverflow.ellipsis, ),
color: ref.watch(themeProvider).themeColor.titleColor(), child: ClipRRect(
fontSize: 18, borderRadius: BorderRadius.circular(15),
), child: TaskDetailPage(
), bean,
hideAppbar: true,
), ),
const SizedBox( ),
width: 5,
),
bean.isDisabled == 1
? const Icon(
Icons.dnd_forwardslash,
size: 16,
color: Colors.red,
)
: const SizedBox.shrink(),
],
), ),
); );
}, },