generated from dellevin/template
v0.1.6版本
This commit is contained in:
@@ -60,13 +60,21 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
// 作者信息
|
||||
_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.genres.isNotEmpty)
|
||||
_buildGenresSection(book),
|
||||
// 出版时间
|
||||
if (book.publishDate != null)
|
||||
_buildPublishDateSection(book),
|
||||
|
||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||
|
||||
@@ -86,11 +94,41 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
],
|
||||
),
|
||||
|
||||
// 底部操作栏
|
||||
bottomNavigationBar: _buildBottomBar(),
|
||||
// 底部无操作栏,编辑和删除在右上角
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建右上角操作按钮
|
||||
Widget _buildActionButton({
|
||||
required IconData icon,
|
||||
required VoidCallback onPressed,
|
||||
required String tooltip,
|
||||
Color color = const Color(0xFF666666),
|
||||
}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建顶部 AppBar
|
||||
Widget _buildSliverAppBar(Book book) {
|
||||
final hasCover = book.coverPath != null && book.coverPath!.isNotEmpty;
|
||||
@@ -105,40 +143,30 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
actions: [
|
||||
// 下载封面按钮(仅当有封面时显示)
|
||||
if (hasCover)
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.download_outlined, color: Color(0xFF666666)),
|
||||
onPressed: () => _downloadCover(book),
|
||||
tooltip: '下载封面',
|
||||
),
|
||||
_buildActionButton(
|
||||
icon: Icons.download_outlined,
|
||||
onPressed: () => _downloadCover(book),
|
||||
tooltip: '下载封面',
|
||||
),
|
||||
// 清空封面按钮(仅当有封面时显示)
|
||||
if (hasCover)
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.hide_image_outlined, color: Color(0xFF666666)),
|
||||
onPressed: () => _showClearCoverDialog(book),
|
||||
tooltip: '清空封面',
|
||||
),
|
||||
_buildActionButton(
|
||||
icon: Icons.hide_image_outlined,
|
||||
onPressed: () => _showClearCoverDialog(book),
|
||||
tooltip: '清空封面',
|
||||
),
|
||||
// 编辑按钮
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.edit_outlined, color: Color(0xFF1A1A1A)),
|
||||
onPressed: () => _navigateToEdit(context),
|
||||
),
|
||||
_buildActionButton(
|
||||
icon: Icons.edit_outlined,
|
||||
onPressed: () => _navigateToEdit(context),
|
||||
tooltip: '编辑',
|
||||
),
|
||||
// 删除按钮
|
||||
_buildActionButton(
|
||||
icon: Icons.delete_outline,
|
||||
color: Colors.red,
|
||||
onPressed: () => _showDeleteDialog(context),
|
||||
tooltip: '删除',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
@@ -256,36 +284,42 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
/// 构建状态标签
|
||||
Widget _buildStatusTag(Book book) {
|
||||
String label;
|
||||
Color color;
|
||||
Color bgColor;
|
||||
Color textColor;
|
||||
switch (book.status) {
|
||||
case 'read':
|
||||
label = '已读';
|
||||
color = const Color(0xFF1A1A1A);
|
||||
bgColor = const Color(0xFF1A1A1A);
|
||||
textColor = Colors.white;
|
||||
break;
|
||||
case 'reading':
|
||||
label = '在读';
|
||||
color = const Color(0xFF666666);
|
||||
bgColor = const Color(0xFFF0F0F0);
|
||||
textColor = const Color(0xFF666666);
|
||||
break;
|
||||
case 'want_to_read':
|
||||
label = '想读';
|
||||
color = const Color(0xFF999999);
|
||||
bgColor = const Color(0xFFF5F5F5);
|
||||
textColor = const Color(0xFF999999);
|
||||
break;
|
||||
default:
|
||||
label = '未知';
|
||||
color = const Color(0xFFCCCCCC);
|
||||
bgColor = const Color(0xFFEEEEEE);
|
||||
textColor = const Color(0xFFCCCCCC);
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -294,109 +328,169 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
/// 构建作者区域
|
||||
Widget _buildAuthorsSection(Book book) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'作者',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF999999),
|
||||
letterSpacing: 1,
|
||||
const SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
'作者',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: book.authors.map((author) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F5F5),
|
||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
||||
),
|
||||
child: Text(
|
||||
author,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
Expanded(
|
||||
child: Text(
|
||||
book.authors.join(','),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 构建ISBN区域
|
||||
Widget _buildIsbnSection(Book book) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
'ISBN',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
book.isbn!,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建出版社区域
|
||||
Widget _buildPublisherSection(Book book) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
|
||||
child: Column(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'出版社',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF999999),
|
||||
letterSpacing: 1,
|
||||
const SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
'出版社',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
book.publisher!,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
Expanded(
|
||||
child: Text(
|
||||
book.publisher!,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 构建出版时间区域
|
||||
Widget _buildPublishDateSection(Book book) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
'出版时间',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${book.publishDate!.year}年${book.publishDate!.month.toString().padLeft(2, '0')}月',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建类型区域
|
||||
Widget _buildGenresSection(Book book) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
|
||||
child: Column(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'类型',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF999999),
|
||||
letterSpacing: 1,
|
||||
const SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
'类型',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: book.genres.map((genre) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
||||
),
|
||||
child: Text(
|
||||
genre,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF666666),
|
||||
Expanded(
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: book.genres.map((genre) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F5F5),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
child: Text(
|
||||
genre,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF666666),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -410,22 +504,41 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'简介',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF999999),
|
||||
letterSpacing: 1,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A1A),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'简介',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
book.summary!,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.6,
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFAFAFA),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
book.summary!,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.8,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -440,124 +553,122 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'更多',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF999999),
|
||||
letterSpacing: 1,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 4,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A1A),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text(
|
||||
'更多',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 书评入口
|
||||
GestureDetector(
|
||||
_buildExtraSectionItem(
|
||||
icon: Icons.rate_review_outlined,
|
||||
title: '书评',
|
||||
subtitleFuture: context.read<AppProvider>().getBookReviewCount(book.id),
|
||||
emptyText: '暂无书评',
|
||||
unit: '条书评',
|
||||
onTap: () => _navigateToReviews(book),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.rate_review_outlined,
|
||||
size: 24,
|
||||
color: Color(0xFF666666),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'书评',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
FutureBuilder<int>(
|
||||
future: context.read<AppProvider>().getBookReviewCount(book.id),
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data ?? 0;
|
||||
return Text(
|
||||
count > 0 ? '$count 条书评' : '暂无书评',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 摘抄入口
|
||||
GestureDetector(
|
||||
_buildExtraSectionItem(
|
||||
icon: Icons.format_quote_outlined,
|
||||
title: '摘抄',
|
||||
subtitleFuture: context.read<AppProvider>().getBookExcerptCount(book.id),
|
||||
emptyText: '暂无摘抄',
|
||||
unit: '条摘抄',
|
||||
onTap: () => _navigateToExcerpts(book),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建更多区域项
|
||||
Widget _buildExtraSectionItem({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required Future<int> subtitleFuture,
|
||||
required String emptyText,
|
||||
required String unit,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFAFAFA),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
child: Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: const Color(0xFF666666),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.format_quote_outlined,
|
||||
size: 24,
|
||||
color: Color(0xFF666666),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'摘抄',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
FutureBuilder<int>(
|
||||
future: context.read<AppProvider>().getBookExcerptCount(book.id),
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data ?? 0;
|
||||
return Text(
|
||||
count > 0 ? '$count 条摘抄' : '暂无摘抄',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
color: Color(0xFF999999),
|
||||
const SizedBox(height: 4),
|
||||
FutureBuilder<int>(
|
||||
future: subtitleFuture,
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data ?? 0;
|
||||
return Text(
|
||||
count > 0 ? '$count $unit' : emptyText,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
color: Color(0xFFCCCCCC),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -580,51 +691,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建底部操作栏
|
||||
Widget _buildBottomBar() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: Color(0xFFE5E5E5), width: 0.5),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => _navigateToEdit(context),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF1A1A1A),
|
||||
side: const BorderSide(color: Color(0xFF1A1A1A)),
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
child: const Text('编辑'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => _showDeleteDialog(context),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.red,
|
||||
side: const BorderSide(color: Colors.red),
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
),
|
||||
child: const Text('删除'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 格式化日期
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
@@ -644,15 +711,32 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
title: const Text('确认删除'),
|
||||
content: Text('确定要删除"${widget.book.title}"吗?'),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: const Text(
|
||||
'确认删除',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
'确定要删除"${widget.book.title}"吗?删除后可在回收站恢复。',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF666666),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF666666),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await context.read<AppProvider>().removeBook(widget.book.id);
|
||||
if (!mounted) return;
|
||||
@@ -660,9 +744,19 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
Navigator.pop(context);
|
||||
ToastUtil.show(context, '已删除');
|
||||
},
|
||||
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -674,15 +768,32 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
|
||||
title: const Text('清空封面'),
|
||||
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: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消', style: TextStyle(color: Color(0xFF666666))),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF666666),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
final updatedBook = book.copyWith(
|
||||
@@ -694,9 +805,19 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
||||
ToastUtil.show(context, '封面已清空');
|
||||
}
|
||||
},
|
||||
child: const Text('清空', style: TextStyle(color: Colors.red)),
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
late TextEditingController _publisherController;
|
||||
late TextEditingController _summaryController;
|
||||
late TextEditingController _ratingController;
|
||||
late TextEditingController _isbnController;
|
||||
|
||||
// 多值字段的临时输入控制器
|
||||
final Map<String, TextEditingController> _tagControllers = {};
|
||||
@@ -39,6 +40,7 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
List<String> _genres = [];
|
||||
String? _coverPath;
|
||||
String _status = 'want_to_read';
|
||||
DateTime? _publishDate;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -63,6 +65,7 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
_publisherController = TextEditingController(text: book?.publisher ?? '');
|
||||
_summaryController = TextEditingController(text: book?.summary ?? '');
|
||||
_ratingController = TextEditingController(text: book?.rating?.toString() ?? '');
|
||||
_isbnController = TextEditingController(text: book?.isbn ?? '');
|
||||
|
||||
if (book != null) {
|
||||
_authors = List.from(book.authors);
|
||||
@@ -70,6 +73,7 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
_genres = List.from(book.genres);
|
||||
_coverPath = book.coverPath;
|
||||
_status = book.status;
|
||||
_publishDate = book.publishDate;
|
||||
} else if (widget.initialStatus != null) {
|
||||
// 添加模式:使用传入的默认状态
|
||||
_status = widget.initialStatus!;
|
||||
@@ -82,6 +86,7 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
_publisherController.dispose();
|
||||
_summaryController.dispose();
|
||||
_ratingController.dispose();
|
||||
_isbnController.dispose();
|
||||
_tagControllers.values.forEach((c) => c.dispose());
|
||||
super.dispose();
|
||||
}
|
||||
@@ -90,24 +95,51 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
return _tagControllers.putIfAbsent(key, () => TextEditingController());
|
||||
}
|
||||
|
||||
/// 构建右上角操作按钮
|
||||
Widget _buildActionButton({
|
||||
required IconData icon,
|
||||
required VoidCallback onPressed,
|
||||
required String tooltip,
|
||||
Color color = const Color(0xFF1A1A1A),
|
||||
}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isEdit = widget.book != null;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: Text(isEdit ? '编辑书籍' : '添加书籍'),
|
||||
actions: [
|
||||
TextButton(
|
||||
// 保存按钮
|
||||
_buildActionButton(
|
||||
icon: Icons.save_outlined,
|
||||
onPressed: _saveBook,
|
||||
child: const Text(
|
||||
'保存',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
tooltip: '保存',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
@@ -132,9 +164,10 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 基本信息区域
|
||||
_buildFormItem(
|
||||
label: '书名 *',
|
||||
// 书名
|
||||
_buildHorizontalFormItem(
|
||||
label: '书名',
|
||||
required: true,
|
||||
child: TextFormField(
|
||||
controller: _titleController,
|
||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||
@@ -153,10 +186,10 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
),
|
||||
),
|
||||
|
||||
_buildDivider(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 别名
|
||||
_buildMultiValueItem(
|
||||
_buildHorizontalMultiValueItem(
|
||||
label: '别名',
|
||||
values: _alternateTitles,
|
||||
hint: '输入别名',
|
||||
@@ -165,10 +198,10 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
onRemove: (i) => setState(() => _alternateTitles.removeAt(i)),
|
||||
),
|
||||
|
||||
_buildDivider(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 作者
|
||||
_buildMultiValueItem(
|
||||
_buildHorizontalMultiValueItem(
|
||||
label: '作者',
|
||||
values: _authors,
|
||||
hint: '输入作者姓名',
|
||||
@@ -177,10 +210,10 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
onRemove: (i) => setState(() => _authors.removeAt(i)),
|
||||
),
|
||||
|
||||
_buildDivider(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 出版社
|
||||
_buildFormItem(
|
||||
_buildHorizontalFormItem(
|
||||
label: '出版社',
|
||||
child: TextFormField(
|
||||
controller: _publisherController,
|
||||
@@ -194,19 +227,63 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
),
|
||||
),
|
||||
|
||||
_buildDivider(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 类型
|
||||
_buildMultiValueItem(
|
||||
_buildHorizontalMultiValueItem(
|
||||
label: '类型',
|
||||
values: _genres,
|
||||
hint: '如:小说、历史',
|
||||
hint: '如:小说、历史、传记',
|
||||
controllerKey: 'genres',
|
||||
onAdd: (v) => setState(() => _genres.add(v)),
|
||||
onRemove: (i) => setState(() => _genres.removeAt(i)),
|
||||
),
|
||||
|
||||
_buildDivider(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// ISBN
|
||||
_buildHorizontalFormItem(
|
||||
label: 'ISBN',
|
||||
child: TextFormField(
|
||||
controller: _isbnController,
|
||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入ISBN编号',
|
||||
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 出版社
|
||||
_buildHorizontalFormItem(
|
||||
label: '出版社',
|
||||
child: TextFormField(
|
||||
controller: _publisherController,
|
||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入出版社名称',
|
||||
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 出版时间
|
||||
_buildVerticalDateItem(
|
||||
label: '出版时间',
|
||||
date: _publishDate,
|
||||
onTap: _selectPublishDate,
|
||||
onClear: () => setState(() => _publishDate = null),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 书籍简介
|
||||
_buildFormItem(
|
||||
@@ -231,24 +308,129 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建表单条目(标签 + 内容)
|
||||
/// 构建表单条目(标签 + 内容)- 书籍简介使用
|
||||
Widget _buildFormItem({required String label, required Widget child}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: label.contains('*') ? const Color(0xFF1A1A1A) : const Color(0xFF666666),
|
||||
fontWeight: label.contains('*') ? FontWeight.w500 : FontWeight.normal,
|
||||
),
|
||||
style: const TextStyle(fontSize: 13, color: Color(0xFF666666)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建横向表单条目(标签在左,内容在右)
|
||||
Widget _buildHorizontalFormItem({
|
||||
required String label,
|
||||
required Widget child,
|
||||
bool required = false,
|
||||
}) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: Text(
|
||||
required ? '$label *' : label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: required ? const Color(0xFF1A1A1A) : const Color(0xFF999999),
|
||||
fontWeight: required ? FontWeight.w500 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建横向多值条目(标签在左,内容在右)
|
||||
Widget _buildHorizontalMultiValueItem({
|
||||
required String label,
|
||||
required List<String> values,
|
||||
required String hint,
|
||||
required String controllerKey,
|
||||
required Function(String) onAdd,
|
||||
required Function(int) onRemove,
|
||||
}) {
|
||||
final controller = _getTagController(controllerKey);
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 48,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 13, color: Color(0xFF999999)),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
...values.asMap().entries.map((entry) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F5F5),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
entry.value,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
GestureDetector(
|
||||
onTap: () => onRemove(entry.key),
|
||||
child: const Icon(Icons.close, size: 14, color: Color(0xFF999999)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
// 输入框
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 80, maxWidth: 120),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||
decoration: InputDecoration(
|
||||
hintText: values.isEmpty ? hint : '',
|
||||
hintStyle: const TextStyle(fontSize: 13, color: Color(0xFFCCCCCC)),
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 6),
|
||||
),
|
||||
onSubmitted: (value) {
|
||||
final trimmed = value.trim();
|
||||
if (trimmed.isNotEmpty && !values.contains(trimmed)) {
|
||||
onAdd(trimmed);
|
||||
controller.clear();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建多值条目
|
||||
Widget _buildMultiValueItem({
|
||||
@@ -376,15 +558,7 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建分隔线
|
||||
Widget _buildDivider() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 16),
|
||||
height: 0.5,
|
||||
color: const Color(0xFFE5E5E5),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// 构建状态选择器(靠左显示,带标签)
|
||||
Widget _buildStatusSelector() {
|
||||
return Row(
|
||||
@@ -524,6 +698,74 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建纵向日期条目(标签在上,日期在下)
|
||||
Widget _buildVerticalDateItem({
|
||||
required String label,
|
||||
required DateTime? date,
|
||||
required VoidCallback onTap,
|
||||
required VoidCallback onClear,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 13, color: Color(0xFF999999)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
date != null
|
||||
? '${date.year}.${date.month.toString().padLeft(2, '0')}.${date.day.toString().padLeft(2, '0')}'
|
||||
: '选择日期',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: date != null
|
||||
? const Color(0xFF1A1A1A)
|
||||
: const Color(0xFFCCCCCC),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (date != null)
|
||||
GestureDetector(
|
||||
onTap: onClear,
|
||||
child: const Icon(Icons.close, size: 18, color: Color(0xFF999999)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 选择出版时间
|
||||
Future<void> _selectPublishDate() async {
|
||||
final picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _publishDate ?? DateTime.now(),
|
||||
firstDate: DateTime(1900),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365 * 5)),
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
colorScheme: const ColorScheme.light(
|
||||
primary: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
setState(() => _publishDate = picked);
|
||||
}
|
||||
}
|
||||
|
||||
/// 构建状态选项
|
||||
Widget _buildStatusOption(String label, String value) {
|
||||
final isSelected = _status == value;
|
||||
@@ -707,6 +949,8 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
summary: _summaryController.text.trim(),
|
||||
rating: rating,
|
||||
status: _status,
|
||||
isbn: _isbnController.text.trim().isNotEmpty ? _isbnController.text.trim() : null,
|
||||
publishDate: _publishDate,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
);
|
||||
@@ -723,6 +967,8 @@ class _BookFormPageState extends State<BookFormPage> {
|
||||
summary: _summaryController.text.trim(),
|
||||
rating: rating,
|
||||
status: _status,
|
||||
isbn: _isbnController.text.trim().isNotEmpty ? _isbnController.text.trim() : null,
|
||||
publishDate: _publishDate,
|
||||
updatedAt: now,
|
||||
);
|
||||
|
||||
|
||||
180
lib/pages/book/book_review_detail_page.dart
Normal file
180
lib/pages/book/book_review_detail_page.dart
Normal file
@@ -0,0 +1,180 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../models/data_models.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import 'book_review_form_page.dart';
|
||||
|
||||
/// 书评详情页
|
||||
class BookReviewDetailPage extends StatefulWidget {
|
||||
final BookReview review;
|
||||
final String bookId;
|
||||
|
||||
const BookReviewDetailPage({
|
||||
super.key,
|
||||
required this.review,
|
||||
required this.bookId,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BookReviewDetailPage> createState() => _BookReviewDetailPageState();
|
||||
}
|
||||
|
||||
class _BookReviewDetailPageState extends State<BookReviewDetailPage> {
|
||||
late BookReview _review;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_review = widget.review;
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_refreshReviewData();
|
||||
}
|
||||
|
||||
Future<void> _refreshReviewData() async {
|
||||
final provider = context.read<AppProvider>();
|
||||
final reviews = await provider.getBookReviews(widget.bookId);
|
||||
final updatedReview = reviews
|
||||
.where((r) => r.id == widget.review.id)
|
||||
.firstOrNull;
|
||||
if (updatedReview != null && updatedReview.id == _review.id) {
|
||||
setState(() {
|
||||
_review = updatedReview;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('书评详情'),
|
||||
actions: [
|
||||
// 编辑按钮
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
onPressed: () => _navigateToEdit(context),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 书评内容
|
||||
Text(
|
||||
_review.content,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.8,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 分隔线
|
||||
Container(
|
||||
height: 0.5,
|
||||
color: const Color(0xFFE5E5E5),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 书评人
|
||||
_buildInfoRow(
|
||||
icon: Icons.person_outline,
|
||||
label: '书评人:',
|
||||
value: _review.reviewer.isNotEmpty ? _review.reviewer : '匿名',
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 来源
|
||||
if (_review.source.isNotEmpty)
|
||||
_buildInfoRow(
|
||||
icon: Icons.source_outlined,
|
||||
label: '来源:',
|
||||
value: _review.source,
|
||||
),
|
||||
|
||||
if (_review.source.isNotEmpty) const SizedBox(height: 16),
|
||||
|
||||
// 类型
|
||||
_buildInfoRow(
|
||||
icon: Icons.category_outlined,
|
||||
label: '类型:',
|
||||
value: _review.typeText,
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 时间
|
||||
_buildInfoRow(
|
||||
icon: Icons.access_time,
|
||||
label: '时间:',
|
||||
value: _formatDate(_review.createdAt),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建信息行
|
||||
Widget _buildInfoRow({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required String value,
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: const Color(0xFF999999),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Color(0xFF1A1A1A),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.year}.${date.month.toString().padLeft(2, '0')}.${date.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _navigateToEdit(BuildContext context) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BookReviewFormPage(
|
||||
bookId: widget.bookId,
|
||||
review: _review,
|
||||
),
|
||||
),
|
||||
).then((_) => _refreshReviewData());
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../models/data_models.dart';
|
||||
import '../../utils/toast_util.dart';
|
||||
import 'book_review_form_page.dart';
|
||||
import 'book_review_detail_page.dart';
|
||||
|
||||
/// 书籍书评列表页面
|
||||
class BookReviewsPage extends StatefulWidget {
|
||||
@@ -17,7 +19,10 @@ class BookReviewsPage extends StatefulWidget {
|
||||
|
||||
class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
List<BookReview> _reviews = [];
|
||||
List<BookReview> _filteredReviews = [];
|
||||
bool _isLoading = true;
|
||||
bool _isSearching = false;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -25,18 +30,45 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
_loadReviews();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadReviews() async {
|
||||
setState(() => _isLoading = true);
|
||||
try {
|
||||
final reviews = await context.read<AppProvider>().getBookReviews(widget.book.id);
|
||||
setState(() {
|
||||
_reviews = reviews;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() => _isLoading = false);
|
||||
ToastUtil.show(context, '加载失败: $e');
|
||||
}
|
||||
final reviews = await context.read<AppProvider>().getBookReviews(widget.book.id);
|
||||
setState(() {
|
||||
_reviews = reviews;
|
||||
_filteredReviews = reviews;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleSearch() {
|
||||
setState(() {
|
||||
_isSearching = !_isSearching;
|
||||
if (!_isSearching) {
|
||||
_searchController.clear();
|
||||
_filteredReviews = _reviews;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _onSearchChanged(String query) {
|
||||
setState(() {
|
||||
if (query.isEmpty) {
|
||||
_filteredReviews = _reviews;
|
||||
} else {
|
||||
final lowerQuery = query.toLowerCase();
|
||||
_filteredReviews = _reviews.where((review) {
|
||||
return review.content.toLowerCase().contains(lowerQuery) ||
|
||||
review.reviewer.toLowerCase().contains(lowerQuery) ||
|
||||
review.source.toLowerCase().contains(lowerQuery);
|
||||
}).toList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -44,8 +76,26 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('书评'),
|
||||
title: _isSearching
|
||||
? TextField(
|
||||
controller: _searchController,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '搜索书评内容、书评人、来源...',
|
||||
hintStyle: TextStyle(color: Color(0xFF999999)),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
style: const TextStyle(color: Color(0xFF1A1A1A)),
|
||||
onChanged: _onSearchChanged,
|
||||
)
|
||||
: const Text('书评'),
|
||||
actions: [
|
||||
// 搜索按钮
|
||||
IconButton(
|
||||
icon: Icon(_isSearching ? Icons.close : Icons.search),
|
||||
onPressed: _toggleSearch,
|
||||
),
|
||||
// 添加按钮
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () => _navigateToAddReview(),
|
||||
@@ -55,7 +105,7 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _reviews.isEmpty
|
||||
: _filteredReviews.isEmpty
|
||||
? _buildEmptyState()
|
||||
: _buildReviewList(),
|
||||
);
|
||||
@@ -95,82 +145,63 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
}
|
||||
|
||||
Widget _buildReviewList() {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: _reviews.length,
|
||||
return MasonryGridView.count(
|
||||
crossAxisCount: 2,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemCount: _filteredReviews.length,
|
||||
itemBuilder: (context, index) {
|
||||
final review = _reviews[index];
|
||||
return _buildReviewItem(review);
|
||||
final review = _filteredReviews[index];
|
||||
return _buildReviewCard(review);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReviewItem(BookReview review) {
|
||||
Widget _buildReviewCard(BookReview review) {
|
||||
return InkWell(
|
||||
onTap: () => _navigateToReviewDetail(review),
|
||||
onLongPress: () => _showDeleteDialog(review),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
||||
color: const Color(0xFFF5F5F5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 头部:类型标签 + 操作按钮
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: review.reviewType == 1
|
||||
? const Color(0xFFF5F5F5)
|
||||
: const Color(0xFF1A1A1A),
|
||||
),
|
||||
child: Text(
|
||||
review.typeText,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: review.reviewType == 1
|
||||
? const Color(0xFF666666)
|
||||
: Colors.white,
|
||||
),
|
||||
),
|
||||
// 类型标签
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: review.reviewType == 1
|
||||
? Colors.white
|
||||
: const Color(0xFF1A1A1A),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
review.typeText,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: review.reviewType == 1
|
||||
? const Color(0xFF666666)
|
||||
: Colors.white,
|
||||
),
|
||||
const Spacer(),
|
||||
// 编辑按钮
|
||||
GestureDetector(
|
||||
onTap: () => _navigateToEditReview(review),
|
||||
child: const Icon(
|
||||
Icons.edit_outlined,
|
||||
size: 18,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// 删除按钮
|
||||
GestureDetector(
|
||||
onTap: () => _showDeleteDialog(review),
|
||||
child: const Icon(
|
||||
Icons.delete_outline,
|
||||
size: 18,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 评论内容
|
||||
Text(
|
||||
review.content,
|
||||
maxLines: review.reviewType == 1 ? 3 : 5,
|
||||
maxLines: review.reviewType == 1 ? 4 : 8,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontSize: 13,
|
||||
color: Color(0xFF1A1A1A),
|
||||
height: 1.6,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -179,31 +210,43 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
// 底部信息
|
||||
Row(
|
||||
children: [
|
||||
if (review.reviewer.isNotEmpty) ...[
|
||||
Text(
|
||||
review.reviewer,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF666666),
|
||||
// 书评人
|
||||
if (review.reviewer.isNotEmpty)
|
||||
Expanded(
|
||||
child: Text(
|
||||
review.reviewer,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Color(0xFF666666),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
if (review.source.isNotEmpty) ...[
|
||||
Text(
|
||||
'来源:${review.source}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF999999),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 来源和日期一行
|
||||
Row(
|
||||
children: [
|
||||
// 来源
|
||||
if (review.source.isNotEmpty)
|
||||
Expanded(
|
||||
child: Text(
|
||||
review.source,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
const Spacer(),
|
||||
// 日期
|
||||
Text(
|
||||
_formatDate(review.createdAt),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontSize: 10,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
@@ -240,6 +283,18 @@ class _BookReviewsPageState extends State<BookReviewsPage> {
|
||||
).then((_) => _loadReviews());
|
||||
}
|
||||
|
||||
void _navigateToReviewDetail(BookReview review) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BookReviewDetailPage(
|
||||
review: review,
|
||||
bookId: widget.book.id,
|
||||
),
|
||||
),
|
||||
).then((_) => _loadReviews());
|
||||
}
|
||||
|
||||
void _showDeleteDialog(BookReview review) {
|
||||
showDialog(
|
||||
context: context,
|
||||
|
||||
Reference in New Issue
Block a user