适配深色模式

This commit is contained in:
DelLevin-Home
2026-05-26 05:10:21 +08:00
parent b36f50827f
commit 73f3795e65
53 changed files with 3846 additions and 3211 deletions

View File

@@ -13,9 +13,9 @@ import 'book_share_page.dart';
/// 书籍详情页 - 极简主义设计
class BookDetailPage extends StatefulWidget {
final Book book;
const BookDetailPage({super.key, required this.book});
@override
State<BookDetailPage> createState() => _BookDetailPageState();
}
@@ -24,80 +24,54 @@ class _BookDetailPageState extends State<BookDetailPage> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
// 页面获得焦点时刷新数据
_refreshBookData();
}
void _refreshBookData() {
final provider = context.read<AppProvider>();
// 强制刷新当前书籍数据
provider.loadBooks();
}
@override
Widget build(BuildContext context) {
// 从 Provider 获取最新的 book 数据,实现动态刷新
final colors = Theme.of(context).colorScheme;
final book = context.watch<AppProvider>().books
.where((b) => b.id == widget.book.id)
.firstOrNull ?? widget.book;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
body: Stack(
children: [
CustomScrollView(
slivers: [
// 顶部封面区域
_buildSliverAppBar(book),
// 内容区域
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 基本信息
_buildBasicInfo(book),
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
// 作者信息
Divider(height: 0.5, thickness: 0.5, color: colors.outline),
_buildAuthorsSection(book),
// 类型
if (book.genres.isNotEmpty)
_buildGenresSection(book),
// ISBN
if (book.isbn != null && book.isbn!.isNotEmpty)
_buildIsbnSection(book),
// 出版社
if (book.publisher != null && book.publisher!.isNotEmpty)
_buildPublisherSection(book),
// 出版时间
if (book.publishDate != null)
_buildPublishDateSection(book),
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
// 简介
Divider(height: 0.5, thickness: 0.5, color: colors.outline),
if (book.summary != null && book.summary!.isNotEmpty)
_buildSummarySection(book),
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
// 书评和摘抄入口
Divider(height: 0.5, thickness: 0.5, color: colors.outline),
_buildExtraSections(book),
const SizedBox(height: 120),
],
),
),
],
),
// 右下角悬浮按钮组
Positioned(
right: 16,
bottom: 24,
@@ -107,9 +81,9 @@ class _BookDetailPageState extends State<BookDetailPage> {
),
);
}
/// 构建右下角悬浮按钮组
Widget _buildFloatingActionButtons(Book book) {
final colors = Theme.of(context).colorScheme;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
@@ -117,13 +91,16 @@ class _BookDetailPageState extends State<BookDetailPage> {
icon: Icons.edit_outlined,
onPressed: () => _navigateToEdit(context),
tooltip: '编辑',
backgroundColor: colors.primary,
foregroundColor: colors.onPrimary,
),
const SizedBox(height: 12),
_buildFloatingButton(
icon: Icons.delete_outline,
onPressed: () => _showDeleteDialog(context),
tooltip: '删除',
backgroundColor: Colors.red,
backgroundColor: colors.error,
foregroundColor: colors.onError,
),
const SizedBox(height: 12),
_buildFloatingButton(
@@ -131,17 +108,18 @@ class _BookDetailPageState extends State<BookDetailPage> {
onPressed: () => _showSharePoster(book),
tooltip: '分享海报',
backgroundColor: const Color(0xFF4CAF50),
foregroundColor: Colors.white,
),
],
);
}
/// 构建单个悬浮按钮
Widget _buildFloatingButton({
required IconData icon,
required VoidCallback onPressed,
required String tooltip,
Color backgroundColor = const Color(0xFF1A1A1A),
required Color backgroundColor,
required Color foregroundColor,
}) {
return Material(
color: Colors.transparent,
@@ -160,15 +138,15 @@ class _BookDetailPageState extends State<BookDetailPage> {
],
),
child: IconButton(
icon: Icon(icon, size: 18, color: Colors.white),
icon: Icon(icon, size: 18, color: foregroundColor),
onPressed: onPressed,
padding: EdgeInsets.zero,
tooltip: tooltip,
),
),
);
}
/// 构建带背景的返回按钮
Widget _buildBackButton() {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
@@ -194,21 +172,19 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建顶部 AppBar
Widget _buildSliverAppBar(Book book) {
final colors = Theme.of(context).colorScheme;
return SliverAppBar(
expandedHeight: 320,
pinned: true,
backgroundColor: const Color(0xFFF5F5F5),
backgroundColor: colors.surfaceContainerHighest,
leading: _buildBackButton(),
flexibleSpace: FlexibleSpaceBar(
background: _buildCoverSection(book),
),
// 右上角按钮已移到右下角悬浮按钮
);
}
/// 构建封面区域
Widget _buildCoverSection(Book book) {
return SizedBox.expand(
child: book.coverPath != null && book.coverPath!.isNotEmpty
@@ -220,79 +196,74 @@ class _BookDetailPageState extends State<BookDetailPage> {
: _buildCoverPlaceholder(),
);
}
Widget _buildCoverPlaceholder() {
return const Center(
final colors = Theme.of(context).colorScheme;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.menu_book,
size: 64,
color: Color(0xFFCCCCCC),
color: colors.onSurface.withValues(alpha: 0.25),
),
SizedBox(height: 16),
const SizedBox(height: 16),
Text(
'暂无封面',
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
],
),
);
}
/// 构建基本信息
Widget _buildBasicInfo(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 书名
Text(
book.title,
style: const TextStyle(
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.3,
),
),
// 别名(显示在主名称下面,用 / 分隔)
if (book.alternateTitles.isNotEmpty) ...[
const SizedBox(height: 8),
Text(
book.alternateTitles.join(' / '),
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
height: 1.4,
),
),
],
const SizedBox(height: 16),
// 评分和状态
Row(
children: [
if (book.rating != null) ...[
const Icon(
Icon(
Icons.star,
size: 20,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
const SizedBox(width: 4),
Text(
book.rating!.toStringAsFixed(1),
style: const TextStyle(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
const SizedBox(width: 16),
@@ -300,15 +271,12 @@ class _BookDetailPageState extends State<BookDetailPage> {
_buildStatusTag(book),
],
),
const SizedBox(height: 8),
// 时间信息
Text(
'添加于 ${_formatDate(book.createdAt)}',
style: const TextStyle(
style: TextStyle(
fontSize: 12,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
],
@@ -316,33 +284,33 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建状态标签
Widget _buildStatusTag(Book book) {
final colors = Theme.of(context).colorScheme;
String label;
Color bgColor;
Color textColor;
switch (book.status) {
case 'read':
label = '已读';
bgColor = const Color(0xFF1A1A1A);
textColor = Colors.white;
bgColor = colors.primary;
textColor = colors.onPrimary;
break;
case 'reading':
label = '在读';
bgColor = const Color(0xFFF0F0F0);
textColor = const Color(0xFF666666);
bgColor = colors.outlineVariant;
textColor = colors.onSurface.withValues(alpha: 0.6);
break;
case 'want_to_read':
label = '想读';
bgColor = const Color(0xFFF5F5F5);
textColor = const Color(0xFF999999);
bgColor = colors.surfaceContainerHighest;
textColor = colors.onSurface.withValues(alpha: 0.4);
break;
default:
label = '未知';
bgColor = const Color(0xFFEEEEEE);
textColor = const Color(0xFFCCCCCC);
bgColor = colors.outlineVariant;
textColor = colors.onSurface.withValues(alpha: 0.25);
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
@@ -359,30 +327,30 @@ class _BookDetailPageState extends State<BookDetailPage> {
),
);
}
/// 构建作者区域
Widget _buildAuthorsSection(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
SizedBox(
width: 64,
child: Text(
'作者',
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
),
Expanded(
child: Text(
book.authors.join(''),
style: const TextStyle(
style: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.5,
),
),
@@ -392,29 +360,29 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建ISBN区域
Widget _buildIsbnSection(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
SizedBox(
width: 64,
child: Text(
'ISBN',
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
),
Expanded(
child: Text(
book.isbn!,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.5,
),
),
@@ -424,29 +392,29 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建出版社区域
Widget _buildPublisherSection(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
SizedBox(
width: 64,
child: Text(
'出版社',
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
),
Expanded(
child: Text(
book.publisher!,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.5,
),
),
@@ -456,29 +424,29 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建出版时间区域
Widget _buildPublishDateSection(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
SizedBox(
width: 64,
child: Text(
'出版时间',
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
),
Expanded(
child: Text(
'${book.publishDate!.year}${book.publishDate!.month.toString().padLeft(2, '0')}',
style: const TextStyle(
style: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.5,
),
),
@@ -488,20 +456,20 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建类型区域
Widget _buildGenresSection(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
SizedBox(
width: 64,
child: Text(
'类型',
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
),
@@ -513,14 +481,14 @@ class _BookDetailPageState extends State<BookDetailPage> {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(4),
),
child: Text(
genre,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
);
@@ -531,9 +499,9 @@ class _BookDetailPageState extends State<BookDetailPage> {
),
);
}
/// 构建简介区域
Widget _buildSummarySection(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.all(24),
child: Column(
@@ -545,17 +513,17 @@ class _BookDetailPageState extends State<BookDetailPage> {
width: 4,
height: 16,
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.onSurface,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
const Text(
Text(
'简介',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
],
@@ -564,14 +532,14 @@ class _BookDetailPageState extends State<BookDetailPage> {
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
),
child: Text(
book.summary!,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.8,
),
),
@@ -581,8 +549,8 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建额外功能区域(书评、摘抄)
Widget _buildExtraSections(Book book) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.all(24),
child: Column(
@@ -594,23 +562,22 @@ class _BookDetailPageState extends State<BookDetailPage> {
width: 4,
height: 16,
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.onSurface,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
const Text(
Text(
'更多',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
],
),
const SizedBox(height: 16),
// 书评入口
_buildExtraSectionItem(
icon: Icons.rate_review_outlined,
title: '书评',
@@ -620,7 +587,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
onTap: () => _navigateToReviews(book),
),
const SizedBox(height: 12),
// 摘抄入口
_buildExtraSectionItem(
icon: Icons.format_quote_outlined,
title: '摘抄',
@@ -634,7 +600,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 构建更多区域项
Widget _buildExtraSectionItem({
required IconData icon,
required String title,
@@ -643,14 +608,15 @@ class _BookDetailPageState extends State<BookDetailPage> {
required String unit,
required VoidCallback onTap,
}) {
final colors = Theme.of(context).colorScheme;
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border: Border.all(color: colors.outlineVariant, width: 0.5),
),
child: Row(
children: [
@@ -658,14 +624,14 @@ class _BookDetailPageState extends State<BookDetailPage> {
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
color: colors.surface,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border: Border.all(color: colors.outlineVariant, width: 0.5),
),
child: Icon(
icon,
size: 20,
color: const Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
const SizedBox(width: 12),
@@ -675,10 +641,10 @@ class _BookDetailPageState extends State<BookDetailPage> {
children: [
Text(
title,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
const SizedBox(height: 4),
@@ -688,9 +654,9 @@ class _BookDetailPageState extends State<BookDetailPage> {
final count = snapshot.data ?? 0;
return Text(
count > 0 ? '$count $unit' : emptyText,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
);
},
@@ -698,9 +664,9 @@ class _BookDetailPageState extends State<BookDetailPage> {
],
),
),
const Icon(
Icon(
Icons.chevron_right,
color: Color(0xFFCCCCCC),
color: colors.onSurface.withValues(alpha: 0.25),
),
],
),
@@ -726,39 +692,37 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 格式化日期
String _formatDate(DateTime date) {
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
}
/// 跳转到编辑页面
void _navigateToEdit(BuildContext context) {
Navigator.pushNamed(context, '/book-form', arguments: widget.book).then((_) {
context.read<AppProvider>().loadBooks();
});
}
/// 显示删除对话框
void _showDeleteDialog(BuildContext context) {
final colors = Theme.of(context).colorScheme;
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
title: const Text(
title: Text(
'确认删除',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: colors.onSurface,
),
),
content: Text(
'确定要删除"${widget.book.title}"吗?删除后可在回收站恢复。',
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
height: 1.5,
),
),
@@ -766,7 +730,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
TextButton(
onPressed: () => Navigator.pop(context),
style: TextButton.styleFrom(
foregroundColor: const Color(0xFF666666),
foregroundColor: colors.onSurface.withValues(alpha: 0.6),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
child: const Text('取消'),
@@ -780,8 +744,8 @@ class _BookDetailPageState extends State<BookDetailPage> {
ToastUtil.show(context, '已删除');
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
backgroundColor: colors.error,
foregroundColor: colors.onError,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
@@ -796,7 +760,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
);
}
/// 下载封面到本地
Future<void> _downloadCover(Book book) async {
if (book.coverPath == null || book.coverPath!.isEmpty) {
ToastUtil.show(context, '没有可下载的封面');
@@ -810,16 +773,13 @@ class _BookDetailPageState extends State<BookDetailPage> {
return;
}
// 生成文件名书籍名称_时间戳_封面.jpg
final timestamp = DateTime.now().millisecondsSinceEpoch;
final fileName = '${book.title}_${timestamp}_封面.jpg';
// 获取临时目录路径
final tempDir = await Directory.systemTemp.createTemp();
final tempFile = File('${tempDir.path}/$fileName');
await sourceFile.copy(tempFile.path);
// 使用分享功能让用户选择保存位置
await Share.shareXFiles(
[XFile(tempFile.path)],
subject: '${book.title} 封面',
@@ -830,7 +790,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
}
}
/// 显示分享海报页面
void _showSharePoster(Book book) {
Navigator.push(
context,

View File

@@ -50,8 +50,9 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
title: Text(_isEditing ? '编辑摘抄' : '添加摘抄'),
actions: [
@@ -63,10 +64,10 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text(
: Text(
'保存',
style: TextStyle(
color: Color(0xFF1A1A1A),
color: colors.onSurface,
fontWeight: FontWeight.w600,
),
),
@@ -82,15 +83,15 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
// 章节
TextFormField(
controller: _chapterController,
decoration: const InputDecoration(
decoration: InputDecoration(
labelText: '章节(可选)',
hintText: '例如第一章、第3节等',
border: OutlineInputBorder(
border: const OutlineInputBorder(
borderRadius: BorderRadius.zero,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide: BorderSide(color: Color(0xFF1A1A1A)),
borderSide: BorderSide(color: colors.primary),
),
),
),
@@ -101,16 +102,16 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
TextFormField(
controller: _contentController,
maxLines: 8,
decoration: const InputDecoration(
decoration: InputDecoration(
labelText: '摘抄内容',
hintText: '输入你想要摘抄的内容...',
alignLabelWithHint: true,
border: OutlineInputBorder(
border: const OutlineInputBorder(
borderRadius: BorderRadius.zero,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide: BorderSide(color: Color(0xFF1A1A1A)),
borderSide: BorderSide(color: colors.primary),
),
),
validator: (value) {
@@ -127,16 +128,16 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
TextFormField(
controller: _commentController,
maxLines: 5,
decoration: const InputDecoration(
decoration: InputDecoration(
labelText: '我的感悟(可选)',
hintText: '记录你对这段内容的思考和感悟...',
alignLabelWithHint: true,
border: OutlineInputBorder(
border: const OutlineInputBorder(
borderRadius: BorderRadius.zero,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.zero,
borderSide: BorderSide(color: Color(0xFF1A1A1A)),
borderSide: BorderSide(color: colors.primary),
),
),
),
@@ -185,4 +186,3 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
}
}
}

View File

@@ -41,8 +41,9 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
title: const Text('摘抄'),
actions: [
@@ -62,6 +63,7 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
}
Widget _buildEmptyState() {
final colors = Theme.of(context).colorScheme;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -70,21 +72,21 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
width: 80,
height: 80,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
child: Icon(
Icons.format_quote_outlined,
size: 40,
color: Color(0xFFCCCCCC),
color: colors.onSurface.withValues(alpha: 0.25),
),
),
const SizedBox(height: 20),
const Text(
Text(
'暂无摘抄',
style: TextStyle(
fontSize: 16,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
const SizedBox(height: 24),
@@ -93,15 +95,15 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.primary,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
child: Text(
'添加记录',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white,
color: colors.onPrimary,
),
),
),
@@ -114,7 +116,7 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
/// 按章节分组摘抄数据
Map<String, List<BookExcerpt>> _groupExcerptsByChapter() {
final Map<String, List<BookExcerpt>> groups = {};
for (final excerpt in _excerpts) {
final chapter = excerpt.chapter.isEmpty ? '未分类' : excerpt.chapter;
if (!groups.containsKey(chapter)) {
@@ -122,19 +124,19 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
}
groups[chapter]!.add(excerpt);
}
// 每个章节内的摘抄按时间排序(新的在前)
for (final chapter in groups.keys) {
groups[chapter]!.sort((a, b) => b.createdAt.compareTo(a.createdAt));
}
return groups;
}
Widget _buildExcerptList() {
final groups = _groupExcerptsByChapter();
final chapters = groups.keys.toList();
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: chapters.length,
@@ -147,6 +149,7 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
}
Widget _buildChapterSection(String chapter, List<BookExcerpt> excerpts) {
final colors = Theme.of(context).colorScheme;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -154,18 +157,18 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
decoration: const BoxDecoration(
color: Color(0xFFF5F5F5),
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
border: Border(
left: BorderSide(color: Color(0xFF1A1A1A), width: 4),
left: BorderSide(color: colors.primary, width: 4),
),
),
child: Text(
chapter,
style: const TextStyle(
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
),
@@ -178,11 +181,12 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
}
Widget _buildExcerptItem(BookExcerpt excerpt) {
final colors = Theme.of(context).colorScheme;
return Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFE5E5E5)),
border: Border.all(color: colors.outline),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -192,9 +196,9 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
excerpt.content,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.5,
),
),
@@ -205,16 +209,16 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
decoration: const BoxDecoration(
color: Color(0xFFF5F5F5),
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
),
child: Text(
excerpt.comment,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
style: TextStyle(
fontSize: 12,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
),
@@ -227,29 +231,29 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
children: [
Text(
_formatDate(excerpt.createdAt),
style: const TextStyle(
style: TextStyle(
fontSize: 11,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
const Spacer(),
// 编辑按钮
GestureDetector(
onTap: () => _navigateToEditExcerpt(excerpt),
child: const Icon(
child: Icon(
Icons.edit_outlined,
size: 16,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
const SizedBox(width: 12),
// 删除按钮
GestureDetector(
onTap: () => _showDeleteDialog(excerpt),
child: const Icon(
child: Icon(
Icons.delete_outline,
size: 16,
color: Colors.red,
color: colors.error,
),
),
],
@@ -287,28 +291,31 @@ class _BookExcerptsPageState extends State<BookExcerptsPage> {
void _showDeleteDialog(BookExcerpt excerpt) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('确认删除'),
content: const Text('确定要删除这条摘抄吗?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
),
TextButton(
onPressed: () async {
await context.read<AppProvider>().removeBookExcerpt(excerpt.id);
Navigator.pop(context);
_loadExcerpts();
ToastUtil.show(context, '已删除');
},
child: const Text('删除', style: TextStyle(color: Colors.red)),
),
],
),
builder: (context) {
final colors = Theme.of(context).colorScheme;
return AlertDialog(
backgroundColor: colors.surface,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('确认删除'),
content: const Text('确定要删除这条摘抄吗?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.6))),
),
TextButton(
onPressed: () async {
await context.read<AppProvider>().removeBookExcerpt(excerpt.id);
Navigator.pop(context);
_loadExcerpts();
ToastUtil.show(context, '删除');
},
child: Text('删除', style: TextStyle(color: colors.error)),
),
],
);
},
);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -49,8 +49,9 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
title: const Text('书评详情'),
actions: [
@@ -70,9 +71,9 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
// 书评内容
Text(
_review.content,
style: const TextStyle(
style: TextStyle(
fontSize: 16,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.8,
),
),
@@ -82,7 +83,7 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
// 分隔线
Container(
height: 0.5,
color: const Color(0xFFE5E5E5),
color: colors.outline,
),
const SizedBox(height: 24),
@@ -92,6 +93,7 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
icon: Icons.person_outline,
label: '书评人:',
value: _review.reviewer.isNotEmpty ? _review.reviewer : '匿名',
colors: colors,
),
const SizedBox(height: 16),
@@ -102,6 +104,7 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
icon: Icons.source_outlined,
label: '来源:',
value: _review.source,
colors: colors,
),
if (_review.source.isNotEmpty) const SizedBox(height: 16),
@@ -111,6 +114,7 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
icon: Icons.category_outlined,
label: '类型:',
value: _review.typeText,
colors: colors,
),
const SizedBox(height: 16),
@@ -120,6 +124,7 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
icon: Icons.access_time,
label: '时间:',
value: _formatDate(_review.createdAt),
colors: colors,
),
],
),
@@ -132,29 +137,30 @@ class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
required IconData icon,
required String label,
required String value,
required ColorScheme colors,
}) {
return Row(
children: [
Icon(
icon,
size: 20,
color: const Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
const SizedBox(width: 12),
Text(
label,
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
const SizedBox(width: 16),
Expanded(
child: Text(
value,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
),

View File

@@ -47,10 +47,11 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final isEdit = widget.review != null;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
title: Text(isEdit ? '编辑书评' : '写书评'),
actions: [
@@ -74,24 +75,24 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
// 顶部信息栏
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: const BoxDecoration(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Color(0xFFE5E5E5), width: 0.5),
bottom: BorderSide(color: colors.outline, width: 0.5),
),
),
child: Row(
children: [
// 类型选择
_buildTypeSelector(),
_buildTypeSelector(colors),
const SizedBox(width: 16),
// 评论人
Expanded(
child: TextField(
controller: _reviewerController,
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
decoration: const InputDecoration(
style: TextStyle(fontSize: 14, color: colors.onSurface),
decoration: InputDecoration(
hintText: '评论人',
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.25)),
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.zero,
@@ -104,10 +105,10 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
width: 100,
child: TextField(
controller: _sourceController,
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
decoration: const InputDecoration(
style: TextStyle(fontSize: 14, color: colors.onSurface),
decoration: InputDecoration(
hintText: '来源',
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.25)),
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.zero,
@@ -125,19 +126,19 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
maxLines: null,
expands: true,
textAlignVertical: TextAlignVertical.top,
style: const TextStyle(
style: TextStyle(
fontSize: 16,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.7,
),
decoration: const InputDecoration(
decoration: InputDecoration(
hintText: '写下你的书评...',
hintStyle: TextStyle(
fontSize: 16,
color: Color(0xFFCCCCCC),
color: colors.onSurface.withValues(alpha: 0.25),
),
border: InputBorder.none,
contentPadding: EdgeInsets.all(16),
contentPadding: const EdgeInsets.all(16),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
@@ -154,29 +155,29 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
}
/// 构建类型选择器
Widget _buildTypeSelector() {
Widget _buildTypeSelector(ColorScheme colors) {
return GestureDetector(
onTap: () => _showTypeSelector(),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFE5E5E5)),
border: Border.all(color: colors.outline),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_reviewType == 1 ? '短评' : '长评',
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
const SizedBox(width: 4),
const Icon(
Icon(
Icons.arrow_drop_down,
size: 16,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
],
),
@@ -188,36 +189,42 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
void _showTypeSelector() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.white,
backgroundColor: Colors.transparent,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
builder: (context) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: const Text('短评'),
trailing: _reviewType == 1
? const Icon(Icons.check, color: Color(0xFF1A1A1A))
: null,
onTap: () {
setState(() => _reviewType = 1);
Navigator.pop(context);
},
builder: (context) {
final colors = Theme.of(context).colorScheme;
return Container(
color: colors.surface,
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: const Text('短评'),
trailing: _reviewType == 1
? Icon(Icons.check, color: colors.onSurface)
: null,
onTap: () {
setState(() => _reviewType = 1);
Navigator.pop(context);
},
),
Divider(height: 0.5, color: colors.outline),
ListTile(
title: const Text('长评'),
trailing: _reviewType == 2
? Icon(Icons.check, color: colors.onSurface)
: null,
onTap: () {
setState(() => _reviewType = 2);
Navigator.pop(context);
},
),
],
),
const Divider(height: 0.5),
ListTile(
title: const Text('长评'),
trailing: _reviewType == 2
? const Icon(Icons.check, color: Color(0xFF1A1A1A))
: null,
onTap: () {
setState(() => _reviewType = 2);
Navigator.pop(context);
},
),
],
),
),
),
);
},
);
}
@@ -259,4 +266,3 @@ class _BookReviewFormPageState extends State<BookReviewFormPage> {
Navigator.pop(context);
}
}

View File

@@ -73,19 +73,20 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
title: _isSearching
? TextField(
controller: _searchController,
autofocus: true,
decoration: const InputDecoration(
decoration: InputDecoration(
hintText: '搜索书评内容、书评人、来源...',
hintStyle: TextStyle(color: Color(0xFF999999)),
hintStyle: TextStyle(color: colors.onSurface.withValues(alpha: 0.4)),
border: InputBorder.none,
),
style: const TextStyle(color: Color(0xFF1A1A1A)),
style: TextStyle(color: colors.onSurface),
onChanged: _onSearchChanged,
)
: const Text('书评'),
@@ -112,6 +113,7 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
}
Widget _buildEmptyState() {
final colors = Theme.of(context).colorScheme;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@@ -120,21 +122,21 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
width: 80,
height: 80,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
child: Icon(
Icons.rate_review_outlined,
size: 40,
color: Color(0xFFCCCCCC),
color: colors.onSurface.withValues(alpha: 0.25),
),
),
const SizedBox(height: 20),
const Text(
Text(
'暂无书评',
style: TextStyle(
fontSize: 16,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
const SizedBox(height: 24),
@@ -143,15 +145,15 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.primary,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
child: Text(
'添加记录',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white,
color: colors.onPrimary,
),
),
),
@@ -176,13 +178,14 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
}
Widget _buildReviewCard(BookReview review) {
final colors = Theme.of(context).colorScheme;
return InkWell(
onTap: () => _navigateToReviewDetail(review),
onLongPress: () => _showDeleteDialog(review),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Column(
@@ -193,8 +196,8 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: review.reviewType == 1
? Colors.white
: const Color(0xFF1A1A1A),
? colors.surface
: colors.primary,
borderRadius: BorderRadius.circular(4),
),
child: Text(
@@ -202,8 +205,8 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
style: TextStyle(
fontSize: 10,
color: review.reviewType == 1
? const Color(0xFF666666)
: Colors.white,
? colors.onSurface.withValues(alpha: 0.6)
: colors.onPrimary,
),
),
),
@@ -215,9 +218,9 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
review.content,
maxLines: review.reviewType == 1 ? 4 : 8,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.5,
),
),
@@ -232,9 +235,9 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
Expanded(
child: Text(
review.reviewer,
style: const TextStyle(
style: TextStyle(
fontSize: 11,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
overflow: TextOverflow.ellipsis,
),
@@ -252,9 +255,9 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
Expanded(
child: Text(
review.source,
style: const TextStyle(
style: TextStyle(
fontSize: 10,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
overflow: TextOverflow.ellipsis,
),
@@ -262,9 +265,9 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
// 日期
Text(
_formatDate(review.createdAt),
style: const TextStyle(
style: TextStyle(
fontSize: 10,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
],
@@ -315,28 +318,31 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
void _showDeleteDialog(BookReview review) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('确认删除'),
content: const Text('确定要删除这条书评吗?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
),
TextButton(
onPressed: () async {
await context.read<AppProvider>().removeBookReview(review.id);
Navigator.pop(context);
_loadReviews();
ToastUtil.show(context, '已删除');
},
child: const Text('删除', style: TextStyle(color: Colors.red)),
),
],
),
builder: (context) {
final colors = Theme.of(context).colorScheme;
return AlertDialog(
backgroundColor: colors.surface,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: const Text('确认删除'),
content: const Text('确定要删除这条书评吗?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.6))),
),
TextButton(
onPressed: () async {
await context.read<AppProvider>().removeBookReview(review.id);
Navigator.pop(context);
_loadReviews();
ToastUtil.show(context, '删除');
},
child: Text('删除', style: TextStyle(color: colors.error)),
),
],
);
},
);
}
}

View File

@@ -23,21 +23,22 @@ class _BookSharePageState extends State<BookSharePage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
backgroundColor: colors.surfaceContainerHighest,
appBar: AppBar(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.close, color: Color(0xFF1A1A1A)),
icon: Icon(Icons.close, color: colors.onSurface),
onPressed: () => Navigator.pop(context),
),
title: const Text(
title: Text(
'分享海报',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
centerTitle: true,
@@ -50,12 +51,12 @@ class _BookSharePageState extends State<BookSharePage> {
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text(
: Text(
'分享',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
),
@@ -76,13 +77,14 @@ class _BookSharePageState extends State<BookSharePage> {
/// 构建海报 Widget
Widget _buildPosterWidget() {
final colors = Theme.of(context).colorScheme;
final book = widget.book;
final hasCover = book.coverPath != null && book.coverPath!.isNotEmpty;
return Container(
width: 320,
decoration: BoxDecoration(
color: Colors.white,
color: colors.surface,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
@@ -117,10 +119,10 @@ class _BookSharePageState extends State<BookSharePage> {
// 书名
Text(
book.title,
style: const TextStyle(
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
@@ -129,9 +131,9 @@ class _BookSharePageState extends State<BookSharePage> {
const SizedBox(height: 8),
Text(
book.alternateTitles.join(' / '),
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
],
@@ -157,11 +159,11 @@ class _BookSharePageState extends State<BookSharePage> {
),
),
const SizedBox(width: 4),
const Text(
Text(
'/ 10',
style: TextStyle(
fontSize: 12,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
],
@@ -171,44 +173,45 @@ class _BookSharePageState extends State<BookSharePage> {
// 作者
if (book.authors.isNotEmpty)
_buildInfoRow('作者', book.authors.join(' / ')),
_buildInfoRow('作者', book.authors.join(' / '), colors),
// 出版社
if (book.publisher != null && book.publisher!.isNotEmpty)
_buildInfoRow('出版社', book.publisher!),
_buildInfoRow('出版社', book.publisher!, colors),
// 出版时间
if (book.publishDate != null)
_buildInfoRow(
'出版',
'${book.publishDate!.year}.${book.publishDate!.month.toString().padLeft(2, '0')}.${book.publishDate!.day.toString().padLeft(2, '0')}',
colors,
),
// 类型
if (book.genres.isNotEmpty)
_buildInfoRow('类型', book.genres.join(' / ')),
_buildInfoRow('类型', book.genres.join(' / '), colors),
// ISBN
if (book.isbn != null && book.isbn!.isNotEmpty)
_buildInfoRow('ISBN', book.isbn!),
_buildInfoRow('ISBN', book.isbn!, colors),
const SizedBox(height: 16),
// 简介
if (book.summary != null && book.summary!.isNotEmpty) ...[
const Text(
Text(
'简介',
style: TextStyle(
fontSize: 12,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
const SizedBox(height: 8),
Text(
book.summary!,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
height: 1.6,
),
maxLines: 5,
@@ -219,7 +222,7 @@ class _BookSharePageState extends State<BookSharePage> {
const SizedBox(height: 20),
// 底部标识
const Divider(height: 1, color: Color(0xFFE8E8E8)),
Divider(height: 1, color: colors.outline),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.center,
@@ -227,14 +230,14 @@ class _BookSharePageState extends State<BookSharePage> {
Icon(
Icons.book_outlined,
size: 14,
color: const Color(0xFF1A1A1A).withOpacity(0.5),
color: colors.onSurface.withValues(alpha: 0.5),
),
const SizedBox(width: 6),
Text(
'来自 MookNote',
style: TextStyle(
fontSize: 12,
color: const Color(0xFF1A1A1A).withOpacity(0.5),
color: colors.onSurface.withValues(alpha: 0.5),
),
),
],
@@ -248,7 +251,7 @@ class _BookSharePageState extends State<BookSharePage> {
}
/// 构建信息行
Widget _buildInfoRow(String label, String value) {
Widget _buildInfoRow(String label, String value, ColorScheme colors) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Row(
@@ -256,17 +259,17 @@ class _BookSharePageState extends State<BookSharePage> {
children: [
Text(
'$label',
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF999999),
color: colors.onSurface.withValues(alpha: 0.4),
),
),
Expanded(
child: Text(
value,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF333333),
color: colors.onSurface.withValues(alpha: 0.75),
),
),
),

View File

@@ -17,7 +17,7 @@ class BookTabPage extends StatefulWidget {
}
class _BookTabPageState extends State<BookTabPage> {
int _layoutStyle = 0; // 0: 封面网格, 1: 列表
int _layoutStyle = 0;
bool _firstLoad = true;
@override
@@ -42,6 +42,7 @@ class _BookTabPageState extends State<BookTabPage> {
}
Widget _buildBookList(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Consumer<AppProvider>(
builder: (context, provider, child) {
final statusMap = {0: 'read', 1: 'reading', 2: 'want_to_read'};
@@ -55,8 +56,8 @@ class _BookTabPageState extends State<BookTabPage> {
if (books.isEmpty) {
return RefreshIndicator(
onRefresh: () async => await provider.loadBooks(),
color: const Color(0xFF1A1A1A),
backgroundColor: Colors.white,
color: colors.primary,
backgroundColor: colors.surface,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [_buildEmptyState(context, provider.bookStatusIndex)],
@@ -73,10 +74,11 @@ class _BookTabPageState extends State<BookTabPage> {
}
Widget _buildGridView(List books, AppProvider provider) {
final colors = Theme.of(context).colorScheme;
return RefreshIndicator(
onRefresh: () async => await provider.loadBooks(),
color: const Color(0xFF1A1A1A),
backgroundColor: Colors.white,
color: colors.primary,
backgroundColor: colors.surface,
child: GridView.builder(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 100),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
@@ -92,10 +94,11 @@ class _BookTabPageState extends State<BookTabPage> {
}
Widget _buildListView(List books, AppProvider provider) {
final colors = Theme.of(context).colorScheme;
return RefreshIndicator(
onRefresh: () async => await provider.loadBooks(),
color: const Color(0xFF1A1A1A),
backgroundColor: Colors.white,
color: colors.primary,
backgroundColor: colors.surface,
child: ListView.builder(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 100),
itemCount: books.length,
@@ -105,6 +108,7 @@ class _BookTabPageState extends State<BookTabPage> {
}
Widget _buildListCard(book) {
final colors = Theme.of(context).colorScheme;
return GestureDetector(
onTap: () => Navigator.pushNamed(context, '/book-detail', arguments: book),
onLongPress: () => _showDeleteDialog(context, book),
@@ -112,23 +116,22 @@ class _BookTabPageState extends State<BookTabPage> {
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
// 封面缩略图
Container(
width: 48, height: 64,
decoration: BoxDecoration(
color: const Color(0xFFF0F0F0),
color: colors.outlineVariant,
borderRadius: BorderRadius.circular(6),
),
clipBehavior: Clip.antiAlias,
child: book.coverPath != null && book.coverPath!.isNotEmpty
? Image.file(File(book.coverPath!), fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Icon(Icons.menu_book_outlined, size: 22, color: Color(0xFFCCCCCC)))
: const Icon(Icons.menu_book_outlined, size: 22, color: Color(0xFFCCCCCC)),
errorBuilder: (_, __, ___) => Icon(Icons.menu_book_outlined, size: 22, color: colors.onSurface.withValues(alpha: 0.25)))
: Icon(Icons.menu_book_outlined, size: 22, color: colors.onSurface.withValues(alpha: 0.25)),
),
const SizedBox(width: 12),
Expanded(
@@ -136,11 +139,11 @@ class _BookTabPageState extends State<BookTabPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(book.title, maxLines: 1, overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: colors.onSurface)),
if (book.authors.isNotEmpty) ...[
const SizedBox(height: 3),
Text(book.authors.take(2).join(''), maxLines: 1, overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12, color: Color(0xFFAAAAAA))),
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.35))),
],
const SizedBox(height: 6),
if (book.rating != null)
@@ -151,7 +154,7 @@ class _BookTabPageState extends State<BookTabPage> {
),
),
const SizedBox(width: 8),
const Icon(Icons.chevron_right, color: Color(0xFFD0D0D0), size: 20),
Icon(Icons.chevron_right, color: colors.onSurface.withValues(alpha: 0.2), size: 20),
],
),
),
@@ -159,19 +162,20 @@ class _BookTabPageState extends State<BookTabPage> {
}
void _showDeleteDialog(BuildContext context, book) {
final colors = Theme.of(context).colorScheme;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
title: const Text('确认删除', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
title: Text('确认删除', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
content: Text('确定要删除《${book.title}》吗?删除后可在回收站恢复。',
style: const TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.5)),
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.6))),
),
ElevatedButton(
onPressed: () async {
@@ -179,7 +183,7 @@ class _BookTabPageState extends State<BookTabPage> {
Navigator.pop(ctx);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red, foregroundColor: Colors.white, elevation: 0,
backgroundColor: colors.error, foregroundColor: colors.onError, elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
@@ -193,11 +197,12 @@ class _BookTabPageState extends State<BookTabPage> {
Widget _buildSkeleton() {
return _layoutStyle == 1
? MovieSkeletonGrid() // reuse same grid skeleton pattern
? MovieSkeletonGrid()
: const BookSkeletonGrid();
}
Widget _buildEmptyState(BuildContext context, int statusIndex) {
final colors = Theme.of(context).colorScheme;
final statusText = ['已读', '在读', '想读'][statusIndex];
return Center(
child: Column(
@@ -205,11 +210,11 @@ class _BookTabPageState extends State<BookTabPage> {
children: [
Container(
width: 80, height: 80,
decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(20)),
child: const Icon(Icons.menu_book_outlined, size: 40, color: Color(0xFFCCCCCC)),
decoration: BoxDecoration(color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(20)),
child: Icon(Icons.menu_book_outlined, size: 40, color: colors.onSurface.withValues(alpha: 0.25)),
),
const SizedBox(height: 20),
Text('暂无$statusText的书籍', style: const TextStyle(fontSize: 16, color: Color(0xFF999999))),
Text('暂无$statusText的书籍', style: TextStyle(fontSize: 16, color: colors.onSurface.withValues(alpha: 0.4))),
const SizedBox(height: 24),
InkWell(
onTap: () {
@@ -218,8 +223,8 @@ class _BookTabPageState extends State<BookTabPage> {
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
decoration: BoxDecoration(color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(8)),
child: const Text('添加记录', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
decoration: BoxDecoration(color: colors.primary, borderRadius: BorderRadius.circular(8)),
child: Text('添加记录', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: colors.onPrimary)),
),
),
],