深色模式、首页设置页面和功能优化

This commit is contained in:
Developer
2026-04-02 07:06:55 +08:00
parent f0a62ed68b
commit 954d173329
88 changed files with 12157 additions and 7578 deletions

View File

@@ -1,9 +1,11 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../constants/app_constants.dart';
import '../../controllers/history_controller.dart';
import '../../services/network_listener_service.dart';
import '../../services/get/theme_controller.dart';
/// 时间: 2026-03-26
/// 功能: 笔记编辑页面
@@ -24,6 +26,7 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
final TextEditingController _contentController = TextEditingController();
final FocusNode _titleFocusNode = FocusNode();
final FocusNode _contentFocusNode = FocusNode();
final ThemeController _themeController = Get.find<ThemeController>();
String? _currentNoteId;
DateTime? _lastSavedTime;
@@ -279,10 +282,10 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
horizontal: 16,
),
decoration: BoxDecoration(
color: AppConstants.primaryColor.withOpacity(0.1),
color: AppConstants.primaryColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppConstants.primaryColor.withOpacity(0.3),
color: AppConstants.primaryColor.withValues(alpha: 0.3),
),
),
child: Row(
@@ -550,113 +553,146 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: AppConstants.primaryColor),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
_currentNoteId == null ? '新建笔记' : '编辑笔记',
style: const TextStyle(
color: Colors.black87,
fontWeight: FontWeight.w600,
return Obx(() {
final isDark = _themeController.isDarkMode;
return Scaffold(
backgroundColor: isDark
? const Color(0xFF1A1A1A)
: Theme.of(context).scaffoldBackgroundColor,
appBar: AppBar(
backgroundColor: isDark ? const Color(0xFF2A2A2A) : Colors.white,
elevation: 0,
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: isDark ? Colors.white70 : AppConstants.primaryColor,
),
onPressed: () => Navigator.of(context).pop(),
),
),
actions: [
// 删除按钮(仅编辑时显示)
if (_currentNoteId != null)
title: Text(
_currentNoteId == null ? '新建笔记' : '编辑笔记',
style: TextStyle(
color: isDark ? Colors.white : Colors.black87,
fontWeight: FontWeight.w600,
),
),
actions: [
if (_currentNoteId != null)
IconButton(
icon: Icon(
Icons.delete_outline,
color: isDark ? Colors.red[300] : Colors.red[400],
),
onPressed: _showDeleteDialog,
tooltip: '删除笔记',
),
IconButton(
icon: Icon(Icons.delete_outline, color: Colors.red[400]),
onPressed: _showDeleteDialog,
tooltip: '删除笔记',
icon: Icon(
_isLocked ? Icons.lock : Icons.lock_outline,
color: _isLocked
? AppConstants.primaryColor
: (isDark ? Colors.grey[400] : Colors.grey[600]),
),
onPressed: _showPasswordDialog,
tooltip: _isLocked ? '修改密码' : '设置密码',
),
// 锁定按钮
IconButton(
icon: Icon(
_isLocked ? Icons.lock : Icons.lock_outline,
color: _isLocked ? AppConstants.primaryColor : Colors.grey[600],
IconButton(
icon: Icon(
_isPinned ? Icons.push_pin : Icons.push_pin_outlined,
color: _isPinned
? AppConstants.primaryColor
: (isDark ? Colors.grey[400] : Colors.grey[600]),
),
onPressed: _togglePin,
tooltip: _isPinned ? '取消置顶' : '置顶',
),
onPressed: _showPasswordDialog,
tooltip: _isLocked ? '修改密码' : '设置密码',
),
// 置顶按钮
IconButton(
icon: Icon(
_isPinned ? Icons.push_pin : Icons.push_pin_outlined,
color: _isPinned ? AppConstants.primaryColor : Colors.grey[600],
),
onPressed: _togglePin,
tooltip: _isPinned ? '取消置顶' : '置顶',
),
],
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: GestureDetector(
onTap: () {
// 点击非输入框区域取消焦点
_titleFocusNode.unfocus();
_contentFocusNode.unfocus();
},
child: Column(
children: [
_buildStatusBar(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
_buildTitleInput(),
const SizedBox(height: 16),
_buildContentInput(),
],
],
),
body: _isLoading
? Center(
child: CircularProgressIndicator(
color: isDark ? Colors.white : AppConstants.primaryColor,
),
)
: GestureDetector(
onTap: () {
_titleFocusNode.unfocus();
_contentFocusNode.unfocus();
},
child: Column(
children: [
_buildStatusBar(isDark),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
_buildTitleInput(isDark),
const SizedBox(height: 16),
_buildContentInput(isDark),
],
),
),
),
),
],
],
),
),
),
);
);
});
}
Widget _buildStatusBar() {
Widget _buildStatusBar(bool isDark) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: Colors.grey[50],
color: isDark ? const Color(0xFF2A2A2A) : Colors.grey[50],
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
// 创建时间
Icon(Icons.add_circle_outline, size: 14, color: Colors.grey[500]),
Icon(
Icons.add_circle_outline,
size: 14,
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
const SizedBox(width: 4),
Text(
_createTime != null ? '创建 ${_formatDate(_createTime!)}' : '新笔记',
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
),
const SizedBox(width: 16),
// 保存时间
Icon(Icons.access_time, size: 14, color: Colors.grey[500]),
Icon(
Icons.access_time,
size: 14,
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
const SizedBox(width: 4),
Text(
_lastSavedTime != null
? '保存 ${_formatDateTime(_lastSavedTime!)}'
: '未保存',
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
),
const SizedBox(width: 16),
// 字数
Icon(Icons.text_fields, size: 14, color: Colors.grey[500]),
Icon(
Icons.text_fields,
size: 14,
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
const SizedBox(width: 4),
Text(
'$_charCount',
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
style: TextStyle(
fontSize: 12,
color: isDark ? Colors.grey[400] : Colors.grey[500],
),
),
if (_isPinned) ...[
const SizedBox(width: 16),
@@ -740,23 +776,27 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
);
}
Widget _buildTitleInput() {
Widget _buildTitleInput(bool isDark) {
return Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: _titleFocusNode.hasFocus
? AppConstants.primaryColor.withValues(alpha: 0.5)
: Colors.grey.withValues(alpha: 0.2),
: (isDark
? Colors.grey[700]!
: Colors.grey.withValues(alpha: 0.2)),
width: 1.5,
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
color: isDark
? Colors.black.withValues(alpha: 0.2)
: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@@ -768,23 +808,30 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
maxLines: 1,
decoration: InputDecoration(
hintText: '标题(可选)',
hintStyle: TextStyle(color: Colors.grey[400]),
hintStyle: TextStyle(
color: isDark ? Colors.grey[500] : Colors.grey[400],
),
border: InputBorder.none,
contentPadding: const EdgeInsets.all(16),
),
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: isDark ? Colors.white : Colors.black87,
),
),
),
),
const SizedBox(width: 12),
// 分类选择
Container(
decoration: BoxDecoration(
color: Colors.white,
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
color: isDark
? Colors.black.withValues(alpha: 0.2)
: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@@ -797,7 +844,6 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
: null,
onSelected: (value) async {
if (value == _customCategoryKey) {
// 弹出自定义分类输入框
await _showCustomCategoryDialog();
} else {
setState(() {
@@ -819,13 +865,17 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
color: AppConstants.primaryColor,
),
if (category == _category) const SizedBox(width: 8),
Text(category),
Text(
category,
style: TextStyle(
color: isDark ? Colors.white : Colors.black87,
),
),
],
),
);
}).toList();
// 添加自定义分类选项
items.add(
PopupMenuItem(
value: _customCategoryKey,
@@ -843,9 +893,18 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
_category != null &&
_category!.isNotEmpty)
const SizedBox(width: 8),
Icon(Icons.edit, size: 16, color: Colors.grey[600]),
Icon(
Icons.edit,
size: 16,
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
const SizedBox(width: 8),
Text('自定义', style: TextStyle(color: Colors.grey[600])),
Text(
'自定义',
style: TextStyle(
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
),
],
),
),
@@ -874,7 +933,7 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey[600],
color: isDark ? Colors.grey[400] : Colors.grey[600],
),
],
),
@@ -885,21 +944,25 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
);
}
Widget _buildContentInput() {
Widget _buildContentInput(bool isDark) {
return Container(
constraints: const BoxConstraints(minHeight: 300),
decoration: BoxDecoration(
color: Colors.white,
color: isDark ? const Color(0xFF2A2A2A) : Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: _contentFocusNode.hasFocus
? AppConstants.primaryColor.withValues(alpha: 0.5)
: Colors.grey.withValues(alpha: 0.2),
: (isDark
? Colors.grey[700]!
: Colors.grey.withValues(alpha: 0.2)),
width: 1.5,
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
color: isDark
? Colors.black.withValues(alpha: 0.2)
: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@@ -912,11 +975,17 @@ class _CollectNotesPageState extends State<CollectNotesPage> {
minLines: 12,
decoration: InputDecoration(
hintText: '开始写笔记...',
hintStyle: TextStyle(color: Colors.grey[400]),
hintStyle: TextStyle(
color: isDark ? Colors.grey[500] : Colors.grey[400],
),
border: InputBorder.none,
contentPadding: const EdgeInsets.all(16),
),
style: const TextStyle(fontSize: 16, height: 1.5),
style: TextStyle(
fontSize: 16,
height: 1.5,
color: isDark ? Colors.white : Colors.black87,
),
),
);
}