generated from dellevin/template
编辑界面优化
This commit is contained in:
@@ -296,7 +296,7 @@ class Note {
|
|||||||
final String id;
|
final String id;
|
||||||
final String title;
|
final String title;
|
||||||
final String content;
|
final String content;
|
||||||
final String contentType; // markdown / plain_text
|
final String contentType; // 内容类型(markdown)
|
||||||
final List<String> tags;
|
final List<String> tags;
|
||||||
final List<String> images; // 图片路径列表
|
final List<String> images; // 图片路径列表
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
|
|||||||
@@ -110,12 +110,15 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
|
|
||||||
/// 构建右下角悬浮按钮组
|
/// 构建右下角悬浮按钮组
|
||||||
Widget _buildFloatingActionButtons(Book book) {
|
Widget _buildFloatingActionButtons(Book book) {
|
||||||
final hasCover = book.coverPath != null && book.coverPath!.isNotEmpty;
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// 删除按钮
|
_buildFloatingButton(
|
||||||
|
icon: Icons.edit_outlined,
|
||||||
|
onPressed: () => _navigateToEdit(context),
|
||||||
|
tooltip: '编辑',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
_buildFloatingButton(
|
_buildFloatingButton(
|
||||||
icon: Icons.delete_outline,
|
icon: Icons.delete_outline,
|
||||||
onPressed: () => _showDeleteDialog(context),
|
onPressed: () => _showDeleteDialog(context),
|
||||||
@@ -123,23 +126,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
// 清空封面按钮(仅当有封面时显示)
|
|
||||||
if (hasCover) ...[
|
|
||||||
_buildFloatingButton(
|
|
||||||
icon: Icons.hide_image_outlined,
|
|
||||||
onPressed: () => _showClearCoverDialog(book),
|
|
||||||
tooltip: '清空封面',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
// 编辑按钮
|
|
||||||
_buildFloatingButton(
|
|
||||||
icon: Icons.edit_outlined,
|
|
||||||
onPressed: () => _navigateToEdit(context),
|
|
||||||
tooltip: '编辑',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
// 分享按钮
|
|
||||||
_buildFloatingButton(
|
_buildFloatingButton(
|
||||||
icon: Icons.share_outlined,
|
icon: Icons.share_outlined,
|
||||||
onPressed: () => _showSharePoster(book),
|
onPressed: () => _showSharePoster(book),
|
||||||
@@ -796,67 +782,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 显示清空封面对话框
|
|
||||||
void _showClearCoverDialog(Book book) {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => AlertDialog(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
||||||
title: const Text(
|
|
||||||
'清空封面',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
content: const Text(
|
|
||||||
'确定要清空封面吗?清空后将使用默认占位图。',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: const Color(0xFF666666),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('取消'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
Navigator.pop(context);
|
|
||||||
final updatedBook = book.copyWith(
|
|
||||||
coverPath: null,
|
|
||||||
updatedAt: DateTime.now(),
|
|
||||||
);
|
|
||||||
await context.read<AppProvider>().updateBook(updatedBook);
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '封面已清空');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('清空'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 下载封面到本地
|
/// 下载封面到本地
|
||||||
Future<void> _downloadCover(Book book) async {
|
Future<void> _downloadCover(Book book) async {
|
||||||
if (book.coverPath == null || book.coverPath!.isEmpty) {
|
if (book.coverPath == null || book.coverPath!.isEmpty) {
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ class HomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> {
|
class _HomePageState extends State<HomePage> {
|
||||||
/// 当前正在滑动的页面索引(用于PageView)
|
|
||||||
final PageController _pageController = PageController();
|
final PageController _pageController = PageController();
|
||||||
|
bool _isSwitchingPage = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@@ -28,33 +28,36 @@ class _HomePageState extends State<HomePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
// 左侧弹出菜单(仅在主页显示)
|
|
||||||
drawer: context.watch<AppProvider>().bottomNavIndex == 0
|
drawer: context.watch<AppProvider>().bottomNavIndex == 0
|
||||||
? CustomDrawer()
|
? CustomDrawer()
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
// 主体内容
|
|
||||||
body: Consumer<AppProvider>(
|
body: Consumer<AppProvider>(
|
||||||
builder: (context, provider, child) {
|
builder: (context, provider, child) {
|
||||||
// 同步底部导航栏和 PageView 的页面
|
|
||||||
final currentPage = provider.bottomNavIndex == 0 ? 0 : 1;
|
final currentPage = provider.bottomNavIndex == 0 ? 0 : 1;
|
||||||
if (_pageController.hasClients && _pageController.page?.round() != currentPage) {
|
if (_pageController.hasClients && _pageController.page?.round() != currentPage) {
|
||||||
|
_isSwitchingPage = true;
|
||||||
_pageController.jumpToPage(currentPage);
|
_pageController.jumpToPage(currentPage);
|
||||||
|
// 切换完成后重置标记,确保导航栏显示
|
||||||
|
Future.delayed(const Duration(milliseconds: 300), () {
|
||||||
|
if (mounted) {
|
||||||
|
_isSwitchingPage = false;
|
||||||
|
provider.setBottomNavVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return NotificationListener<ScrollNotification>(
|
return NotificationListener<ScrollNotification>(
|
||||||
onNotification: (notification) {
|
onNotification: (notification) {
|
||||||
|
if (_isSwitchingPage) return false;
|
||||||
if (notification is ScrollUpdateNotification) {
|
if (notification is ScrollUpdateNotification) {
|
||||||
final delta = notification.scrollDelta;
|
final delta = notification.scrollDelta;
|
||||||
if (delta != null && delta.abs() > 2) {
|
if (delta != null && delta.abs() > 2) {
|
||||||
// 根据用户设置决定是否启用滚动隐藏
|
|
||||||
final userPrefs = UserPrefs();
|
final userPrefs = UserPrefs();
|
||||||
if (!userPrefs.hideBottomNavOnScroll) return false;
|
if (!userPrefs.hideBottomNavOnScroll) return false;
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
// 下拉(内容向下滚动)- 显示导航栏
|
|
||||||
provider.setBottomNavVisible(true);
|
provider.setBottomNavVisible(true);
|
||||||
} else {
|
} else {
|
||||||
// 上滑(内容向上滚动)- 隐藏导航栏
|
|
||||||
provider.setBottomNavVisible(false);
|
provider.setBottomNavVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,10 +66,8 @@ class _HomePageState extends State<HomePage> {
|
|||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
// 底层:主体内容(支持左右滑动切换)
|
|
||||||
_buildPageView(provider),
|
_buildPageView(provider),
|
||||||
|
|
||||||
// 底部导航栏(带动画)
|
|
||||||
Positioned(
|
Positioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
@@ -79,7 +80,6 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// 导航栏隐藏时的展开按钮
|
|
||||||
if (!provider.bottomNavVisible)
|
if (!provider.bottomNavVisible)
|
||||||
Positioned(
|
Positioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
@@ -126,11 +126,10 @@ class _HomePageState extends State<HomePage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建主体内容(使用 PageView 支持左右滑动切换)
|
|
||||||
Widget _buildPageView(AppProvider provider) {
|
Widget _buildPageView(AppProvider provider) {
|
||||||
return PageView(
|
return PageView(
|
||||||
controller: _pageController,
|
controller: _pageController,
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
onPageChanged: (index) {
|
onPageChanged: (index) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
provider.setBottomNavIndex(0);
|
provider.setBottomNavIndex(0);
|
||||||
|
|||||||
@@ -110,12 +110,15 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
|
|
||||||
/// 构建右下角悬浮按钮组
|
/// 构建右下角悬浮按钮组
|
||||||
Widget _buildFloatingActionButtons(Movie movie) {
|
Widget _buildFloatingActionButtons(Movie movie) {
|
||||||
final hasPoster = movie.posterPath != null && movie.posterPath!.isNotEmpty;
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// 删除按钮
|
_buildFloatingButton(
|
||||||
|
icon: Icons.edit_outlined,
|
||||||
|
onPressed: () => _navigateToEdit(context),
|
||||||
|
tooltip: '编辑',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
_buildFloatingButton(
|
_buildFloatingButton(
|
||||||
icon: Icons.delete_outline,
|
icon: Icons.delete_outline,
|
||||||
onPressed: () => _showDeleteDialog(context),
|
onPressed: () => _showDeleteDialog(context),
|
||||||
@@ -123,23 +126,6 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
// 清空海报按钮(仅当有海报时显示)
|
|
||||||
if (hasPoster) ...[
|
|
||||||
_buildFloatingButton(
|
|
||||||
icon: Icons.hide_image_outlined,
|
|
||||||
onPressed: () => _showClearPosterDialog(movie),
|
|
||||||
tooltip: '清空海报',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
// 编辑按钮
|
|
||||||
_buildFloatingButton(
|
|
||||||
icon: Icons.edit_outlined,
|
|
||||||
onPressed: () => _navigateToEdit(context),
|
|
||||||
tooltip: '编辑',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
// 分享按钮
|
|
||||||
_buildFloatingButton(
|
_buildFloatingButton(
|
||||||
icon: Icons.share_outlined,
|
icon: Icons.share_outlined,
|
||||||
onPressed: () => _showSharePoster(movie),
|
onPressed: () => _showSharePoster(movie),
|
||||||
@@ -244,67 +230,6 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 显示清空海报对话框
|
|
||||||
void _showClearPosterDialog(Movie movie) {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => AlertDialog(
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
||||||
title: const Text(
|
|
||||||
'清空海报',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
content: const Text(
|
|
||||||
'确定要清空海报吗?清空后将使用默认占位图。',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: const Color(0xFF666666),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('取消'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
Navigator.pop(context);
|
|
||||||
final updatedMovie = movie.copyWith(
|
|
||||||
posterPath: null,
|
|
||||||
updatedAt: DateTime.now(),
|
|
||||||
);
|
|
||||||
await context.read<AppProvider>().updateMovie(updatedMovie);
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '海报已清空');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('清空'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 构建基本信息
|
/// 构建基本信息
|
||||||
Widget _buildBasicInfo(Movie movie) {
|
Widget _buildBasicInfo(Movie movie) {
|
||||||
return Padding(
|
return Padding(
|
||||||
|
|||||||
@@ -450,6 +450,7 @@ class _MovieFormPageState extends State<MovieFormPage> {
|
|||||||
? ''
|
? ''
|
||||||
: '${_alternateTitles.length}个:${_alternateTitles.join('、')}',
|
: '${_alternateTitles.length}个:${_alternateTitles.join('、')}',
|
||||||
icon: Icons.alternate_email_outlined,
|
icon: Icons.alternate_email_outlined,
|
||||||
|
scrollHorizontal: true,
|
||||||
onTap: () => _showMultiValueDialog(
|
onTap: () => _showMultiValueDialog(
|
||||||
title: '添加别名',
|
title: '添加别名',
|
||||||
initialValues: _alternateTitles,
|
initialValues: _alternateTitles,
|
||||||
@@ -594,6 +595,7 @@ class _MovieFormPageState extends State<MovieFormPage> {
|
|||||||
IconData? icon,
|
IconData? icon,
|
||||||
double? height,
|
double? height,
|
||||||
bool scrollable = false,
|
bool scrollable = false,
|
||||||
|
bool scrollHorizontal = false,
|
||||||
}) {
|
}) {
|
||||||
final hasValue = value.isNotEmpty;
|
final hasValue = value.isNotEmpty;
|
||||||
|
|
||||||
@@ -614,6 +616,20 @@ class _MovieFormPageState extends State<MovieFormPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else if (scrollHorizontal) {
|
||||||
|
// 水平可滚动模式(别名等长文本使用)
|
||||||
|
return SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
|
child: Text(
|
||||||
|
hasValue ? value : '点击填写',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
color: hasValue ? const Color(0xFF1A1A1A) : const Color(0xFFCCCCCC),
|
||||||
|
fontWeight: hasValue ? FontWeight.w500 : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// 普通模式:只显示一行
|
// 普通模式:只显示一行
|
||||||
return Text(
|
return Text(
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../../providers/app_provider.dart';
|
import '../../providers/app_provider.dart';
|
||||||
import '../../models/data_models.dart';
|
import '../../models/data_models.dart';
|
||||||
import '../../utils/toast_util.dart';
|
import 'note_share_page.dart';
|
||||||
|
|
||||||
/// 笔记详情页 - 极简主义设计
|
/// 笔记详情页
|
||||||
class NoteDetailPage extends StatefulWidget {
|
class NoteDetailPage extends StatefulWidget {
|
||||||
final Note note;
|
final Note note;
|
||||||
|
|
||||||
@@ -17,9 +17,10 @@ class NoteDetailPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NoteDetailPageState extends State<NoteDetailPage> {
|
class _NoteDetailPageState extends State<NoteDetailPage> {
|
||||||
|
static const _weekdays = ['一', '二', '三', '四', '五', '六', '日'];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// 从 Provider 获取最新的笔记数据
|
|
||||||
final note = context.watch<AppProvider>().notes.firstWhere(
|
final note = context.watch<AppProvider>().notes.firstWhere(
|
||||||
(n) => n.id == widget.note.id,
|
(n) => n.id == widget.note.id,
|
||||||
orElse: () => widget.note,
|
orElse: () => widget.note,
|
||||||
@@ -29,24 +30,20 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
|
|||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(
|
title: Text(
|
||||||
note.title.isNotEmpty ? note.title : '无标题',
|
note.title.isNotEmpty
|
||||||
|
? note.title
|
||||||
|
: _truncateContent(note.content),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
),
|
),
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.edit_outlined),
|
|
||||||
onPressed: () => _navigateToEdit(context),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
body: Stack(
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
children: [
|
||||||
// 标签区域
|
Column(
|
||||||
if (note.tags.isNotEmpty)
|
children: [
|
||||||
|
// 日期 + 字数
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
border: Border(
|
border: Border(
|
||||||
bottom: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
bottom: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
||||||
@@ -54,238 +51,207 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
|
|||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Wrap(
|
Text(
|
||||||
spacing: 10,
|
'${note.createdAt.day}',
|
||||||
runSpacing: 10,
|
|
||||||
children: note.tags.map((tag) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFFAFAFA),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
tag,
|
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 30,
|
||||||
color: Color(0xFF666666),
|
fontWeight: FontWeight.w200,
|
||||||
|
color: Color(0xFF333333),
|
||||||
|
height: 1.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
const SizedBox(width: 8),
|
||||||
}).toList(),
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${note.createdAt.year}/${note.createdAt.month.toString().padLeft(2, '0')} 周${_weekdays[note.createdAt.weekday - 1]}',
|
||||||
|
style: const TextStyle(fontSize: 11, fontWeight: FontWeight.w500, color: Color(0xFF777777)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 1),
|
||||||
|
Text(
|
||||||
|
'${note.createdAt.hour.toString().padLeft(2, '0')}:${note.createdAt.minute.toString().padLeft(2, '0')}',
|
||||||
|
style: const TextStyle(fontSize: 11, color: Color(0xFF999999)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
Text(
|
||||||
|
'${note.content.length} 字',
|
||||||
|
style: const TextStyle(fontSize: 11, color: Color(0xFFAAAAAA)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// 内容区域 - Markdown 渲染
|
// 标签行
|
||||||
|
if (note.tags.isNotEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 6),
|
||||||
|
child: _buildTagRow(note.tags),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 内容
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _buildMarkdownContent(note),
|
child: Markdown(
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 构建 Markdown 内容
|
|
||||||
Widget _buildMarkdownContent(Note note) {
|
|
||||||
return Markdown(
|
|
||||||
data: note.content,
|
data: note.content,
|
||||||
styleSheet: _buildMarkdownStyleSheet(),
|
styleSheet: _buildMarkdownStyleSheet(),
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
// TODO: migrate to sizedImageBuilder when flutter_markdown is updated
|
|
||||||
// ignore: deprecated_member_use
|
// ignore: deprecated_member_use
|
||||||
imageBuilder: (uri, title, alt) => _buildMarkdownImage(uri),
|
imageBuilder: (uri, title, alt) => _buildMarkdownImage(uri, note),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 图片行
|
||||||
|
if (note.images.isNotEmpty) _buildImageRow(note.images),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
// 右下角悬浮按钮组
|
||||||
|
Positioned(
|
||||||
|
right: 16,
|
||||||
|
bottom: 24,
|
||||||
|
child: _buildFloatingActionButtons(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTagRow(List<String> tags) {
|
||||||
|
return Container(
|
||||||
|
height: 28,
|
||||||
|
margin: const EdgeInsets.only(bottom: 2),
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
itemCount: tags.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 6),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFF5F5F5),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
tags[index],
|
||||||
|
style: const TextStyle(fontSize: 11, color: Color(0xFF666666)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildImageRow(List<String> images) {
|
||||||
|
return Container(
|
||||||
|
height: 80,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
border: const Border(
|
||||||
|
top: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
||||||
|
),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.03),
|
||||||
|
blurRadius: 6,
|
||||||
|
offset: const Offset(0, -2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
itemCount: images.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 8),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: () => _showImagePreview(images, index),
|
||||||
|
child: Container(
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: Image.file(
|
||||||
|
File(images[index]),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
errorBuilder: (_, __, ___) => Container(
|
||||||
|
color: const Color(0xFFF5F5F5),
|
||||||
|
child: const Icon(Icons.broken_image_outlined, size: 20, color: Color(0xFFCCCCCC)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建 Markdown 样式表
|
|
||||||
MarkdownStyleSheet _buildMarkdownStyleSheet() {
|
MarkdownStyleSheet _buildMarkdownStyleSheet() {
|
||||||
return MarkdownStyleSheet(
|
return MarkdownStyleSheet(
|
||||||
h1: const TextStyle(
|
h1: const TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A), height: 1.4),
|
||||||
fontSize: 24,
|
h2: const TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A), height: 1.4),
|
||||||
fontWeight: FontWeight.w600,
|
h3: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A), height: 1.4),
|
||||||
color: Color(0xFF1A1A1A),
|
h4: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A), height: 1.4),
|
||||||
height: 1.4,
|
p: const TextStyle(fontSize: 15, color: Color(0xFF333333), height: 1.8),
|
||||||
),
|
code: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A), backgroundColor: Color(0xFFF5F5F5), fontFamily: 'monospace'),
|
||||||
h2: const TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
height: 1.4,
|
|
||||||
),
|
|
||||||
h3: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
height: 1.4,
|
|
||||||
),
|
|
||||||
h4: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
height: 1.4,
|
|
||||||
),
|
|
||||||
p: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
color: Color(0xFF333333),
|
|
||||||
height: 1.8,
|
|
||||||
),
|
|
||||||
code: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
backgroundColor: Color(0xFFF5F5F5),
|
|
||||||
fontFamily: 'monospace',
|
|
||||||
),
|
|
||||||
codeblockDecoration: BoxDecoration(
|
codeblockDecoration: BoxDecoration(
|
||||||
color: const Color(0xFFF8F8F8),
|
color: const Color(0xFFF8F8F8),
|
||||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
border: Border.all(color: const Color(0xFFE5E5E5)),
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
codeblockPadding: const EdgeInsets.all(12),
|
codeblockPadding: const EdgeInsets.all(12),
|
||||||
blockquote: const TextStyle(
|
blockquote: const TextStyle(fontSize: 15, color: Color(0xFF666666), fontStyle: FontStyle.italic, height: 1.8),
|
||||||
fontSize: 15,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
height: 1.8,
|
|
||||||
),
|
|
||||||
blockquoteDecoration: const BoxDecoration(
|
blockquoteDecoration: const BoxDecoration(
|
||||||
border: Border(left: BorderSide(color: Color(0xFF999999), width: 4)),
|
border: Border(left: BorderSide(color: Color(0xFF999999), width: 4)),
|
||||||
),
|
),
|
||||||
blockquotePadding: const EdgeInsets.only(left: 12, top: 4, bottom: 4),
|
blockquotePadding: const EdgeInsets.only(left: 12, top: 4, bottom: 4),
|
||||||
listBullet: const TextStyle(
|
listBullet: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||||
fontSize: 15,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
listIndent: 24,
|
listIndent: 24,
|
||||||
a: const TextStyle(
|
a: const TextStyle(fontSize: 15, color: Color(0xFF4A90D9), decoration: TextDecoration.underline),
|
||||||
fontSize: 15,
|
tableHead: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
|
||||||
color: Color(0xFF4A90D9),
|
tableBody: const TextStyle(fontSize: 14, color: Color(0xFF333333)),
|
||||||
decoration: TextDecoration.underline,
|
tableBorder: TableBorder.all(color: const Color(0xFFE5E5E5), width: 0.5),
|
||||||
),
|
|
||||||
tableHead: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
tableBody: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF333333),
|
|
||||||
),
|
|
||||||
tableBorder: TableBorder.all(
|
|
||||||
color: const Color(0xFFE5E5E5),
|
|
||||||
width: 0.5,
|
|
||||||
),
|
|
||||||
tableColumnWidth: const FlexColumnWidth(),
|
tableColumnWidth: const FlexColumnWidth(),
|
||||||
tableCellsDecoration: const BoxDecoration(
|
tableCellsDecoration: const BoxDecoration(color: Colors.white),
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
tablePadding: const EdgeInsets.all(8),
|
tablePadding: const EdgeInsets.all(8),
|
||||||
strong: const TextStyle(
|
strong: const TextStyle(fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
|
||||||
fontWeight: FontWeight.w600,
|
em: const TextStyle(fontStyle: FontStyle.italic, color: Color(0xFF333333)),
|
||||||
color: Color(0xFF1A1A1A),
|
del: const TextStyle(decoration: TextDecoration.lineThrough, color: Color(0xFF999999)),
|
||||||
),
|
|
||||||
em: const TextStyle(
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
color: Color(0xFF333333),
|
|
||||||
),
|
|
||||||
del: const TextStyle(
|
|
||||||
decoration: TextDecoration.lineThrough,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建 Markdown 中的图片
|
Widget _buildMarkdownImage(Uri uri, Note note) {
|
||||||
Widget _buildMarkdownImage(Uri uri) {
|
|
||||||
// 检查是否是本地图片路径
|
|
||||||
final path = uri.toString();
|
final path = uri.toString();
|
||||||
if (path.isEmpty) return const SizedBox.shrink();
|
if (path.isEmpty) return const SizedBox.shrink();
|
||||||
|
|
||||||
// 尝试从笔记图片列表中查找
|
for (final imgPath in note.images) {
|
||||||
final noteImages = widget.note.images;
|
|
||||||
String? matchedPath;
|
|
||||||
for (final imgPath in noteImages) {
|
|
||||||
if (imgPath.contains(path) || path.contains(imgPath)) {
|
if (imgPath.contains(path) || path.contains(imgPath)) {
|
||||||
matchedPath = imgPath;
|
if (File(imgPath).existsSync()) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matchedPath != null && File(matchedPath).existsSync()) {
|
|
||||||
return ClipRRect(
|
return ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
child: Image.file(
|
child: Image.file(File(imgPath), fit: BoxFit.cover),
|
||||||
File(matchedPath),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
errorBuilder: (context, error, stackTrace) {
|
|
||||||
return _buildImageErrorWidget();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是网络图片
|
|
||||||
if (path.startsWith('http')) {
|
if (path.startsWith('http')) {
|
||||||
return ClipRRect(
|
return ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
child: Image.network(
|
child: Image.network(path, fit: BoxFit.cover, errorBuilder: (_, __, ___) => const SizedBox.shrink()),
|
||||||
path,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
errorBuilder: (context, error, stackTrace) {
|
|
||||||
return _buildImageErrorWidget();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _buildImageErrorWidget();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建图片错误状态
|
void _showImagePreview(List<String> images, int initialIndex) {
|
||||||
Widget _buildImageErrorWidget() {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.broken_image_outlined, size: 20, color: Color(0xFF999999)),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
const Expanded(
|
|
||||||
child: Text(
|
|
||||||
'图片加载失败',
|
|
||||||
style: TextStyle(fontSize: 13, color: Color(0xFF999999)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 格式化日期时间
|
|
||||||
String _formatDateTime(DateTime dateTime) {
|
|
||||||
return '${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 跳转到编辑页面
|
|
||||||
void _navigateToEdit(BuildContext context) {
|
|
||||||
// 从 Provider 获取最新的笔记数据,确保图片等字段是最新的
|
|
||||||
final currentNote = context.read<AppProvider>().notes.firstWhere(
|
|
||||||
(n) => n.id == widget.note.id,
|
|
||||||
orElse: () => widget.note,
|
|
||||||
);
|
|
||||||
Navigator.pushNamed(context, '/note-form', arguments: currentNote).then((_) async {
|
|
||||||
// 返回时刷新笔记列表
|
|
||||||
await context.read<AppProvider>().loadNotes();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 显示图片预览
|
|
||||||
void _showImagePreview(BuildContext context, List<String> images, int initialIndex) {
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
@@ -299,10 +265,7 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
|
|||||||
boundaryMargin: const EdgeInsets.all(20),
|
boundaryMargin: const EdgeInsets.all(20),
|
||||||
minScale: 0.5,
|
minScale: 0.5,
|
||||||
maxScale: 4,
|
maxScale: 4,
|
||||||
child: Image.file(
|
child: Image.file(File(images[initialIndex]), fit: BoxFit.contain),
|
||||||
File(images[initialIndex]),
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -310,91 +273,120 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建操作按钮
|
/// 截取内容前N个字作为标题
|
||||||
Widget _buildActionButton({
|
String _truncateContent(String content) {
|
||||||
|
final cleaned = content
|
||||||
|
.replaceAll(RegExp(r'^#+\s+', multiLine: true), '')
|
||||||
|
.replaceAll(RegExp(r'\*\*(.+?)\*\*'), r'$1')
|
||||||
|
.replaceAll(RegExp(r'\*(.+?)\*'), r'$1')
|
||||||
|
.replaceAll(RegExp(r'`(.+?)`'), r'$1')
|
||||||
|
.replaceAll(RegExp(r'^\s*[-*+]\s', multiLine: true), '')
|
||||||
|
.replaceAll(RegExp(r'^\s*>\s', multiLine: true), '')
|
||||||
|
.replaceAll(RegExp(r'\[([^\]]+)\]\([^)]+\)'), r'$1')
|
||||||
|
.replaceAll(RegExp(r'!\[([^\]]*)\]\([^)]+\)'), '')
|
||||||
|
.trim();
|
||||||
|
if (cleaned.isEmpty) return '无标题';
|
||||||
|
return cleaned.length > 20 ? '${cleaned.substring(0, 20)}…' : cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _navigateToEdit(BuildContext context) {
|
||||||
|
final currentNote = context.read<AppProvider>().notes.firstWhere(
|
||||||
|
(n) => n.id == widget.note.id,
|
||||||
|
orElse: () => widget.note,
|
||||||
|
);
|
||||||
|
Navigator.pushNamed(context, '/note-form', arguments: currentNote).then((_) async {
|
||||||
|
await context.read<AppProvider>().loadNotes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 右下角悬浮按钮组
|
||||||
|
Widget _buildFloatingActionButtons() {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.edit_outlined,
|
||||||
|
onPressed: () => _navigateToEdit(context),
|
||||||
|
tooltip: '编辑',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.delete_outline,
|
||||||
|
onPressed: () => _showDeleteDialog(context),
|
||||||
|
tooltip: '删除',
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.share_outlined,
|
||||||
|
onPressed: _shareNote,
|
||||||
|
tooltip: '分享',
|
||||||
|
backgroundColor: const Color(0xFF4CAF50),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildFloatingButton({
|
||||||
required IconData icon,
|
required IconData icon,
|
||||||
required Color color,
|
required VoidCallback onPressed,
|
||||||
required VoidCallback onTap,
|
required String tooltip,
|
||||||
|
Color backgroundColor = const Color(0xFF1A1A1A),
|
||||||
}) {
|
}) {
|
||||||
return Container(
|
return Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Ink(
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 40,
|
height: 40,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: backgroundColor,
|
||||||
borderRadius: BorderRadius.circular(10),
|
shape: BoxShape.circle,
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: backgroundColor.withValues(alpha: 0.3),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
),
|
),
|
||||||
child: Material(
|
],
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: onTap,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
child: Icon(
|
|
||||||
icon,
|
|
||||||
color: color,
|
|
||||||
size: 20,
|
|
||||||
),
|
),
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(icon, size: 18, color: Colors.white),
|
||||||
|
onPressed: onPressed,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
tooltip: tooltip,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 显示删除对话框
|
|
||||||
void _showDeleteDialog(BuildContext context) {
|
void _showDeleteDialog(BuildContext context) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
title: const Text('删除笔记'),
|
||||||
elevation: 0,
|
content: const Text('删除后将移至回收站,确定要删除吗?'),
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
||||||
title: const Text(
|
|
||||||
'确认删除',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
content: const Text(
|
|
||||||
'确定要删除这条笔记吗?删除后可在回收站恢复。',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(ctx),
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: const Color(0xFF666666),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('取消'),
|
child: const Text('取消'),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () {
|
||||||
await context.read<AppProvider>().removeNote(widget.note.id);
|
Navigator.pop(ctx);
|
||||||
// 刷新笔记列表
|
context.read<AppProvider>().removeNote(widget.note.id);
|
||||||
await context.read<AppProvider>().loadNotes();
|
|
||||||
if (!mounted) return;
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.pop(context);
|
|
||||||
ToastUtil.show(context, '已删除');
|
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||||
backgroundColor: Colors.red,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('删除'),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _shareNote() {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => NoteSharePage(note: widget.note)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,54 +20,84 @@ class NoteFormPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NoteFormPageState extends State<NoteFormPage> {
|
class _NoteFormPageState extends State<NoteFormPage> {
|
||||||
|
late TextEditingController _titleController;
|
||||||
late TextEditingController _contentController;
|
late TextEditingController _contentController;
|
||||||
late DateTime _createdAt;
|
late DateTime _createdAt;
|
||||||
List<String> _tags = [];
|
List<String> _tags = [];
|
||||||
List<String> _images = []; // 图片路径列表
|
List<String> _images = []; // 图片路径列表
|
||||||
String _contentType = 'plain_text'; // markdown / plain_text
|
|
||||||
bool _isEditing = false;
|
bool _isEditing = false;
|
||||||
final ImagePicker _picker = ImagePicker();
|
final ImagePicker _picker = ImagePicker();
|
||||||
String? _tempNoteId; // 新建模式时使用的临时笔记ID
|
String? _tempNoteId; // 新建模式时使用的临时笔记ID
|
||||||
String _editorMode = 'split'; // 'edit' | 'split' | 'preview'
|
String _editorMode = 'edit'; // 'edit' | 'preview'
|
||||||
|
int _charCount = 0;
|
||||||
|
|
||||||
|
static const _weekdays = ['一', '二', '三', '四', '五', '六', '日'];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final note = widget.note;
|
final note = widget.note;
|
||||||
_contentController = TextEditingController(text: note?.content ?? '');
|
_titleController = TextEditingController(text: note?.title ?? '');
|
||||||
|
final text = note?.content ?? '';
|
||||||
|
_contentController = TextEditingController(text: text);
|
||||||
|
_charCount = text.length;
|
||||||
|
_contentController.addListener(() {
|
||||||
|
setState(() => _charCount = _contentController.text.length);
|
||||||
|
});
|
||||||
_createdAt = note?.createdAt ?? DateTime.now();
|
_createdAt = note?.createdAt ?? DateTime.now();
|
||||||
_tags = note != null ? List.from(note.tags) : [];
|
_tags = note != null ? List.from(note.tags) : [];
|
||||||
_images = note != null ? List.from(note.images) : [];
|
_images = note != null ? List.from(note.images) : [];
|
||||||
_contentType = note?.contentType ?? 'plain_text';
|
|
||||||
_isEditing = note != null;
|
_isEditing = note != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_titleController.dispose();
|
||||||
_contentController.dispose();
|
_contentController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final bottomInset = MediaQuery.of(context).viewInsets.bottom;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(_isEditing ? '编辑笔记' : '新建笔记'),
|
title: GestureDetector(
|
||||||
actions: [
|
onLongPress: _showTitleDialog,
|
||||||
IconButton(
|
child: _buildAppBarTitle(),
|
||||||
onPressed: _saveNote,
|
),
|
||||||
icon: const Icon(Icons.save_outlined),
|
actions: [
|
||||||
tooltip: '保存',
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 12),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: _saveNote,
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
backgroundColor: const Color(0xFF1A1A1A),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
),
|
||||||
|
child: const Text('保存', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
// 顶部信息栏:创建时间 + 格式选择 + 标签
|
// 主内容区域 — 图片网格固定在内容下方
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(bottom: 56 + bottomInset),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
// 顶部信息栏
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
border: Border(
|
border: Border(
|
||||||
bottom: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
bottom: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
||||||
@@ -77,67 +107,78 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
// 创建时间
|
// 大日号
|
||||||
Container(
|
Text(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
'${_createdAt.day}',
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFFAFAFA),
|
|
||||||
borderRadius: BorderRadius.circular(6),
|
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
_formatDateTime(_createdAt),
|
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 30,
|
||||||
color: Color(0xFF666666),
|
fontWeight: FontWeight.w200,
|
||||||
|
color: Color(0xFF333333),
|
||||||
|
height: 1.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
// 右边:年月 + 时分 纵向排列
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${_createdAt.year}/${_createdAt.month.toString().padLeft(2, '0')} 周${_weekdays[_createdAt.weekday - 1]}',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Color(0xFF777777),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 1),
|
||||||
|
Text(
|
||||||
|
'${_createdAt.hour.toString().padLeft(2, '0')}:${_createdAt.minute.toString().padLeft(2, '0')}',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
// 格式选择
|
// 字数统计
|
||||||
_buildFormatSelector(),
|
Text(
|
||||||
|
'$_charCount 字',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
color: Color(0xFFAAAAAA),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
|
||||||
// 标签
|
|
||||||
_buildTagSelector(),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// 标签行
|
||||||
|
_buildTagRow(),
|
||||||
|
|
||||||
// 编辑 / 预览区域
|
// 编辑 / 预览区域
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _contentType == 'markdown'
|
child: _buildContentArea(),
|
||||||
? _buildContentArea()
|
|
||||||
: _buildEditor(),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
// 图片区域(放在内容下方)
|
// 图片区域
|
||||||
if (_contentType == 'plain_text' && _images.isNotEmpty)
|
_buildImageRow(),
|
||||||
Container(
|
],
|
||||||
height: 100,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
border: Border(
|
|
||||||
top: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: ListView.separated(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: _images.length,
|
|
||||||
separatorBuilder: (context, index) => const SizedBox(width: 8),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return _buildHorizontalImageItem(index);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// 底部区域:Markdown 浮动工具栏 或 纯文本图片工具栏
|
// 底部浮动工具栏 — 独立于主内容,键盘弹起时单独上移
|
||||||
if (_contentType == 'markdown')
|
Positioned(
|
||||||
_buildFloatingToolbar()
|
left: 0,
|
||||||
else
|
right: 0,
|
||||||
_buildPlainTextBottom(),
|
bottom: bottomInset,
|
||||||
|
child: _buildFloatingToolbar(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -216,7 +257,6 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
_modeSwitch(Icons.edit, 'edit'),
|
_modeSwitch(Icons.edit, 'edit'),
|
||||||
_modeSwitch(Icons.vertical_split, 'split'),
|
|
||||||
_modeSwitch(Icons.visibility, 'preview'),
|
_modeSwitch(Icons.visibility, 'preview'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -323,91 +363,14 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 纯文本模式底部栏
|
|
||||||
Widget _buildPlainTextBottom() {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
border: Border(
|
|
||||||
top: BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
if (_images.isNotEmpty)
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFFAFAFA),
|
|
||||||
borderRadius: BorderRadius.circular(6),
|
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.image_outlined, size: 14, color: Color(0xFF666666)),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text('${_images.length}', style: const TextStyle(fontSize: 12, color: Color(0xFF666666))),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
InkWell(
|
|
||||||
onTap: _pickImage,
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFF1A1A1A),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: const Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.add_photo_alternate_outlined, size: 18, color: Colors.white),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text('添加图片', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: Colors.white)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 根据 _editorMode 构建内容区域
|
/// 根据 _editorMode 构建内容区域
|
||||||
Widget _buildContentArea() {
|
Widget _buildContentArea() {
|
||||||
switch (_editorMode) {
|
switch (_editorMode) {
|
||||||
case 'edit':
|
|
||||||
return _buildEditor();
|
|
||||||
case 'preview':
|
case 'preview':
|
||||||
return _buildPreview();
|
return _buildPreview();
|
||||||
case 'split':
|
case 'edit':
|
||||||
default:
|
default:
|
||||||
return Column(
|
return _buildEditor();
|
||||||
children: [
|
|
||||||
Expanded(flex: 1, child: _buildEditor()),
|
|
||||||
GestureDetector(
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
onTap: () => setState(() => _editorMode = 'preview'),
|
|
||||||
child: Container(
|
|
||||||
height: 4,
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
child: Center(
|
|
||||||
child: Container(
|
|
||||||
width: 28,
|
|
||||||
height: 3,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFD0D0D0),
|
|
||||||
borderRadius: BorderRadius.circular(1.5),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(flex: 1, child: _buildPreview()),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,9 +392,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
height: 1.6,
|
height: 1.6,
|
||||||
),
|
),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: _contentType == 'markdown'
|
hintText: '使用 Markdown 格式书写...',
|
||||||
? '使用 Markdown 格式书写...'
|
|
||||||
: '开始书写...',
|
|
||||||
hintStyle: const TextStyle(
|
hintStyle: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: Color(0xFFCCCCCC),
|
color: Color(0xFFCCCCCC),
|
||||||
@@ -443,10 +404,13 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 实时 Markdown 预览
|
/// 实时 Markdown 预览(点击回到编辑)
|
||||||
Widget _buildPreview() {
|
Widget _buildPreview() {
|
||||||
final text = _contentController.text;
|
final text = _contentController.text;
|
||||||
return Container(
|
return GestureDetector(
|
||||||
|
onTap: () => setState(() => _editorMode = 'edit'),
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
child: Container(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: const Color(0xFFFAFAFA),
|
||||||
child: text.isEmpty
|
child: text.isEmpty
|
||||||
? const Center(
|
? const Center(
|
||||||
@@ -506,262 +470,72 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
));
|
||||||
}
|
|
||||||
|
|
||||||
/// 构建格式选择器
|
|
||||||
Widget _buildFormatSelector() {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => _showFormatSelector(),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFFAFAFA),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
_contentType == 'markdown' ? Icons.code : Icons.text_fields,
|
|
||||||
size: 16,
|
|
||||||
color: const Color(0xFF666666),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(
|
|
||||||
_contentType == 'markdown' ? 'Markdown' : '纯文本',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
const Icon(
|
|
||||||
Icons.arrow_drop_down,
|
|
||||||
size: 18,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 显示格式选择对话框
|
|
||||||
void _showFormatSelector() {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
shape: const RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
||||||
),
|
|
||||||
builder: (context) => SafeArea(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
// 顶部指示条
|
|
||||||
Container(
|
|
||||||
margin: const EdgeInsets.only(top: 12, bottom: 16),
|
|
||||||
width: 40,
|
|
||||||
height: 4,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFE0E0E0),
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// 标题
|
|
||||||
const Padding(
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'选择格式',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
_buildFormatOption(
|
|
||||||
icon: Icons.code,
|
|
||||||
title: 'Markdown',
|
|
||||||
subtitle: '支持 Markdown 语法',
|
|
||||||
isSelected: _contentType == 'markdown',
|
|
||||||
onTap: () {
|
|
||||||
setState(() => _contentType = 'markdown');
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
_buildFormatOption(
|
|
||||||
icon: Icons.text_fields,
|
|
||||||
title: '纯文本',
|
|
||||||
subtitle: '普通文本格式,支持图片',
|
|
||||||
isSelected: _contentType == 'plain_text',
|
|
||||||
onTap: () {
|
|
||||||
setState(() => _contentType = 'plain_text');
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 构建格式选项
|
|
||||||
Widget _buildFormatOption({
|
|
||||||
required IconData icon,
|
|
||||||
required String title,
|
|
||||||
required String subtitle,
|
|
||||||
required bool isSelected,
|
|
||||||
required VoidCallback onTap,
|
|
||||||
}) {
|
|
||||||
return InkWell(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 44,
|
|
||||||
height: 44,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFF5F5F5),
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
icon,
|
|
||||||
size: 22,
|
|
||||||
color: const Color(0xFF666666),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
subtitle,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (isSelected)
|
|
||||||
Container(
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFF1A1A1A),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.check,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建标签选择器
|
/// 构建标签选择器
|
||||||
Widget _buildTagSelector() {
|
/// 构建标签横向滚动行
|
||||||
return Wrap(
|
Widget _buildTagRow() {
|
||||||
spacing: 10,
|
|
||||||
runSpacing: 8,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
|
||||||
..._tags.asMap().entries.map((entry) {
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
height: 28,
|
||||||
|
margin: const EdgeInsets.only(top: 6, bottom: 2),
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
itemCount: _tags.length + 1,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 6),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index < _tags.length) {
|
||||||
|
return _buildTagChip(index);
|
||||||
|
}
|
||||||
|
return _buildAddTagButton();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTagChip(int index) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: const Color(0xFFF5F5F5),
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
entry.value,
|
_tags[index],
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 11, color: Color(0xFF666666)),
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 3),
|
||||||
const SizedBox(width: 6),
|
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => setState(() => _tags.removeAt(entry.key)),
|
onTap: () => setState(() => _tags.removeAt(index)),
|
||||||
child: Container(
|
child: const Icon(Icons.close, size: 10, color: Color(0xFFBBBBBB)),
|
||||||
padding: const EdgeInsets.all(2),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFE8E8E8),
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.close,
|
|
||||||
size: 10,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}
|
||||||
// 添加标签按钮
|
|
||||||
GestureDetector(
|
Widget _buildAddTagButton() {
|
||||||
onTap: () => _showAddTagDialog(),
|
return GestureDetector(
|
||||||
|
onTap: _showAddTagDialog,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
border: Border.all(color: const Color(0xFFDDDDDD), width: 1),
|
||||||
),
|
),
|
||||||
child: const Row(
|
child: const Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.add, size: 12, color: Color(0xFFAAAAAA)),
|
||||||
Icons.add,
|
SizedBox(width: 2),
|
||||||
size: 14,
|
Text('标签', style: TextStyle(fontSize: 11, color: Color(0xFFAAAAAA))),
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
SizedBox(width: 4),
|
|
||||||
Text(
|
|
||||||
'标签',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -837,33 +611,30 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Wrap(
|
SizedBox(
|
||||||
spacing: 10,
|
height: 200,
|
||||||
runSpacing: 10,
|
child: ListView(
|
||||||
|
shrinkWrap: true,
|
||||||
children: availableTags.map((tag) {
|
children: availableTags.map((tag) {
|
||||||
return GestureDetector(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_addTag(tag);
|
_addTag(tag);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFFAFAFA),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
tag,
|
tag,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Color(0xFF666666),
|
color: Color(0xFF555555),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -916,17 +687,98 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 格式化日期时间
|
Widget _buildAppBarTitle() {
|
||||||
String _formatDateTime(DateTime date) {
|
final base = _isEditing ? '编辑笔记' : '新建笔记';
|
||||||
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')} ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
|
final t = _titleController.text.trim();
|
||||||
|
if (t.isEmpty) {
|
||||||
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(base),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
const Icon(Icons.edit, size: 14, color: Color(0xFF999999)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final display = t.length > 4 ? '${t.substring(0, 4)}…' : t;
|
||||||
|
return Text('$base($display)');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 长按标题弹出标题编辑窗口
|
||||||
|
void _showTitleDialog() {
|
||||||
|
final controller = TextEditingController(text: _titleController.text);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
title: const Text(
|
||||||
|
'编辑标题',
|
||||||
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
content: TextField(
|
||||||
|
controller: controller,
|
||||||
|
autofocus: true,
|
||||||
|
style: const TextStyle(fontSize: 16, color: Color(0xFF1A1A1A)),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: '输入标题...',
|
||||||
|
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
||||||
|
filled: true,
|
||||||
|
fillColor: const Color(0xFFFAFAFA),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFFE8E8E8), width: 0.5),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFF1A1A1A), width: 1),
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||||
|
),
|
||||||
|
onSubmitted: (value) {
|
||||||
|
setState(() => _titleController.text = value.trim());
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
foregroundColor: const Color(0xFF666666),
|
||||||
|
),
|
||||||
|
child: const Text('取消'),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() => _titleController.text = controller.text.trim());
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color(0xFF1A1A1A),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
|
),
|
||||||
|
child: const Text('确定'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 保存笔记
|
/// 保存笔记
|
||||||
Future<void> _saveNote() async {
|
Future<void> _saveNote() async {
|
||||||
final content = _contentController.text.trim();
|
final content = _contentController.text.trim();
|
||||||
|
final title = _titleController.text.trim();
|
||||||
|
|
||||||
if (content.isEmpty) {
|
if (title.isEmpty && content.isEmpty) {
|
||||||
ToastUtil.show(context, '笔记内容不能为空');
|
ToastUtil.show(context, '标题或内容不能为空');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -935,8 +787,8 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
if (_isEditing) {
|
if (_isEditing) {
|
||||||
// 更新现有笔记
|
// 更新现有笔记
|
||||||
final updatedNote = widget.note!.copyWith(
|
final updatedNote = widget.note!.copyWith(
|
||||||
|
title: _titleController.text.trim(),
|
||||||
content: content,
|
content: content,
|
||||||
contentType: _contentType,
|
|
||||||
tags: _tags,
|
tags: _tags,
|
||||||
images: _images,
|
images: _images,
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
@@ -955,10 +807,12 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
finalImages = await _moveImagesToNewId(oldNoteId, newNoteId);
|
finalImages = await _moveImagesToNewId(oldNoteId, newNoteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final title = _titleController.text.trim();
|
||||||
|
|
||||||
final newNote = Note(
|
final newNote = Note(
|
||||||
id: noteId,
|
id: noteId,
|
||||||
|
title: title,
|
||||||
content: content,
|
content: content,
|
||||||
contentType: _contentType,
|
|
||||||
tags: _tags,
|
tags: _tags,
|
||||||
images: finalImages.isNotEmpty ? finalImages : _images,
|
images: finalImages.isNotEmpty ? finalImages : _images,
|
||||||
createdAt: _createdAt,
|
createdAt: _createdAt,
|
||||||
@@ -1054,35 +908,84 @@ class _NoteFormPageState extends State<NoteFormPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建图片项
|
/// 构建图片横向滚动行
|
||||||
Widget _buildImageItem(int index) {
|
Widget _buildImageRow() {
|
||||||
return InkWell(
|
if (_images.isEmpty) {
|
||||||
onTap: () => _showImagePreview(index),
|
return Container(
|
||||||
onLongPress: () => _showDeleteImageDialog(index),
|
height: 80,
|
||||||
child: Container(
|
decoration: const BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
child: ListView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
children: [
|
||||||
|
_buildAddImageButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
height: 88,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
color: Colors.white,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.02),
|
||||||
|
blurRadius: 4,
|
||||||
|
offset: const Offset(0, -1),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
itemCount: _images.length + 1,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 10),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index < _images.length) {
|
||||||
|
return _buildImageItem(index);
|
||||||
|
}
|
||||||
|
return _buildAddImageButton();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 添加图片按钮
|
||||||
|
Widget _buildAddImageButton() {
|
||||||
|
return InkWell(
|
||||||
|
onTap: _pickImage,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
child: Container(
|
||||||
|
width: 64,
|
||||||
|
height: 64,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
color: const Color(0xFFF8F8F8),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
),
|
),
|
||||||
clipBehavior: Clip.antiAlias,
|
child: const Icon(
|
||||||
child: Image.file(
|
Icons.add_photo_alternate_outlined,
|
||||||
File(_images[index]),
|
size: 24,
|
||||||
fit: BoxFit.cover,
|
color: Color(0xFFBBBBBB),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建横向图片项(用于底部图片栏)
|
/// 构建图片项
|
||||||
Widget _buildHorizontalImageItem(int index) {
|
Widget _buildImageItem(int index) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => _showImagePreview(index),
|
onTap: () => _showImagePreview(index),
|
||||||
onLongPress: () => _showDeleteImageDialog(index),
|
onLongPress: () => _showDeleteImageDialog(index),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 84,
|
width: 64,
|
||||||
height: 84,
|
height: 64,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
),
|
),
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
|
|||||||
263
lib/pages/note/note_share_page.dart
Normal file
263
lib/pages/note/note_share_page.dart
Normal file
@@ -0,0 +1,263 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
import '../../models/data_models.dart';
|
||||||
|
import '../../utils/toast_util.dart';
|
||||||
|
|
||||||
|
/// 笔记分享海报页面
|
||||||
|
class NoteSharePage extends StatefulWidget {
|
||||||
|
final Note note;
|
||||||
|
|
||||||
|
const NoteSharePage({super.key, required this.note});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<NoteSharePage> createState() => _NoteSharePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NoteSharePageState extends State<NoteSharePage> {
|
||||||
|
final GlobalKey _posterKey = GlobalKey();
|
||||||
|
bool _isGenerating = false;
|
||||||
|
|
||||||
|
static const _weekdays = ['一', '二', '三', '四', '五', '六', '日'];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF5F5F5),
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Color(0xFF1A1A1A)),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'分享笔记',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
centerTitle: true,
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: _isGenerating ? null : _generateAndShare,
|
||||||
|
child: _isGenerating
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text(
|
||||||
|
'分享',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: RepaintBoundary(
|
||||||
|
key: _posterKey,
|
||||||
|
child: _buildPosterWidget(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildPosterWidget() {
|
||||||
|
final note = widget.note;
|
||||||
|
final hasImages = note.images.isNotEmpty;
|
||||||
|
final dateStr =
|
||||||
|
'${note.createdAt.year}/${note.createdAt.month.toString().padLeft(2, '0')}/${note.createdAt.day.toString().padLeft(2, '0')} '
|
||||||
|
'周${_weekdays[note.createdAt.weekday - 1]} '
|
||||||
|
'${note.createdAt.hour.toString().padLeft(2, '0')}:${note.createdAt.minute.toString().padLeft(2, '0')}';
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
width: 320,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.1),
|
||||||
|
blurRadius: 20,
|
||||||
|
offset: const Offset(0, 10),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 首张图片
|
||||||
|
if (hasImages && File(note.images.first).existsSync())
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
||||||
|
child: Image.file(
|
||||||
|
File(note.images.first),
|
||||||
|
width: 320,
|
||||||
|
height: 200,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 内容区域
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 标题
|
||||||
|
if (note.title.isNotEmpty) ...[
|
||||||
|
Text(
|
||||||
|
note.title,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
],
|
||||||
|
|
||||||
|
// 日期
|
||||||
|
Text(
|
||||||
|
dateStr,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 标签
|
||||||
|
if (note.tags.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Wrap(
|
||||||
|
spacing: 6,
|
||||||
|
runSpacing: 6,
|
||||||
|
children: note.tags.map((tag) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFF0F0F0),
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
tag,
|
||||||
|
style: const TextStyle(fontSize: 11, color: Color(0xFF888888)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Container(height: 0.5, color: const Color(0xFFE8E8E8)),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// 正文内容
|
||||||
|
Text(
|
||||||
|
note.content,
|
||||||
|
maxLines: 12,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Color(0xFF333333),
|
||||||
|
height: 1.8,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 字数和图片数
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
_buildMetaChip(Icons.text_fields_outlined, '${note.content.length} 字'),
|
||||||
|
if (hasImages) ...[
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
_buildMetaChip(Icons.image_outlined, '${note.images.length} 图'),
|
||||||
|
],
|
||||||
|
const Spacer(),
|
||||||
|
// Mooknote 品牌
|
||||||
|
const Text(
|
||||||
|
'Mooknote',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 11,
|
||||||
|
color: Color(0xFFCCCCCC),
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildMetaChip(IconData icon, String text) {
|
||||||
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(icon, size: 13, color: const Color(0xFFAAAAAA)),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
text,
|
||||||
|
style: const TextStyle(fontSize: 11, color: Color(0xFFAAAAAA)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _generateAndShare() async {
|
||||||
|
setState(() => _isGenerating = true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final boundary = _posterKey.currentContext?.findRenderObject()
|
||||||
|
as RenderRepaintBoundary?;
|
||||||
|
if (boundary == null) {
|
||||||
|
throw Exception('无法获取海报边界');
|
||||||
|
}
|
||||||
|
|
||||||
|
final image = await boundary.toImage(pixelRatio: 3.0);
|
||||||
|
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||||
|
if (byteData == null) {
|
||||||
|
throw Exception('无法生成图片数据');
|
||||||
|
}
|
||||||
|
|
||||||
|
final bytes = byteData.buffer.asUint8List();
|
||||||
|
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
final fileName = 'note_share_${DateTime.now().millisecondsSinceEpoch}.png';
|
||||||
|
final file = File('${tempDir.path}/$fileName');
|
||||||
|
await file.writeAsBytes(bytes);
|
||||||
|
|
||||||
|
await Share.shareXFiles(
|
||||||
|
[XFile(file.path)],
|
||||||
|
text: '分享笔记:${widget.note.title.isNotEmpty ? widget.note.title : '无标题'}',
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ToastUtil.show(context, '生成海报失败:$e');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _isGenerating = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1047,10 +1047,10 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 显示清除缓存对话框
|
/// 显示清除缓存对话框
|
||||||
void _showClearCacheDialog(BuildContext context) {
|
void _showClearCacheDialog(BuildContext pageContext) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: pageContext,
|
||||||
builder: (context) => AlertDialog(
|
builder: (dialogContext) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||||
@@ -1058,13 +1058,13 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
content: const Text('这将删除所有未在数据库中引用的图片文件。确定要继续吗?'),
|
content: const Text('这将删除所有未在数据库中引用的图片文件。确定要继续吗?'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(dialogContext),
|
||||||
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
|
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.pop(context);
|
Navigator.pop(dialogContext);
|
||||||
await _clearCacheData(context);
|
await _clearCacheData(pageContext);
|
||||||
},
|
},
|
||||||
child: const Text('确定', style: TextStyle(color: Colors.red)),
|
child: const Text('确定', style: TextStyle(color: Colors.red)),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -12,36 +12,68 @@ class RecycleBinPage extends StatefulWidget {
|
|||||||
State<RecycleBinPage> createState() => _RecycleBinPageState();
|
State<RecycleBinPage> createState() => _RecycleBinPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RecycleBinPageState extends State<RecycleBinPage> with SingleTickerProviderStateMixin {
|
enum _ItemType { movie, book, note }
|
||||||
late TabController _tabController;
|
|
||||||
List<Movie> _deletedMovies = [];
|
class _DeletedItem {
|
||||||
List<Book> _deletedBooks = [];
|
final _ItemType type;
|
||||||
List<Note> _deletedNotes = [];
|
final String id;
|
||||||
|
final String title;
|
||||||
|
final String subtitle;
|
||||||
|
final IconData icon;
|
||||||
|
final String typeLabel;
|
||||||
|
|
||||||
|
_DeletedItem.movie(Movie m)
|
||||||
|
: type = _ItemType.movie,
|
||||||
|
id = m.id,
|
||||||
|
title = m.title,
|
||||||
|
subtitle = '删除于 ${m.updatedAt.year}.${m.updatedAt.month.toString().padLeft(2, '0')}.${m.updatedAt.day.toString().padLeft(2, '0')}',
|
||||||
|
icon = Icons.movie_outlined,
|
||||||
|
typeLabel = '影视';
|
||||||
|
|
||||||
|
_DeletedItem.book(Book b)
|
||||||
|
: type = _ItemType.book,
|
||||||
|
id = b.id,
|
||||||
|
title = b.title,
|
||||||
|
subtitle = '删除于 ${b.updatedAt.year}.${b.updatedAt.month.toString().padLeft(2, '0')}.${b.updatedAt.day.toString().padLeft(2, '0')}',
|
||||||
|
icon = Icons.menu_book_outlined,
|
||||||
|
typeLabel = '书籍';
|
||||||
|
|
||||||
|
_DeletedItem.note(Note n)
|
||||||
|
: type = _ItemType.note,
|
||||||
|
id = n.id,
|
||||||
|
title = n.title.isNotEmpty ? n.title : n.summary,
|
||||||
|
subtitle = '删除于 ${n.updatedAt.year}.${n.updatedAt.month.toString().padLeft(2, '0')}.${n.updatedAt.day.toString().padLeft(2, '0')}',
|
||||||
|
icon = Icons.description_outlined,
|
||||||
|
typeLabel = '笔记';
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecycleBinPageState extends State<RecycleBinPage> {
|
||||||
|
List<_DeletedItem> _allItems = [];
|
||||||
|
_ItemType? _filterType; // null = 全部
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
|
||||||
|
List<_DeletedItem> get _filteredItems =>
|
||||||
|
_filterType == null ? _allItems : _allItems.where((i) => i.type == _filterType).toList();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_tabController = TabController(length: 3, vsync: this);
|
|
||||||
_loadDeletedItems();
|
_loadDeletedItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_tabController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadDeletedItems() async {
|
Future<void> _loadDeletedItems() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
final provider = context.read<AppProvider>();
|
final provider = context.read<AppProvider>();
|
||||||
final movies = await provider.getDeletedMovies();
|
final movies = await provider.getDeletedMovies();
|
||||||
final books = await provider.getDeletedBooks();
|
final books = await provider.getDeletedBooks();
|
||||||
final notes = await provider.getDeletedNotes();
|
final notes = await provider.getDeletedNotes();
|
||||||
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_deletedMovies = movies;
|
_allItems = [
|
||||||
_deletedBooks = books;
|
for (final m in movies) _DeletedItem.movie(m),
|
||||||
_deletedNotes = notes;
|
for (final b in books) _DeletedItem.book(b),
|
||||||
|
for (final n in notes) _DeletedItem.note(n),
|
||||||
|
];
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -52,380 +84,287 @@ class _RecycleBinPageState extends State<RecycleBinPage> with SingleTickerProvid
|
|||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('回收站'),
|
title: const Text('回收站'),
|
||||||
bottom: TabBar(
|
|
||||||
controller: _tabController,
|
|
||||||
labelColor: const Color(0xFF1A1A1A),
|
|
||||||
unselectedLabelColor: const Color(0xFF999999),
|
|
||||||
indicatorColor: const Color(0xFF1A1A1A),
|
|
||||||
indicatorSize: TabBarIndicatorSize.label,
|
|
||||||
labelStyle: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
unselectedLabelStyle: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
tabs: [
|
|
||||||
Tab(text: '影视 (${_deletedMovies.length})'),
|
|
||||||
Tab(text: '书籍 (${_deletedBooks.length})'),
|
|
||||||
Tab(text: '笔记 (${_deletedNotes.length})'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
actions: [
|
||||||
// 清空全部
|
if (_allItems.isNotEmpty)
|
||||||
TextButton.icon(
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 12),
|
||||||
|
child: TextButton(
|
||||||
onPressed: _showClearAllDialog,
|
onPressed: _showClearAllDialog,
|
||||||
icon: const Icon(Icons.delete_sweep, size: 18, color: Colors.red),
|
style: TextButton.styleFrom(
|
||||||
label: const Text(
|
backgroundColor: Colors.white,
|
||||||
'清空',
|
foregroundColor: Colors.red,
|
||||||
style: TextStyle(color: Colors.red),
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
side: const BorderSide(color: Color(0xFFFFDDDD), width: 0.5),
|
||||||
|
),
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
),
|
||||||
|
child: const Text('清空', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: _isLoading
|
body: _isLoading
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator(strokeWidth: 2, color: Color(0xFF1A1A1A)))
|
||||||
: TabBarView(
|
: Column(
|
||||||
controller: _tabController,
|
|
||||||
children: [
|
children: [
|
||||||
_buildMovieList(),
|
// 筛选标签行
|
||||||
_buildBookList(),
|
if (_allItems.isNotEmpty) _buildFilterRow(),
|
||||||
_buildNoteList(),
|
// 列表
|
||||||
|
Expanded(
|
||||||
|
child: _filteredItems.isEmpty
|
||||||
|
? _buildEmptyState()
|
||||||
|
: RefreshIndicator(
|
||||||
|
onRefresh: _loadDeletedItems,
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
itemCount: _filteredItems.length,
|
||||||
|
itemBuilder: (_, i) => _buildCard(_filteredItems[i]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 影视列表
|
Widget _buildFilterRow() {
|
||||||
Widget _buildMovieList() {
|
|
||||||
if (_deletedMovies.isEmpty) {
|
|
||||||
return _buildEmptyState('暂无删除的影视');
|
|
||||||
}
|
|
||||||
return ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(top: 8),
|
|
||||||
itemCount: _deletedMovies.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final movie = _deletedMovies[index];
|
|
||||||
return _buildDeletedItemCard(
|
|
||||||
title: movie.title,
|
|
||||||
subtitle: '删除于 ${_formatDate(movie.updatedAt)}',
|
|
||||||
onRestore: () => _restoreMovie(movie),
|
|
||||||
onDelete: () => _permanentDeleteMovie(movie),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 书籍列表
|
|
||||||
Widget _buildBookList() {
|
|
||||||
if (_deletedBooks.isEmpty) {
|
|
||||||
return _buildEmptyState('暂无删除的书籍');
|
|
||||||
}
|
|
||||||
return ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(top: 8),
|
|
||||||
itemCount: _deletedBooks.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final book = _deletedBooks[index];
|
|
||||||
return _buildDeletedItemCard(
|
|
||||||
title: book.title,
|
|
||||||
subtitle: '删除于 ${_formatDate(book.updatedAt)}',
|
|
||||||
onRestore: () => _restoreBook(book),
|
|
||||||
onDelete: () => _permanentDeleteBook(book),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 笔记列表
|
|
||||||
Widget _buildNoteList() {
|
|
||||||
if (_deletedNotes.isEmpty) {
|
|
||||||
return _buildEmptyState('暂无删除的笔记');
|
|
||||||
}
|
|
||||||
return ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(top: 8),
|
|
||||||
itemCount: _deletedNotes.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final note = _deletedNotes[index];
|
|
||||||
return _buildDeletedItemCard(
|
|
||||||
title: note.summary,
|
|
||||||
subtitle: '删除于 ${_formatDate(note.updatedAt)}',
|
|
||||||
onRestore: () => _restoreNote(note),
|
|
||||||
onDelete: () => _permanentDeleteNote(note),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 构建已删除项卡片 - 紧凑列表布局
|
|
||||||
Widget _buildDeletedItemCard({
|
|
||||||
required String title,
|
|
||||||
required String subtitle,
|
|
||||||
required VoidCallback onRestore,
|
|
||||||
required VoidCallback onDelete,
|
|
||||||
}) {
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(bottom: BorderSide(color: Color(0xFFEEEEEE), width: 0.5)),
|
||||||
|
),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: [
|
||||||
|
_filterChip('全部', null),
|
||||||
|
_filterChip('影视', _ItemType.movie),
|
||||||
|
_filterChip('书籍', _ItemType.book),
|
||||||
|
_filterChip('笔记', _ItemType.note),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _filterChip(String label, _ItemType? type) {
|
||||||
|
final active = _filterType == type;
|
||||||
|
final count = type == null ? _allItems.length : _allItems.where((i) => i.type == type).length;
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () => setState(() => _filterType = type),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: active ? const Color(0xFF1A1A1A) : const Color(0xFFF5F5F5),
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'$label · $count',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: active ? Colors.white : const Color(0xFF888888),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCard(_DeletedItem item) {
|
||||||
|
return Dismissible(
|
||||||
|
key: Key('${item.type.name}_${item.id}'),
|
||||||
|
direction: DismissDirection.endToStart,
|
||||||
|
background: _buildDismissBackground(),
|
||||||
|
confirmDismiss: (_) async => _showConfirmDialog('确定要彻底删除吗?此操作不可恢复。'),
|
||||||
|
onDismissed: (_) => _permanentDelete(item),
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: const Color(0xFFFAFAFA),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(8),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
// 左侧图标
|
|
||||||
Container(
|
Container(
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 40,
|
height: 40,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
border: Border.all(color: const Color(0xFFEEEEEE), width: 0.5),
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.delete_outline,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
size: 20,
|
|
||||||
),
|
),
|
||||||
|
child: Icon(item.icon, size: 20, color: const Color(0xFF888888)),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
// 中间内容区域
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Row(
|
||||||
title,
|
children: [
|
||||||
style: const TextStyle(
|
Expanded(
|
||||||
fontSize: 15,
|
child: Text(
|
||||||
fontWeight: FontWeight.w500,
|
item.title,
|
||||||
color: Color(0xFF1A1A1A),
|
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A), height: 1.3),
|
||||||
),
|
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
),
|
||||||
Text(
|
const SizedBox(width: 6),
|
||||||
subtitle,
|
Container(
|
||||||
style: const TextStyle(
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
||||||
fontSize: 12,
|
decoration: BoxDecoration(
|
||||||
color: Color(0xFF999999),
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(3),
|
||||||
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
item.typeLabel,
|
||||||
|
style: const TextStyle(fontSize: 9, fontWeight: FontWeight.w600, color: Color(0xFF999999)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 3),
|
||||||
|
Text(
|
||||||
|
item.subtitle,
|
||||||
|
style: const TextStyle(fontSize: 11, color: Color(0xFFAAAAAA)),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
// 右侧操作按钮
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
// 恢复按钮
|
|
||||||
_buildActionButton(
|
|
||||||
icon: Icons.restore,
|
|
||||||
color: const Color(0xFF1A1A1A),
|
|
||||||
tooltip: '恢复',
|
|
||||||
onTap: onRestore,
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
// 彻底删除按钮
|
_actionBtn(Icons.restore, '恢复', const Color(0xFF1A1A1A), () => _restore(item)),
|
||||||
_buildActionButton(
|
const SizedBox(width: 6),
|
||||||
icon: Icons.delete_forever,
|
_actionBtn(Icons.delete_outline, '删除', Colors.red, () => _permanentDelete(item)),
|
||||||
color: Colors.red,
|
|
||||||
tooltip: '彻底删除',
|
|
||||||
onTap: onDelete,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建操作按钮
|
Widget _buildDismissBackground() {
|
||||||
Widget _buildActionButton({
|
return Container(
|
||||||
required IconData icon,
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||||
required Color color,
|
|
||||||
required String tooltip,
|
|
||||||
required VoidCallback onTap,
|
|
||||||
}) {
|
|
||||||
return Tooltip(
|
|
||||||
message: tooltip,
|
|
||||||
child: Container(
|
|
||||||
width: 36,
|
|
||||||
height: 36,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.red,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
|
||||||
),
|
),
|
||||||
child: Material(
|
alignment: Alignment.centerRight,
|
||||||
|
padding: const EdgeInsets.only(right: 24),
|
||||||
|
child: const Icon(Icons.delete_forever, color: Colors.white, size: 22),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _actionBtn(IconData icon, String tooltip, Color color, VoidCallback onTap) {
|
||||||
|
return Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(6),
|
||||||
child: Icon(
|
child: Tooltip(
|
||||||
icon,
|
message: tooltip,
|
||||||
color: color,
|
child: Container(
|
||||||
size: 18,
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
border: Border.all(color: const Color(0xFFEEEEEE), width: 0.5),
|
||||||
),
|
),
|
||||||
|
child: Icon(icon, size: 16, color: color),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEmptyState(String message) {
|
Widget _buildEmptyState() {
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 80,
|
width: 72,
|
||||||
height: 80,
|
height: 72,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF5F5F5),
|
color: const Color(0xFFF8F8F8),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(18),
|
||||||
),
|
),
|
||||||
child: const Icon(
|
child: const Icon(Icons.delete_outline, size: 32, color: Color(0xFFD5D5D5)),
|
||||||
Icons.delete_outline,
|
|
||||||
size: 40,
|
|
||||||
color: Color(0xFFCCCCCC),
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 16),
|
||||||
const SizedBox(height: 20),
|
|
||||||
Text(
|
Text(
|
||||||
message,
|
_filterType == null ? '回收站是空的' : '没有删除的项目',
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
||||||
fontSize: 15,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
const Text(
|
|
||||||
'删除的项目将显示在这里',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFFBBBBBB),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
const Text('删除的项目会显示在这里', style: TextStyle(fontSize: 12, color: Color(0xFFCCCCCC))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatDate(DateTime date) {
|
Future<void> _restore(_DeletedItem item) async {
|
||||||
return '${date.year}.${date.month.toString().padLeft(2, '0')}.${date.day.toString().padLeft(2, '0')}';
|
final provider = context.read<AppProvider>();
|
||||||
|
switch (item.type) {
|
||||||
|
case _ItemType.movie:
|
||||||
|
await provider.restoreMovie(item.id);
|
||||||
|
if (mounted) ToastUtil.show(context, '影视已恢复');
|
||||||
|
case _ItemType.book:
|
||||||
|
await provider.restoreBook(item.id);
|
||||||
|
if (mounted) ToastUtil.show(context, '书籍已恢复');
|
||||||
|
case _ItemType.note:
|
||||||
|
await provider.restoreNote(item.id);
|
||||||
|
if (mounted) ToastUtil.show(context, '笔记已恢复');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 恢复影视
|
|
||||||
Future<void> _restoreMovie(Movie movie) async {
|
|
||||||
await context.read<AppProvider>().restoreMovie(movie.id);
|
|
||||||
_loadDeletedItems();
|
_loadDeletedItems();
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '影视已恢复');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 彻底删除影视
|
Future<void> _permanentDelete(_DeletedItem item) async {
|
||||||
Future<void> _permanentDeleteMovie(Movie movie) async {
|
final confirmed = await _showConfirmDialog('确定要彻底删除吗?此操作不可恢复。');
|
||||||
final confirmed = await _showConfirmDialog('确定要彻底删除这部影视吗?此操作不可恢复。');
|
if (!confirmed) return;
|
||||||
if (confirmed) {
|
final provider = context.read<AppProvider>();
|
||||||
await context.read<AppProvider>().permanentDeleteMovie(movie.id);
|
switch (item.type) {
|
||||||
|
case _ItemType.movie:
|
||||||
|
await provider.permanentDeleteMovie(item.id);
|
||||||
|
case _ItemType.book:
|
||||||
|
await provider.permanentDeleteBook(item.id);
|
||||||
|
case _ItemType.note:
|
||||||
|
await provider.permanentDeleteNote(item.id);
|
||||||
|
}
|
||||||
_loadDeletedItems();
|
_loadDeletedItems();
|
||||||
if (mounted) {
|
if (mounted) ToastUtil.show(context, '已彻底删除');
|
||||||
ToastUtil.show(context, '已彻底删除');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 恢复书籍
|
|
||||||
Future<void> _restoreBook(Book book) async {
|
|
||||||
await context.read<AppProvider>().restoreBook(book.id);
|
|
||||||
_loadDeletedItems();
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '书籍已恢复');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 彻底删除书籍
|
|
||||||
Future<void> _permanentDeleteBook(Book book) async {
|
|
||||||
final confirmed = await _showConfirmDialog('确定要彻底删除这本书籍吗?此操作不可恢复。');
|
|
||||||
if (confirmed) {
|
|
||||||
await context.read<AppProvider>().permanentDeleteBook(book.id);
|
|
||||||
_loadDeletedItems();
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '已彻底删除');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 恢复笔记
|
|
||||||
Future<void> _restoreNote(Note note) async {
|
|
||||||
await context.read<AppProvider>().restoreNote(note.id);
|
|
||||||
_loadDeletedItems();
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '笔记已恢复');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 彻底删除笔记
|
|
||||||
Future<void> _permanentDeleteNote(Note note) async {
|
|
||||||
final confirmed = await _showConfirmDialog('确定要彻底删除这条笔记吗?此操作不可恢复。');
|
|
||||||
if (confirmed) {
|
|
||||||
await context.read<AppProvider>().permanentDeleteNote(note.id);
|
|
||||||
_loadDeletedItems();
|
|
||||||
if (mounted) {
|
|
||||||
ToastUtil.show(context, '已彻底删除');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 显示确认对话框
|
|
||||||
Future<bool> _showConfirmDialog(String message) async {
|
Future<bool> _showConfirmDialog(String message) async {
|
||||||
final result = await showDialog<bool>(
|
final result = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
title: const Text(
|
title: const Text('确认删除', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
'确认删除',
|
content: Text(message, style: const TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.5)),
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
content: Text(
|
|
||||||
message,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context, false),
|
onPressed: () => Navigator.pop(ctx, false),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(foregroundColor: const Color(0xFF666666)),
|
||||||
foregroundColor: const Color(0xFF666666),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('取消'),
|
child: const Text('取消'),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () => Navigator.pop(context, true),
|
onPressed: () => Navigator.pop(ctx, true),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
),
|
||||||
child: const Text('删除'),
|
child: const Text('删除'),
|
||||||
),
|
),
|
||||||
@@ -436,61 +375,43 @@ class _RecycleBinPageState extends State<RecycleBinPage> with SingleTickerProvid
|
|||||||
return result ?? false;
|
return result ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 显示清空全部对话框
|
|
||||||
void _showClearAllDialog() {
|
void _showClearAllDialog() {
|
||||||
|
final pageContext = context;
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: pageContext,
|
||||||
builder: (context) => AlertDialog(
|
builder: (ctx) => AlertDialog(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
title: const Row(
|
title: const Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.warning_amber, color: Colors.red, size: 24),
|
Icon(Icons.warning_amber_rounded, color: Colors.red, size: 22),
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Text(
|
Text('清空回收站', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
|
||||||
'清空回收站',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
content: const Text(
|
content: const Text(
|
||||||
'确定要清空回收站吗?所有项目将被彻底删除,此操作不可恢复。',
|
'确定要清空回收站吗?所有项目将被彻底删除,此操作不可恢复。',
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.5),
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(ctx),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(foregroundColor: const Color(0xFF666666)),
|
||||||
foregroundColor: const Color(0xFF666666),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
|
||||||
child: const Text('取消'),
|
child: const Text('取消'),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.pop(context);
|
Navigator.pop(ctx);
|
||||||
await context.read<AppProvider>().clearRecycleBin();
|
await pageContext.read<AppProvider>().clearRecycleBin();
|
||||||
_loadDeletedItems();
|
_loadDeletedItems();
|
||||||
if (mounted) {
|
if (mounted) ToastUtil.show(pageContext, '回收站已清空');
|
||||||
ToastUtil.show(context, '回收站已清空');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.red,
|
backgroundColor: Colors.red,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
),
|
),
|
||||||
child: const Text('清空'),
|
child: const Text('清空'),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -578,8 +578,6 @@ class _SearchPageState extends State<SearchPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildNoteItem(Note note) {
|
Widget _buildNoteItem(Note note) {
|
||||||
final isPlainText = note.contentType == 'plain_text';
|
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
@@ -611,7 +609,7 @@ class _SearchPageState extends State<SearchPage> {
|
|||||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
isPlainText ? 'TXT' : 'MD',
|
'MD',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 10,
|
fontSize: 10,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
import '../models/data_models.dart';
|
import '../models/data_models.dart';
|
||||||
|
import '../utils/user_prefs.dart';
|
||||||
|
|
||||||
/// 数据统计页面 - 多维度数据分析
|
/// 数据统计页面 - 多维度数据分析
|
||||||
class StatisticsPage extends StatefulWidget {
|
class StatisticsPage extends StatefulWidget {
|
||||||
@@ -14,6 +15,10 @@ class StatisticsPage extends StatefulWidget {
|
|||||||
class _StatisticsPageState extends State<StatisticsPage> {
|
class _StatisticsPageState extends State<StatisticsPage> {
|
||||||
int _selectedTab = 0;
|
int _selectedTab = 0;
|
||||||
|
|
||||||
|
bool get _showMovies => UserPrefs().showMovieTab;
|
||||||
|
bool get _showBooks => UserPrefs().showBookTab;
|
||||||
|
bool get _showNotes => UserPrefs().showNoteTab;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -29,9 +34,7 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// 标签切换栏
|
|
||||||
_buildTabBar(),
|
_buildTabBar(),
|
||||||
// 内容区域
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: _selectedTab == 0
|
child: _selectedTab == 0
|
||||||
? _buildOverviewTab(movies, books, notes)
|
? _buildOverviewTab(movies, books, notes)
|
||||||
@@ -44,25 +47,19 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建标签栏
|
|
||||||
Widget _buildTabBar() {
|
Widget _buildTabBar() {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(child: _buildTabItem('概览', 0)),
|
||||||
child: _buildTabItem('概览', 0),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(child: _buildTabItem('趋势', 1)),
|
||||||
child: _buildTabItem('趋势', 1),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建标签项
|
|
||||||
Widget _buildTabItem(String label, int index) {
|
Widget _buildTabItem(String label, int index) {
|
||||||
final isSelected = _selectedTab == index;
|
final isSelected = _selectedTab == index;
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
@@ -86,7 +83,6 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 概览标签页
|
|
||||||
Widget _buildOverviewTab(List<Movie> movies, List<Book> books, List<Note> notes) {
|
Widget _buildOverviewTab(List<Movie> movies, List<Book> books, List<Note> notes) {
|
||||||
final totalMovies = movies.where((m) => !m.isDeleted).length;
|
final totalMovies = movies.where((m) => !m.isDeleted).length;
|
||||||
final totalBooks = books.length;
|
final totalBooks = books.length;
|
||||||
@@ -100,170 +96,161 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
final readingBooks = books.where((b) => b.status == 'reading').length;
|
final readingBooks = books.where((b) => b.status == 'reading').length;
|
||||||
final wantToReadBooks = books.where((b) => b.status == 'want_to_read').length;
|
final wantToReadBooks = books.where((b) => b.status == 'want_to_read').length;
|
||||||
|
|
||||||
|
final children = <Widget>[];
|
||||||
|
|
||||||
|
// 数据总览
|
||||||
|
children.add(_buildSectionTitle('数据总览'));
|
||||||
|
children.add(const SizedBox(height: 16));
|
||||||
|
children.add(_buildTotalOverview(totalMovies, totalBooks, totalNotes));
|
||||||
|
children.add(const SizedBox(height: 32));
|
||||||
|
|
||||||
|
// 影视状态分布
|
||||||
|
if (_showMovies) {
|
||||||
|
children.add(_buildSectionTitle('影视状态分布'));
|
||||||
|
children.add(const SizedBox(height: 16));
|
||||||
|
children.add(_buildStatusDistribution([
|
||||||
|
_StatusData('已看', watchedMovies, const Color(0xFF1A1A1A)),
|
||||||
|
_StatusData('在看', watchingMovies, const Color(0xFF666666)),
|
||||||
|
_StatusData('想看', wantToWatchMovies, const Color(0xFF999999)),
|
||||||
|
]));
|
||||||
|
children.add(const SizedBox(height: 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 书籍状态分布
|
||||||
|
if (_showBooks) {
|
||||||
|
children.add(_buildSectionTitle('书籍状态分布'));
|
||||||
|
children.add(const SizedBox(height: 16));
|
||||||
|
children.add(_buildStatusDistribution([
|
||||||
|
_StatusData('已读', readBooks, const Color(0xFF1A1A1A)),
|
||||||
|
_StatusData('在读', readingBooks, const Color(0xFF666666)),
|
||||||
|
_StatusData('想读', wantToReadBooks, const Color(0xFF999999)),
|
||||||
|
]));
|
||||||
|
children.add(const SizedBox(height: 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最近活动
|
||||||
|
children.add(_buildSectionTitle('最近7天活动'));
|
||||||
|
children.add(const SizedBox(height: 16));
|
||||||
|
children.add(_buildRecentActivity(movies, books, notes));
|
||||||
|
|
||||||
return ListView(
|
return ListView(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
children: [
|
children: children,
|
||||||
// 总数据卡片
|
);
|
||||||
_buildSectionTitle('数据总览'),
|
}
|
||||||
const SizedBox(height: 16),
|
|
||||||
Container(
|
Widget _buildTotalOverview(int totalMovies, int totalBooks, int totalNotes) {
|
||||||
|
final items = <Widget>[];
|
||||||
|
if (_showMovies) items.add(Expanded(child: _buildStatItem('影视', totalMovies, Icons.movie_outlined)));
|
||||||
|
if (_showBooks) items.add(Expanded(child: _buildStatItem('书籍', totalBooks, Icons.menu_book_outlined)));
|
||||||
|
if (_showNotes) items.add(Expanded(child: _buildStatItem('笔记', totalNotes, Icons.note_outlined)));
|
||||||
|
|
||||||
|
return Container(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF8F8F8),
|
color: const Color(0xFFF8F8F8),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(children: items),
|
||||||
children: [
|
|
||||||
Expanded(child: _buildStatItem('影视', totalMovies, Icons.movie_outlined)),
|
|
||||||
Expanded(child: _buildStatItem('书籍', totalBooks, Icons.menu_book_outlined)),
|
|
||||||
Expanded(child: _buildStatItem('笔记', totalNotes, Icons.note_outlined)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
|
|
||||||
// 影视状态分布
|
|
||||||
_buildSectionTitle('影视状态分布'),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_buildStatusDistribution([
|
|
||||||
_StatusData('已看', watchedMovies, const Color(0xFF1A1A1A)),
|
|
||||||
_StatusData('在看', watchingMovies, const Color(0xFF666666)),
|
|
||||||
_StatusData('想看', wantToWatchMovies, const Color(0xFF999999)),
|
|
||||||
]),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
|
|
||||||
// 书籍状态分布
|
|
||||||
_buildSectionTitle('书籍状态分布'),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_buildStatusDistribution([
|
|
||||||
_StatusData('已读', readBooks, const Color(0xFF1A1A1A)),
|
|
||||||
_StatusData('在读', readingBooks, const Color(0xFF666666)),
|
|
||||||
_StatusData('想读', wantToReadBooks, const Color(0xFF999999)),
|
|
||||||
]),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
|
|
||||||
// 最近活动
|
|
||||||
_buildSectionTitle('最近7天活动'),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_buildRecentActivity(movies, books, notes),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 趋势标签页
|
|
||||||
Widget _buildTrendTab(List<Movie> movies, List<Book> books, List<Note> notes) {
|
Widget _buildTrendTab(List<Movie> movies, List<Book> books, List<Note> notes) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final thirtyDaysAgo = now.subtract(const Duration(days: 30));
|
|
||||||
|
|
||||||
// 生成最近30天的日期列表
|
final dates = List.generate(30, (index) => now.subtract(Duration(days: 29 - index)));
|
||||||
final dates = List.generate(30, (index) {
|
|
||||||
return now.subtract(Duration(days: 29 - index));
|
|
||||||
});
|
|
||||||
|
|
||||||
// 计算每天的新增数量
|
|
||||||
final movieTrend = dates.map((date) {
|
final movieTrend = dates.map((date) {
|
||||||
return movies.where((m) {
|
return movies.where((m) {
|
||||||
final created = m.createdAt;
|
final created = m.createdAt;
|
||||||
return created.year == date.year &&
|
return created.year == date.year && created.month == date.month && created.day == date.day && !m.isDeleted;
|
||||||
created.month == date.month &&
|
|
||||||
created.day == date.day &&
|
|
||||||
!m.isDeleted;
|
|
||||||
}).length;
|
}).length;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final bookTrend = dates.map((date) {
|
final bookTrend = dates.map((date) {
|
||||||
return books.where((b) {
|
return books.where((b) {
|
||||||
final created = b.createdAt;
|
final created = b.createdAt;
|
||||||
return created.year == date.year &&
|
return created.year == date.year && created.month == date.month && created.day == date.day;
|
||||||
created.month == date.month &&
|
|
||||||
created.day == date.day;
|
|
||||||
}).length;
|
}).length;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final noteTrend = dates.map((date) {
|
final noteTrend = dates.map((date) {
|
||||||
return notes.where((n) {
|
return notes.where((n) {
|
||||||
final created = n.createdAt;
|
final created = n.createdAt;
|
||||||
return created.year == date.year &&
|
return created.year == date.year && created.month == date.month && created.day == date.day;
|
||||||
created.month == date.month &&
|
|
||||||
created.day == date.day;
|
|
||||||
}).length;
|
}).length;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
// 计算总数
|
final totalMovies = movieTrend.fold(0, (a, b) => a + b);
|
||||||
final totalMovies = movieTrend.reduce((a, b) => a + b);
|
final totalBooks = bookTrend.fold(0, (a, b) => a + b);
|
||||||
final totalBooks = bookTrend.reduce((a, b) => a + b);
|
final totalNotes = noteTrend.fold(0, (a, b) => a + b);
|
||||||
final totalNotes = noteTrend.reduce((a, b) => a + b);
|
|
||||||
|
final children = <Widget>[];
|
||||||
|
|
||||||
|
children.add(_buildSectionTitle('近30天新增'));
|
||||||
|
children.add(const SizedBox(height: 16));
|
||||||
|
children.add(_buildTrendSummaryRow(totalMovies, totalBooks, totalNotes));
|
||||||
|
children.add(const SizedBox(height: 32));
|
||||||
|
children.add(_buildSectionTitle('数据趋势'));
|
||||||
|
children.add(const SizedBox(height: 16));
|
||||||
|
children.add(_buildTrendChart(movieTrend, bookTrend, noteTrend));
|
||||||
|
|
||||||
return ListView(
|
return ListView(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
children: [
|
children: children,
|
||||||
// 30天统计摘要
|
);
|
||||||
_buildSectionTitle('近30天新增'),
|
}
|
||||||
const SizedBox(height: 16),
|
|
||||||
Container(
|
Widget _buildTrendSummaryRow(int totalMovies, int totalBooks, int totalNotes) {
|
||||||
|
final items = <Widget>[];
|
||||||
|
if (_showMovies) items.add(Expanded(child: _buildTrendSummary('影视', totalMovies)));
|
||||||
|
if (_showBooks) items.add(Expanded(child: _buildTrendSummary('书籍', totalBooks)));
|
||||||
|
if (_showNotes) items.add(Expanded(child: _buildTrendSummary('笔记', totalNotes)));
|
||||||
|
|
||||||
|
return Container(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF8F8F8),
|
color: const Color(0xFFF8F8F8),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(children: items),
|
||||||
children: [
|
);
|
||||||
Expanded(child: _buildTrendSummary('影视', totalMovies)),
|
}
|
||||||
Expanded(child: _buildTrendSummary('书籍', totalBooks)),
|
|
||||||
Expanded(child: _buildTrendSummary('笔记', totalNotes)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 32),
|
|
||||||
|
|
||||||
// 趋势说明
|
Widget _buildTrendChart(List<int> movieTrend, List<int> bookTrend, List<int> noteTrend) {
|
||||||
_buildSectionTitle('数据趋势'),
|
final rows = <Widget>[];
|
||||||
const SizedBox(height: 16),
|
if (_showMovies) {
|
||||||
Container(
|
rows.add(_buildTrendRow('影视', movieTrend, const Color(0xFF1A1A1A)));
|
||||||
|
}
|
||||||
|
if (_showBooks) {
|
||||||
|
if (rows.isNotEmpty) rows.add(const SizedBox(height: 16));
|
||||||
|
rows.add(_buildTrendRow('书籍', bookTrend, const Color(0xFF666666)));
|
||||||
|
}
|
||||||
|
if (_showNotes) {
|
||||||
|
if (rows.isNotEmpty) rows.add(const SizedBox(height: 16));
|
||||||
|
rows.add(_buildTrendRow('笔记', noteTrend, const Color(0xFF999999)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Container(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: const Color(0xFFFAFAFA),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(children: rows),
|
||||||
children: [
|
|
||||||
_buildTrendRow('影视', movieTrend, const Color(0xFF1A1A1A)),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_buildTrendRow('书籍', bookTrend, const Color(0xFF666666)),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_buildTrendRow('笔记', noteTrend, const Color(0xFF999999)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建趋势摘要项
|
|
||||||
Widget _buildTrendSummary(String label, int count) {
|
Widget _buildTrendSummary(String label, int count) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(count.toString(), style: const TextStyle(fontSize: 28, fontWeight: FontWeight.w700, color: Color(0xFF1A1A1A))),
|
||||||
count.toString(),
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 28,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(label, style: const TextStyle(fontSize: 13, color: Color(0xFF666666))),
|
||||||
label,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF666666),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建趋势行
|
|
||||||
Widget _buildTrendRow(String label, List<int> data, Color color) {
|
Widget _buildTrendRow(String label, List<int> data, Color color) {
|
||||||
final maxValue = data.isEmpty ? 1 : data.reduce((a, b) => a > b ? a : b);
|
final maxValue = data.isEmpty ? 1 : data.reduce((a, b) => a > b ? a : b);
|
||||||
final safeMax = maxValue == 0 ? 1 : maxValue;
|
final safeMax = maxValue == 0 ? 1 : maxValue;
|
||||||
@@ -271,14 +258,7 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(label, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: color)),
|
||||||
label,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: color,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 40,
|
height: 40,
|
||||||
@@ -303,30 +283,18 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建统计项
|
|
||||||
Widget _buildStatItem(String title, int count, IconData icon) {
|
Widget _buildStatItem(String title, int count, IconData icon) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Icon(icon, size: 24, color: const Color(0xFF666666)),
|
Icon(icon, size: 24, color: const Color(0xFF666666)),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(count.toString(), style: const TextStyle(fontSize: 28, fontWeight: FontWeight.w700, color: Color(0xFF1A1A1A))),
|
||||||
count.toString(),
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 28,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(title, style: const TextStyle(fontSize: 13, color: Color(0xFF666666))),
|
||||||
title,
|
|
||||||
style: const TextStyle(fontSize: 13, color: Color(0xFF666666)),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建状态分布
|
|
||||||
Widget _buildStatusDistribution(List<_StatusData> data) {
|
Widget _buildStatusDistribution(List<_StatusData> data) {
|
||||||
final total = data.fold(0, (sum, item) => sum + item.count);
|
final total = data.fold(0, (sum, item) => sum + item.count);
|
||||||
|
|
||||||
@@ -344,38 +312,15 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 10,
|
width: 10, height: 10,
|
||||||
height: 10,
|
decoration: BoxDecoration(color: item.color, borderRadius: BorderRadius.circular(2)),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: item.color,
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Text(
|
Text(item.label, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A))),
|
||||||
item.label,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Text(
|
Text('${item.count}', style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
'${item.count}',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text('($percentage%)', style: const TextStyle(fontSize: 13, color: Color(0xFF999999))),
|
||||||
'($percentage%)',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -384,7 +329,6 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建最近活动
|
|
||||||
Widget _buildRecentActivity(List<Movie> movies, List<Book> books, List<Note> notes) {
|
Widget _buildRecentActivity(List<Movie> movies, List<Book> books, List<Note> notes) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final sevenDaysAgo = now.subtract(const Duration(days: 7));
|
final sevenDaysAgo = now.subtract(const Duration(days: 7));
|
||||||
@@ -393,21 +337,26 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
final recentBooks = books.where((b) => b.createdAt.isAfter(sevenDaysAgo)).length;
|
final recentBooks = books.where((b) => b.createdAt.isAfter(sevenDaysAgo)).length;
|
||||||
final recentNotes = notes.where((n) => n.createdAt.isAfter(sevenDaysAgo)).length;
|
final recentNotes = notes.where((n) => n.createdAt.isAfter(sevenDaysAgo)).length;
|
||||||
|
|
||||||
|
final items = <Widget>[];
|
||||||
|
if (_showMovies) {
|
||||||
|
items.add(_buildActivityRow('新增影视', recentMovies, Icons.movie_outlined));
|
||||||
|
}
|
||||||
|
if (_showBooks) {
|
||||||
|
if (items.isNotEmpty) items.add(const Divider(height: 20, color: Color(0xFFE8E8E8)));
|
||||||
|
items.add(_buildActivityRow('新增书籍', recentBooks, Icons.menu_book_outlined));
|
||||||
|
}
|
||||||
|
if (_showNotes) {
|
||||||
|
if (items.isNotEmpty) items.add(const Divider(height: 20, color: Color(0xFFE8E8E8)));
|
||||||
|
items.add(_buildActivityRow('新增笔记', recentNotes, Icons.note_outlined));
|
||||||
|
}
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFAFAFA),
|
color: const Color(0xFFFAFAFA),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(children: items),
|
||||||
children: [
|
|
||||||
_buildActivityRow('新增影视', recentMovies, Icons.movie_outlined),
|
|
||||||
const Divider(height: 20, color: Color(0xFFE8E8E8)),
|
|
||||||
_buildActivityRow('新增书籍', recentBooks, Icons.menu_book_outlined),
|
|
||||||
const Divider(height: 20, color: Color(0xFFE8E8E8)),
|
|
||||||
_buildActivityRow('新增笔记', recentNotes, Icons.note_outlined),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,8 +364,7 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 36,
|
width: 36, height: 36,
|
||||||
height: 36,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
@@ -425,30 +373,11 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
child: Icon(icon, size: 18, color: const Color(0xFF666666)),
|
child: Icon(icon, size: 18, color: const Color(0xFF666666)),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Text(
|
Text(label, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A))),
|
||||||
label,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Text(
|
Text('$count', style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
'$count',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
const Text(
|
const Text('个', style: TextStyle(fontSize: 13, color: Color(0xFF999999))),
|
||||||
'个',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Color(0xFF999999),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -457,28 +386,16 @@ class _StatisticsPageState extends State<StatisticsPage> {
|
|||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
width: 4,
|
width: 4, height: 16,
|
||||||
height: 16,
|
decoration: BoxDecoration(color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(2)),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFF1A1A1A),
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text(title, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
|
||||||
title,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Color(0xFF1A1A1A),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 状态数据
|
|
||||||
class _StatusData {
|
class _StatusData {
|
||||||
final String label;
|
final String label;
|
||||||
final int count;
|
final int count;
|
||||||
@@ -486,5 +403,3 @@ class _StatusData {
|
|||||||
|
|
||||||
_StatusData(this.label, this.count, this.color);
|
_StatusData(this.label, this.count, this.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
@@ -97,7 +98,8 @@ class _NoteListItemContent extends StatelessWidget {
|
|||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
],
|
],
|
||||||
|
|
||||||
// 内容摘要(去除Markdown标记)
|
// 内容摘要(去除Markdown标记),内容为空则不显示
|
||||||
|
if (_cleanMarkdown(note.content).trim().isNotEmpty)
|
||||||
Text(
|
Text(
|
||||||
_cleanMarkdown(note.content).trim(),
|
_cleanMarkdown(note.content).trim(),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
@@ -115,7 +117,7 @@ class _NoteListItemContent extends StatelessWidget {
|
|||||||
Wrap(
|
Wrap(
|
||||||
spacing: 6,
|
spacing: 6,
|
||||||
runSpacing: 4,
|
runSpacing: 4,
|
||||||
children: note.tags.take(3).map((tag) {
|
children: note.tags.map((tag) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 2),
|
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 2),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -134,12 +136,61 @@ class _NoteListItemContent extends StatelessWidget {
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// 图片预览
|
||||||
|
if (note.images.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildImagePreviewRow(),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 图片预览行
|
||||||
|
Widget _buildImagePreviewRow() {
|
||||||
|
final images = note.images;
|
||||||
|
final count = images.length.clamp(0, 3);
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
Container(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
margin: const EdgeInsets.only(right: 6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||||
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: Image.file(
|
||||||
|
File(images[i]),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
errorBuilder: (_, __, ___) => Container(
|
||||||
|
color: const Color(0xFFF5F5F5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (images.length > 3)
|
||||||
|
Container(
|
||||||
|
width: 48,
|
||||||
|
height: 48,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFF5F5F5),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'+${images.length - 3}',
|
||||||
|
style: const TextStyle(fontSize: 12, color: Color(0xFF999999), fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// 清理 Markdown 标记,提取纯文本
|
/// 清理 Markdown 标记,提取纯文本
|
||||||
String _cleanMarkdown(String text) {
|
String _cleanMarkdown(String text) {
|
||||||
return text
|
return text
|
||||||
|
|||||||
Reference in New Issue
Block a user