generated from dellevin/template
编辑界面优化
This commit is contained in:
@@ -8,6 +8,7 @@ import '../../models/data_models.dart';
|
|||||||
import '../../utils/toast_util.dart';
|
import '../../utils/toast_util.dart';
|
||||||
import 'book_reviews_page.dart';
|
import 'book_reviews_page.dart';
|
||||||
import 'book_excerpts_page.dart';
|
import 'book_excerpts_page.dart';
|
||||||
|
import 'book_share_page.dart';
|
||||||
|
|
||||||
/// 书籍详情页 - 极简主义设计
|
/// 书籍详情页 - 极简主义设计
|
||||||
class BookDetailPage extends StatefulWidget {
|
class BookDetailPage extends StatefulWidget {
|
||||||
@@ -42,90 +43,128 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
body: CustomScrollView(
|
body: Stack(
|
||||||
slivers: [
|
children: [
|
||||||
// 顶部封面区域
|
CustomScrollView(
|
||||||
_buildSliverAppBar(book),
|
slivers: [
|
||||||
|
// 顶部封面区域
|
||||||
|
_buildSliverAppBar(book),
|
||||||
|
|
||||||
// 内容区域
|
// 内容区域
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// 基本信息
|
// 基本信息
|
||||||
_buildBasicInfo(book),
|
_buildBasicInfo(book),
|
||||||
|
|
||||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||||
|
|
||||||
// 作者信息
|
// 作者信息
|
||||||
_buildAuthorsSection(book),
|
_buildAuthorsSection(book),
|
||||||
|
|
||||||
// 类型
|
// 类型
|
||||||
if (book.genres.isNotEmpty)
|
if (book.genres.isNotEmpty)
|
||||||
_buildGenresSection(book),
|
_buildGenresSection(book),
|
||||||
|
|
||||||
// ISBN
|
// ISBN
|
||||||
if (book.isbn != null && book.isbn!.isNotEmpty)
|
if (book.isbn != null && book.isbn!.isNotEmpty)
|
||||||
_buildIsbnSection(book),
|
_buildIsbnSection(book),
|
||||||
|
|
||||||
// 出版社
|
// 出版社
|
||||||
if (book.publisher != null && book.publisher!.isNotEmpty)
|
if (book.publisher != null && book.publisher!.isNotEmpty)
|
||||||
_buildPublisherSection(book),
|
_buildPublisherSection(book),
|
||||||
|
|
||||||
// 出版时间
|
// 出版时间
|
||||||
if (book.publishDate != null)
|
if (book.publishDate != null)
|
||||||
_buildPublishDateSection(book),
|
_buildPublishDateSection(book),
|
||||||
|
|
||||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||||
|
|
||||||
// 简介
|
// 简介
|
||||||
if (book.summary != null && book.summary!.isNotEmpty)
|
if (book.summary != null && book.summary!.isNotEmpty)
|
||||||
_buildSummarySection(book),
|
_buildSummarySection(book),
|
||||||
|
|
||||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||||
|
|
||||||
// 书评和摘抄入口
|
// 书评和摘抄入口
|
||||||
_buildExtraSections(book),
|
_buildExtraSections(book),
|
||||||
|
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 120),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
// 右下角悬浮按钮组
|
||||||
|
Positioned(
|
||||||
|
right: 16,
|
||||||
|
bottom: 24,
|
||||||
|
child: _buildFloatingActionButtons(book),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
// 底部无操作栏,编辑和删除在右上角
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建右上角操作按钮
|
/// 构建右下角悬浮按钮组
|
||||||
Widget _buildActionButton({
|
Widget _buildFloatingActionButtons(Book book) {
|
||||||
|
final hasCover = book.coverPath != null && book.coverPath!.isNotEmpty;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// 删除按钮
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.delete_outline,
|
||||||
|
onPressed: () => _showDeleteDialog(context),
|
||||||
|
tooltip: '删除',
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
// 清空封面按钮(仅当有封面时显示)
|
||||||
|
if (hasCover) ...[
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.hide_image_outlined,
|
||||||
|
onPressed: () => _showClearCoverDialog(book),
|
||||||
|
tooltip: '清空封面',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
],
|
||||||
|
// 编辑按钮
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.edit_outlined,
|
||||||
|
onPressed: () => _navigateToEdit(context),
|
||||||
|
tooltip: '编辑',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
// 分享按钮
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.share_outlined,
|
||||||
|
onPressed: () => _showSharePoster(book),
|
||||||
|
tooltip: '分享海报',
|
||||||
|
backgroundColor: const Color(0xFF4CAF50),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建单个悬浮按钮
|
||||||
|
Widget _buildFloatingButton({
|
||||||
required IconData icon,
|
required IconData icon,
|
||||||
required VoidCallback onPressed,
|
required VoidCallback onPressed,
|
||||||
required String tooltip,
|
required String tooltip,
|
||||||
Color color = const Color(0xFF666666),
|
Color backgroundColor = const Color(0xFF1A1A1A),
|
||||||
}) {
|
}) {
|
||||||
return Container(
|
return FloatingActionButton(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
onPressed: onPressed,
|
||||||
decoration: BoxDecoration(
|
tooltip: tooltip,
|
||||||
color: Colors.white.withOpacity(0.9),
|
backgroundColor: backgroundColor,
|
||||||
borderRadius: BorderRadius.circular(8),
|
foregroundColor: Colors.white,
|
||||||
),
|
mini: true,
|
||||||
child: Material(
|
elevation: 4,
|
||||||
color: Colors.transparent,
|
child: Icon(icon, size: 20),
|
||||||
child: InkWell(
|
|
||||||
onTap: onPressed,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: Icon(
|
|
||||||
icon,
|
|
||||||
color: color,
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,8 +196,6 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
|
|
||||||
/// 构建顶部 AppBar
|
/// 构建顶部 AppBar
|
||||||
Widget _buildSliverAppBar(Book book) {
|
Widget _buildSliverAppBar(Book book) {
|
||||||
final hasCover = book.coverPath != null && book.coverPath!.isNotEmpty;
|
|
||||||
|
|
||||||
return SliverAppBar(
|
return SliverAppBar(
|
||||||
expandedHeight: 320,
|
expandedHeight: 320,
|
||||||
pinned: true,
|
pinned: true,
|
||||||
@@ -167,29 +204,7 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
flexibleSpace: FlexibleSpaceBar(
|
flexibleSpace: FlexibleSpaceBar(
|
||||||
background: _buildCoverSection(book),
|
background: _buildCoverSection(book),
|
||||||
),
|
),
|
||||||
actions: [
|
// 右上角按钮已移到右下角悬浮按钮
|
||||||
// 清空封面按钮(仅当有封面时显示)
|
|
||||||
if (hasCover)
|
|
||||||
_buildActionButton(
|
|
||||||
icon: Icons.hide_image_outlined,
|
|
||||||
onPressed: () => _showClearCoverDialog(book),
|
|
||||||
tooltip: '清空封面',
|
|
||||||
),
|
|
||||||
// 编辑按钮
|
|
||||||
_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),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -875,4 +890,14 @@ class _BookDetailPageState extends State<BookDetailPage> {
|
|||||||
ToastUtil.show(context, '下载失败: $e');
|
ToastUtil.show(context, '下载失败: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 显示分享海报页面
|
||||||
|
void _showSharePoster(Book book) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => BookSharePage(book: book),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,158 +148,164 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
body: Form(
|
body: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||||
children: [
|
children: [
|
||||||
// 封面选择 - 居中显示
|
// 封面选择 - 居中显示
|
||||||
Center(child: _buildCoverPicker()),
|
Center(child: _buildCoverPicker()),
|
||||||
|
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
// 状态选择(靠左显示)
|
// 状态选择(简洁风格)
|
||||||
_buildStatusSelector(),
|
_buildStatusSelector(),
|
||||||
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
// 评分 - 星星选择(靠左显示)
|
// 评分 - 星星选择(简洁风格)
|
||||||
_buildStarRating(),
|
_buildStarRating(),
|
||||||
|
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
|
|
||||||
// 书名
|
// 信息卡片网格
|
||||||
_buildHorizontalFormItem(
|
Wrap(
|
||||||
label: '书名',
|
spacing: 12,
|
||||||
required: true,
|
runSpacing: 12,
|
||||||
child: TextFormField(
|
children: [
|
||||||
controller: _titleController,
|
// 第一行:书名 + 别名
|
||||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
SizedBox(
|
||||||
decoration: const InputDecoration(
|
width: (MediaQuery.of(context).size.width - 52) / 2,
|
||||||
hintText: '请输入书名',
|
height: 90,
|
||||||
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
child: _buildInfoCard(
|
||||||
border: InputBorder.none,
|
label: '书名',
|
||||||
contentPadding: EdgeInsets.zero,
|
value: _titleController.text,
|
||||||
|
required: true,
|
||||||
|
icon: Icons.book_outlined,
|
||||||
|
onTap: () => _showTextInputDialog(
|
||||||
|
title: '书名',
|
||||||
|
initialValue: _titleController.text,
|
||||||
|
hint: '请输入书名',
|
||||||
|
onConfirm: (value) => setState(() => _titleController.text = value),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
validator: (value) {
|
SizedBox(
|
||||||
if (value == null || value.trim().isEmpty) {
|
width: (MediaQuery.of(context).size.width - 52) / 2,
|
||||||
return '请输入书名';
|
height: 90,
|
||||||
}
|
child: _buildInfoCard(
|
||||||
return null;
|
label: '别名',
|
||||||
},
|
value: _alternateTitles.isEmpty
|
||||||
),
|
? ''
|
||||||
),
|
: '${_alternateTitles.length}个:${_alternateTitles.join('、')}',
|
||||||
|
icon: Icons.alternate_email_outlined,
|
||||||
const SizedBox(height: 16),
|
onTap: () => _showMultiValueDialog(
|
||||||
|
title: '添加别名',
|
||||||
// 别名
|
initialValues: _alternateTitles,
|
||||||
_buildHorizontalMultiValueItem(
|
hint: '输入别名',
|
||||||
label: '别名',
|
onConfirm: (values) => setState(() => _alternateTitles = values),
|
||||||
values: _alternateTitles,
|
),
|
||||||
hint: '输入别名',
|
),
|
||||||
controllerKey: 'alternateTitles',
|
|
||||||
onAdd: (v) => setState(() => _alternateTitles.add(v)),
|
|
||||||
onRemove: (i) => setState(() => _alternateTitles.removeAt(i)),
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
|
|
||||||
// 作者
|
|
||||||
_buildHorizontalMultiValueItem(
|
|
||||||
label: '作者',
|
|
||||||
values: _authors,
|
|
||||||
hint: '输入作者姓名',
|
|
||||||
controllerKey: 'authors',
|
|
||||||
onAdd: (v) => setState(() => _authors.add(v)),
|
|
||||||
onRemove: (i) => setState(() => _authors.removeAt(i)),
|
|
||||||
),
|
|
||||||
|
|
||||||
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),
|
// 第二行:作者 + 出版社
|
||||||
|
SizedBox(
|
||||||
// 类型
|
width: (MediaQuery.of(context).size.width - 52) / 2,
|
||||||
_buildHorizontalMultiValueItem(
|
height: 90,
|
||||||
label: '类型',
|
child: _buildInfoCard(
|
||||||
values: _genres,
|
label: '作者',
|
||||||
hint: '如:小说、历史、传记',
|
value: _authors.isEmpty
|
||||||
controllerKey: 'genres',
|
? ''
|
||||||
onAdd: (v) => setState(() => _genres.add(v)),
|
: '${_authors.length}人:${_authors.join('、')}',
|
||||||
onRemove: (i) => setState(() => _genres.removeAt(i)),
|
icon: Icons.person_outline,
|
||||||
),
|
onTap: () => _showMultiValueDialog(
|
||||||
|
title: '添加作者',
|
||||||
const SizedBox(height: 16),
|
initialValues: _authors,
|
||||||
|
hint: '输入作者姓名',
|
||||||
// ISBN
|
onConfirm: (values) => setState(() => _authors = values),
|
||||||
_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,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(
|
||||||
),
|
width: (MediaQuery.of(context).size.width - 52) / 2,
|
||||||
|
height: 90,
|
||||||
const SizedBox(height: 16),
|
child: _buildInfoCard(
|
||||||
|
label: '出版社',
|
||||||
// 出版社
|
value: _publisherController.text,
|
||||||
_buildHorizontalFormItem(
|
icon: Icons.business_outlined,
|
||||||
label: '出版社',
|
onTap: () => _showTextInputDialog(
|
||||||
child: TextFormField(
|
title: '出版社',
|
||||||
controller: _publisherController,
|
initialValue: _publisherController.text,
|
||||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
hint: '请输入出版社',
|
||||||
decoration: const InputDecoration(
|
onConfirm: (value) => setState(() => _publisherController.text = value),
|
||||||
hintText: '请输入出版社名称',
|
),
|
||||||
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
),
|
||||||
border: InputBorder.none,
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(height: 16),
|
// 第三行:类型 + ISBN
|
||||||
|
SizedBox(
|
||||||
// 出版时间
|
width: (MediaQuery.of(context).size.width - 52) / 2,
|
||||||
_buildVerticalDateItem(
|
height: 90,
|
||||||
label: '出版时间',
|
child: _buildInfoCard(
|
||||||
date: _publishDate,
|
label: '类型',
|
||||||
onTap: _selectPublishDate,
|
value: _genres.isEmpty
|
||||||
onClear: () => setState(() => _publishDate = null),
|
? ''
|
||||||
),
|
: '${_genres.length}个:${_genres.join('、')}',
|
||||||
|
icon: Icons.category_outlined,
|
||||||
const SizedBox(height: 16),
|
onTap: () => _showMultiValueDialog(
|
||||||
|
title: '添加类型',
|
||||||
// 书籍简介
|
initialValues: _genres,
|
||||||
_buildFormItem(
|
hint: '如:小说、历史、传记',
|
||||||
label: '书籍简介',
|
onConfirm: (values) => setState(() => _genres = values),
|
||||||
child: TextFormField(
|
),
|
||||||
controller: _summaryController,
|
),
|
||||||
maxLines: 4,
|
|
||||||
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A), height: 1.5),
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: '写下书籍简介...',
|
|
||||||
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
|
||||||
border: InputBorder.none,
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(
|
||||||
|
width: (MediaQuery.of(context).size.width - 52) / 2,
|
||||||
|
height: 90,
|
||||||
|
child: _buildInfoCard(
|
||||||
|
label: 'ISBN',
|
||||||
|
value: _isbnController.text,
|
||||||
|
icon: Icons.qr_code_outlined,
|
||||||
|
onTap: () => _showTextInputDialog(
|
||||||
|
title: 'ISBN',
|
||||||
|
initialValue: _isbnController.text,
|
||||||
|
hint: '请输入ISBN编号',
|
||||||
|
onConfirm: (value) => setState(() => _isbnController.text = value),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 第四行:出版时间(独占一行)
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 90,
|
||||||
|
child: _buildInfoCard(
|
||||||
|
label: '出版时间',
|
||||||
|
value: _publishDate != null
|
||||||
|
? '${_publishDate!.year}.${_publishDate!.month.toString().padLeft(2, '0')}.${_publishDate!.day.toString().padLeft(2, '0')}'
|
||||||
|
: '',
|
||||||
|
icon: Icons.date_range_outlined,
|
||||||
|
onTap: () => _selectPublishDate(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 第五行:书籍简介(独占一行)
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: _buildInfoCard(
|
||||||
|
label: '书籍简介',
|
||||||
|
value: _summaryController.text,
|
||||||
|
icon: Icons.description_outlined,
|
||||||
|
height: 120,
|
||||||
|
scrollable: true,
|
||||||
|
onTap: () => _showTextInputDialog(
|
||||||
|
title: '书籍简介',
|
||||||
|
initialValue: _summaryController.text,
|
||||||
|
hint: '写下书籍简介...',
|
||||||
|
maxLines: 8,
|
||||||
|
onConfirm: (value) => setState(() => _summaryController.text = value),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 48),
|
||||||
@@ -560,20 +566,111 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 构建状态选择器(靠左显示,带标签)
|
/// 构建信息卡片(用于网格布局)
|
||||||
|
Widget _buildInfoCard({
|
||||||
|
required String label,
|
||||||
|
required String value,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
bool required = false,
|
||||||
|
IconData? icon,
|
||||||
|
double? height,
|
||||||
|
bool scrollable = false,
|
||||||
|
}) {
|
||||||
|
final hasValue = value.isNotEmpty;
|
||||||
|
|
||||||
|
// 构建值显示部分
|
||||||
|
Widget buildContent() {
|
||||||
|
if (scrollable && height != null) {
|
||||||
|
// 可滚动模式(仅书籍简介使用)
|
||||||
|
return Flexible(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
|
child: Text(
|
||||||
|
hasValue ? value : '点击填写',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
color: hasValue ? const Color(0xFF1A1A1A) : const Color(0xFFCCCCCC),
|
||||||
|
fontWeight: hasValue ? FontWeight.w500 : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 普通模式:只显示一行
|
||||||
|
return Text(
|
||||||
|
hasValue ? value : '点击填写',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
color: hasValue ? const Color(0xFF1A1A1A) : const Color(0xFFCCCCCC),
|
||||||
|
fontWeight: hasValue ? FontWeight.w500 : FontWeight.normal,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
height: height,
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(color: const Color(0xFFE8E8E8)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.03),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: height != null ? MainAxisSize.max : MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// 标签行
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
if (icon != null) ...[
|
||||||
|
Icon(icon, size: 14, color: const Color(0xFF999999)),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
],
|
||||||
|
Text(
|
||||||
|
required ? '$label *' : label,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: required ? const Color(0xFF1A1A1A) : const Color(0xFF999999),
|
||||||
|
fontWeight: required ? FontWeight.w500 : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// 值显示
|
||||||
|
buildContent(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建状态选择器(简洁风格)
|
||||||
Widget _buildStatusSelector() {
|
Widget _buildStatusSelector() {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text(
|
||||||
'状态',
|
'状态',
|
||||||
style: TextStyle(fontSize: 14, color: Color(0xFF666666)),
|
style: TextStyle(fontSize: 13, color: Color(0xFF999999)),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(4),
|
padding: const EdgeInsets.all(3),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF5F5F5),
|
color: const Color(0xFFF0F0F0),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -588,13 +685,13 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建星星评分(5星制,每星2分,支持手动输入)
|
/// 构建星星评分(支持手动输入)
|
||||||
Widget _buildStarRating() {
|
Widget _buildStarRating() {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text(
|
||||||
'评分',
|
'评分',
|
||||||
style: TextStyle(fontSize: 14, color: Color(0xFF666666)),
|
style: TextStyle(fontSize: 13, color: Color(0xFF999999)),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
// 星星选择
|
// 星星选择
|
||||||
@@ -648,52 +745,42 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建评分输入框
|
/// 构建评分输入框(支持0-10,保留1位小数)
|
||||||
Widget _buildRatingInputField() {
|
Widget _buildRatingInputField() {
|
||||||
return Container(
|
return Container(
|
||||||
width: 56,
|
width: 56,
|
||||||
height: 36,
|
height: 32,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF5F5F5),
|
color: const Color(0xFFF0F0F0),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _ratingController,
|
controller: _ratingController,
|
||||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 15,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color: Color(0xFF1A1A1A),
|
color: Color(0xFF1A1A1A),
|
||||||
),
|
),
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: '-',
|
hintText: '-',
|
||||||
hintStyle: TextStyle(fontSize: 15, color: Color(0xFFCCCCCC)),
|
hintStyle: TextStyle(fontSize: 14, color: Color(0xFFCCCCCC)),
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
contentPadding: EdgeInsets.symmetric(horizontal: 4, vertical: 6),
|
||||||
),
|
),
|
||||||
validator: (value) {
|
|
||||||
if (value != null && value.isNotEmpty) {
|
|
||||||
final rating = double.tryParse(value);
|
|
||||||
if (rating == null || rating < 0 || rating > 10) {
|
|
||||||
return '0-10';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
// 限制输入范围
|
|
||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
final rating = double.tryParse(value);
|
final rating = double.tryParse(value);
|
||||||
if (rating != null) {
|
if (rating != null) {
|
||||||
if (rating > 10) {
|
if (rating > 10) {
|
||||||
_ratingController.text = '10';
|
_ratingController.text = '10.0';
|
||||||
} else if (rating < 0) {
|
} else if (rating < 0) {
|
||||||
_ratingController.text = '0';
|
_ratingController.text = '0.0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setState(() {}); // 更新星星显示
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -806,16 +893,18 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
final hasCover = _coverPath != null && _coverPath!.isNotEmpty;
|
final hasCover = _coverPath != null && _coverPath!.isNotEmpty;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: _pickCover,
|
onTap: _pickCover,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 140,
|
width: 120,
|
||||||
height: 200,
|
height: 170,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF5F5F5),
|
color: const Color(0xFFF5F5F5),
|
||||||
border: Border.all(color: const Color(0xFFE5E5E5), width: 0.5),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
child: hasCover
|
child: hasCover
|
||||||
? Image.file(
|
? Image.file(
|
||||||
File(_coverPath!),
|
File(_coverPath!),
|
||||||
@@ -828,28 +917,29 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
// 清空封面按钮(仅当有封面时显示)
|
// 清空封面按钮(仅当有封面时显示)
|
||||||
if (hasCover)
|
if (hasCover)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 12),
|
padding: const EdgeInsets.only(top: 10),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => setState(() => _coverPath = null),
|
onTap: () => setState(() => _coverPath = null),
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: const Color(0xFFE5E5E5)),
|
color: const Color(0xFFF5F5F5),
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
),
|
||||||
child: const Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
Icons.hide_image_outlined,
|
Icons.delete_outline,
|
||||||
size: 16,
|
size: 14,
|
||||||
color: Color(0xFF666666),
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(
|
Text(
|
||||||
'清空封面',
|
'移除封面',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 12,
|
||||||
color: Color(0xFF666666),
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -866,16 +956,16 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
Icons.add_photo_alternate_outlined,
|
Icons.image_outlined,
|
||||||
size: 40,
|
size: 32,
|
||||||
color: Color(0xFF999999),
|
color: Color(0xFFCCCCCC),
|
||||||
),
|
),
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'点击添加封面',
|
'封面',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 12,
|
||||||
color: Color(0xFF999999),
|
color: Color(0xFFAAAAAA),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -1256,4 +1346,293 @@ class _BookFormPageState extends State<BookFormPage> {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 显示文本输入对话框
|
||||||
|
Future<void> _showTextInputDialog({
|
||||||
|
required String title,
|
||||||
|
required String initialValue,
|
||||||
|
required Function(String) onConfirm,
|
||||||
|
int maxLines = 1,
|
||||||
|
String hint = '',
|
||||||
|
}) async {
|
||||||
|
final result = await showDialog<String>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _TextInputDialog(
|
||||||
|
title: title,
|
||||||
|
initialValue: initialValue,
|
||||||
|
hint: hint,
|
||||||
|
maxLines: maxLines,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
onConfirm(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 显示多值输入对话框
|
||||||
|
Future<void> _showMultiValueDialog({
|
||||||
|
required String title,
|
||||||
|
required List<String> initialValues,
|
||||||
|
required String hint,
|
||||||
|
required Function(List<String>) onConfirm,
|
||||||
|
}) async {
|
||||||
|
final result = await showDialog<List<String>>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => _MultiValueDialog(
|
||||||
|
title: title,
|
||||||
|
initialValues: initialValues,
|
||||||
|
hint: hint,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
onConfirm(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 文本输入对话框组件
|
||||||
|
class _TextInputDialog extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
final String initialValue;
|
||||||
|
final String hint;
|
||||||
|
final int maxLines;
|
||||||
|
|
||||||
|
const _TextInputDialog({
|
||||||
|
required this.title,
|
||||||
|
required this.initialValue,
|
||||||
|
required this.hint,
|
||||||
|
required this.maxLines,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_TextInputDialog> createState() => _TextInputDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TextInputDialogState extends State<_TextInputDialog> {
|
||||||
|
late final TextEditingController controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
controller = TextEditingController(text: widget.initialValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
title: Text(
|
||||||
|
widget.title,
|
||||||
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
content: TextField(
|
||||||
|
controller: controller,
|
||||||
|
maxLines: widget.maxLines,
|
||||||
|
autofocus: true,
|
||||||
|
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: widget.hint,
|
||||||
|
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFF1A1A1A)),
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('取消', style: TextStyle(color: Color(0xFF999999))),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => Navigator.pop(context, controller.text.trim()),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color(0xFF1A1A1A),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
|
),
|
||||||
|
child: const Text('确定'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 多值输入对话框组件
|
||||||
|
class _MultiValueDialog extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
final List<String> initialValues;
|
||||||
|
final String hint;
|
||||||
|
|
||||||
|
const _MultiValueDialog({
|
||||||
|
required this.title,
|
||||||
|
required this.initialValues,
|
||||||
|
required this.hint,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_MultiValueDialog> createState() => _MultiValueDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MultiValueDialogState extends State<_MultiValueDialog> {
|
||||||
|
late List<String> values;
|
||||||
|
final controller = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
values = List<String>.from(widget.initialValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _addValue(String value) {
|
||||||
|
final trimmed = value.trim();
|
||||||
|
if (trimmed.isNotEmpty && !values.contains(trimmed)) {
|
||||||
|
setState(() {
|
||||||
|
values.add(trimmed);
|
||||||
|
});
|
||||||
|
controller.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _removeValue(int index) {
|
||||||
|
setState(() {
|
||||||
|
values.removeAt(index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
title: Text(
|
||||||
|
widget.title,
|
||||||
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
content: SizedBox(
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 已添加的值列表
|
||||||
|
if (values.isNotEmpty)
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: values.asMap().entries.map((entry) {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFF5F5F5),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
entry.value,
|
||||||
|
style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => _removeValue(entry.key),
|
||||||
|
child: const Icon(Icons.close, size: 14, color: Color(0xFF999999)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
if (values.isNotEmpty) const SizedBox(height: 16),
|
||||||
|
// 输入框
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: controller,
|
||||||
|
autofocus: true,
|
||||||
|
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: widget.hint,
|
||||||
|
hintStyle: const TextStyle(fontSize: 14, color: Color(0xFFAAAAAA)),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(color: Color(0xFF1A1A1A)),
|
||||||
|
),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||||
|
),
|
||||||
|
onSubmitted: _addValue,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => _addValue(controller.text),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFF1A1A1A),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.add, size: 20, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('取消', style: TextStyle(color: Color(0xFF999999))),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
// 如果输入框还有内容,先添加
|
||||||
|
_addValue(controller.text);
|
||||||
|
Navigator.pop(context, values);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color(0xFF1A1A1A),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
|
),
|
||||||
|
child: const Text('确定'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
319
lib/pages/book/book_share_page.dart
Normal file
319
lib/pages/book/book_share_page.dart
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
import '../../models/data_models.dart';
|
||||||
|
import '../../utils/toast_util.dart';
|
||||||
|
|
||||||
|
/// 书籍分享海报页面
|
||||||
|
class BookSharePage extends StatefulWidget {
|
||||||
|
final Book book;
|
||||||
|
|
||||||
|
const BookSharePage({super.key, required this.book});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<BookSharePage> createState() => _BookSharePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BookSharePageState extends State<BookSharePage> {
|
||||||
|
final GlobalKey _posterKey = GlobalKey();
|
||||||
|
bool _isGenerating = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF5F5F5),
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Color(0xFF1A1A1A)),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'分享海报',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
centerTitle: true,
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: _isGenerating ? null : _generateAndShare,
|
||||||
|
child: _isGenerating
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text(
|
||||||
|
'分享',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: RepaintBoundary(
|
||||||
|
key: _posterKey,
|
||||||
|
child: _buildPosterWidget(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建海报 Widget
|
||||||
|
Widget _buildPosterWidget() {
|
||||||
|
final book = widget.book;
|
||||||
|
final hasCover = book.coverPath != null && book.coverPath!.isNotEmpty;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
width: 320,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.1),
|
||||||
|
blurRadius: 20,
|
||||||
|
offset: const Offset(0, 10),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 封面图片
|
||||||
|
if (hasCover)
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
||||||
|
child: Image.file(
|
||||||
|
File(book.coverPath!),
|
||||||
|
width: 320,
|
||||||
|
height: 200,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 内容区域
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 书名
|
||||||
|
Text(
|
||||||
|
book.title,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 别名
|
||||||
|
if (book.alternateTitles.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
book.alternateTitles.join(' / '),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Color(0xFF666666),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// 评分
|
||||||
|
if (book.rating != null && book.rating! > 0) ...[
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.star,
|
||||||
|
size: 18,
|
||||||
|
color: Color(0xFFFFB800),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
book.rating!.toStringAsFixed(1),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFFFFB800),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
const Text(
|
||||||
|
'/ 10',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
],
|
||||||
|
|
||||||
|
// 作者
|
||||||
|
if (book.authors.isNotEmpty)
|
||||||
|
_buildInfoRow('作者', book.authors.join(' / ')),
|
||||||
|
|
||||||
|
// 出版社
|
||||||
|
if (book.publisher != null && book.publisher!.isNotEmpty)
|
||||||
|
_buildInfoRow('出版社', book.publisher!),
|
||||||
|
|
||||||
|
// 出版时间
|
||||||
|
if (book.publishDate != null)
|
||||||
|
_buildInfoRow(
|
||||||
|
'出版',
|
||||||
|
'${book.publishDate!.year}.${book.publishDate!.month.toString().padLeft(2, '0')}.${book.publishDate!.day.toString().padLeft(2, '0')}',
|
||||||
|
),
|
||||||
|
|
||||||
|
// 类型
|
||||||
|
if (book.genres.isNotEmpty)
|
||||||
|
_buildInfoRow('类型', book.genres.join(' / ')),
|
||||||
|
|
||||||
|
// ISBN
|
||||||
|
if (book.isbn != null && book.isbn!.isNotEmpty)
|
||||||
|
_buildInfoRow('ISBN', book.isbn!),
|
||||||
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// 简介
|
||||||
|
if (book.summary != null && book.summary!.isNotEmpty) ...[
|
||||||
|
const Text(
|
||||||
|
'简介',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
book.summary!,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Color(0xFF666666),
|
||||||
|
height: 1.6,
|
||||||
|
),
|
||||||
|
maxLines: 5,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
|
// 底部标识
|
||||||
|
const Divider(height: 1, color: Color(0xFFE8E8E8)),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.book_outlined,
|
||||||
|
size: 14,
|
||||||
|
color: const Color(0xFF1A1A1A).withOpacity(0.5),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
'来自 MookNote',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: const Color(0xFF1A1A1A).withOpacity(0.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建信息行
|
||||||
|
Widget _buildInfoRow(String label, String value) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 8),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'$label:',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
value,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Color(0xFF333333),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 生成并分享海报
|
||||||
|
Future<void> _generateAndShare() async {
|
||||||
|
setState(() => _isGenerating = true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 捕获海报图片
|
||||||
|
final boundary = _posterKey.currentContext?.findRenderObject()
|
||||||
|
as RenderRepaintBoundary?;
|
||||||
|
if (boundary == null) {
|
||||||
|
throw Exception('无法获取海报边界');
|
||||||
|
}
|
||||||
|
|
||||||
|
final image = await boundary.toImage(pixelRatio: 3.0);
|
||||||
|
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||||
|
if (byteData == null) {
|
||||||
|
throw Exception('无法生成图片数据');
|
||||||
|
}
|
||||||
|
|
||||||
|
final bytes = byteData.buffer.asUint8List();
|
||||||
|
|
||||||
|
// 保存到临时文件
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
final fileName = 'book_poster_${DateTime.now().millisecondsSinceEpoch}.png';
|
||||||
|
final file = File('${tempDir.path}/$fileName');
|
||||||
|
await file.writeAsBytes(bytes);
|
||||||
|
|
||||||
|
// 分享
|
||||||
|
await Share.shareXFiles(
|
||||||
|
[XFile(file.path)],
|
||||||
|
text: '分享书籍:${widget.book.title}',
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ToastUtil.show(context, '生成海报失败:$e');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _isGenerating = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -318,6 +318,8 @@ class _DoubanWebViewPageState extends State<DoubanWebViewPage> {
|
|||||||
if (roleEl && (
|
if (roleEl && (
|
||||||
roleEl.textContent.includes('配音') ||
|
roleEl.textContent.includes('配音') ||
|
||||||
roleEl.textContent.includes('主演') ||
|
roleEl.textContent.includes('主演') ||
|
||||||
|
roleEl.textContent.includes('演员') ||
|
||||||
|
roleEl.textContent.includes('参演') ||
|
||||||
roleEl.textContent.includes('饰')
|
roleEl.textContent.includes('饰')
|
||||||
)) {
|
)) {
|
||||||
const nameEl = el.querySelector('.name');
|
const nameEl = el.querySelector('.name');
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import '../../models/data_models.dart';
|
|||||||
import '../../utils/toast_util.dart';
|
import '../../utils/toast_util.dart';
|
||||||
import 'movie_reviews_page.dart';
|
import 'movie_reviews_page.dart';
|
||||||
import 'movie_posters_page.dart';
|
import 'movie_posters_page.dart';
|
||||||
|
import 'movie_share_page.dart';
|
||||||
|
|
||||||
/// 影视详情页 - 极简主义设计
|
/// 影视详情页 - 极简主义设计
|
||||||
class MovieDetailPage extends StatefulWidget {
|
class MovieDetailPage extends StatefulWidget {
|
||||||
@@ -45,87 +46,125 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
body: CustomScrollView(
|
body: Stack(
|
||||||
slivers: [
|
children: [
|
||||||
// 顶部海报区域
|
CustomScrollView(
|
||||||
_buildSliverAppBar(movie),
|
slivers: [
|
||||||
|
// 顶部海报区域
|
||||||
|
_buildSliverAppBar(movie),
|
||||||
|
|
||||||
// 内容区域
|
// 内容区域
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// 基本信息
|
// 基本信息
|
||||||
_buildBasicInfo(movie),
|
_buildBasicInfo(movie),
|
||||||
|
|
||||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||||
|
|
||||||
// 导演
|
// 导演
|
||||||
if (movie.directors.isNotEmpty)
|
if (movie.directors.isNotEmpty)
|
||||||
_buildDirectorsSection(movie),
|
_buildDirectorsSection(movie),
|
||||||
|
|
||||||
// 编剧
|
// 编剧
|
||||||
if (movie.writers.isNotEmpty)
|
if (movie.writers.isNotEmpty)
|
||||||
_buildWritersSection(movie),
|
_buildWritersSection(movie),
|
||||||
|
|
||||||
// 主演
|
// 主演
|
||||||
if (movie.actors.isNotEmpty)
|
if (movie.actors.isNotEmpty)
|
||||||
_buildActorsSection(movie),
|
_buildActorsSection(movie),
|
||||||
|
|
||||||
// 类型
|
// 类型
|
||||||
if (movie.genres.isNotEmpty)
|
if (movie.genres.isNotEmpty)
|
||||||
_buildGenresSection(movie),
|
_buildGenresSection(movie),
|
||||||
|
|
||||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||||
|
|
||||||
// 简介
|
// 简介
|
||||||
if (movie.summary != null && movie.summary!.isNotEmpty)
|
if (movie.summary != null && movie.summary!.isNotEmpty)
|
||||||
_buildSummarySection(movie),
|
_buildSummarySection(movie),
|
||||||
|
|
||||||
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFE5E5E5)),
|
||||||
|
|
||||||
// 影评和海报墙入口
|
// 影评和海报墙入口
|
||||||
_buildExtraSections(movie),
|
_buildExtraSections(movie),
|
||||||
|
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 120),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
// 右下角悬浮按钮组
|
||||||
|
Positioned(
|
||||||
|
right: 16,
|
||||||
|
bottom: 24,
|
||||||
|
child: _buildFloatingActionButtons(movie),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
// 底部无操作栏,编辑和删除在右上角
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 构建右上角操作按钮
|
/// 构建右下角悬浮按钮组
|
||||||
Widget _buildActionButton({
|
Widget _buildFloatingActionButtons(Movie movie) {
|
||||||
|
final hasPoster = movie.posterPath != null && movie.posterPath!.isNotEmpty;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// 删除按钮
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.delete_outline,
|
||||||
|
onPressed: () => _showDeleteDialog(context),
|
||||||
|
tooltip: '删除',
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
// 清空海报按钮(仅当有海报时显示)
|
||||||
|
if (hasPoster) ...[
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.hide_image_outlined,
|
||||||
|
onPressed: () => _showClearPosterDialog(movie),
|
||||||
|
tooltip: '清空海报',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
],
|
||||||
|
// 编辑按钮
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.edit_outlined,
|
||||||
|
onPressed: () => _navigateToEdit(context),
|
||||||
|
tooltip: '编辑',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
// 分享按钮
|
||||||
|
_buildFloatingButton(
|
||||||
|
icon: Icons.share_outlined,
|
||||||
|
onPressed: () => _showSharePoster(movie),
|
||||||
|
tooltip: '分享海报',
|
||||||
|
backgroundColor: const Color(0xFF4CAF50),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建单个悬浮按钮
|
||||||
|
Widget _buildFloatingButton({
|
||||||
required IconData icon,
|
required IconData icon,
|
||||||
required VoidCallback onPressed,
|
required VoidCallback onPressed,
|
||||||
required String tooltip,
|
required String tooltip,
|
||||||
Color color = const Color(0xFF666666),
|
Color backgroundColor = const Color(0xFF1A1A1A),
|
||||||
}) {
|
}) {
|
||||||
return Container(
|
return FloatingActionButton(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
onPressed: onPressed,
|
||||||
decoration: BoxDecoration(
|
tooltip: tooltip,
|
||||||
color: Colors.white.withOpacity(0.9),
|
backgroundColor: backgroundColor,
|
||||||
borderRadius: BorderRadius.circular(8),
|
foregroundColor: Colors.white,
|
||||||
),
|
mini: true,
|
||||||
child: Material(
|
elevation: 4,
|
||||||
color: Colors.transparent,
|
child: Icon(icon, size: 20),
|
||||||
child: InkWell(
|
|
||||||
onTap: onPressed,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: Icon(
|
|
||||||
icon,
|
|
||||||
color: color,
|
|
||||||
size: 22,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,8 +196,6 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
|
|
||||||
/// 构建顶部 AppBar
|
/// 构建顶部 AppBar
|
||||||
Widget _buildSliverAppBar(Movie movie) {
|
Widget _buildSliverAppBar(Movie movie) {
|
||||||
final hasPoster = movie.posterPath != null && movie.posterPath!.isNotEmpty;
|
|
||||||
|
|
||||||
return SliverAppBar(
|
return SliverAppBar(
|
||||||
expandedHeight: 320,
|
expandedHeight: 320,
|
||||||
pinned: true,
|
pinned: true,
|
||||||
@@ -167,29 +204,7 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
flexibleSpace: FlexibleSpaceBar(
|
flexibleSpace: FlexibleSpaceBar(
|
||||||
background: _buildPosterSection(movie),
|
background: _buildPosterSection(movie),
|
||||||
),
|
),
|
||||||
actions: [
|
// 右上角按钮已移到右下角悬浮按钮
|
||||||
// 清空海报按钮(仅当有海报时显示)
|
|
||||||
if (hasPoster)
|
|
||||||
_buildActionButton(
|
|
||||||
icon: Icons.hide_image_outlined,
|
|
||||||
onPressed: () => _showClearPosterDialog(movie),
|
|
||||||
tooltip: '清空海报',
|
|
||||||
),
|
|
||||||
// 编辑按钮
|
|
||||||
_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),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,4 +865,14 @@ class _MovieDetailPageState extends State<MovieDetailPage> {
|
|||||||
// 这里默认返回较低版本,使用传统存储权限
|
// 这里默认返回较低版本,使用传统存储权限
|
||||||
return 30;
|
return 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 显示分享海报页面
|
||||||
|
void _showSharePoster(Movie movie) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => MovieSharePage(movie: movie),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
320
lib/pages/movies/movie_share_page.dart
Normal file
320
lib/pages/movies/movie_share_page.dart
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
import '../../models/data_models.dart';
|
||||||
|
import '../../utils/toast_util.dart';
|
||||||
|
|
||||||
|
/// 影视分享海报页面
|
||||||
|
class MovieSharePage extends StatefulWidget {
|
||||||
|
final Movie movie;
|
||||||
|
|
||||||
|
const MovieSharePage({super.key, required this.movie});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MovieSharePage> createState() => _MovieSharePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MovieSharePageState extends State<MovieSharePage> {
|
||||||
|
final GlobalKey _posterKey = GlobalKey();
|
||||||
|
bool _isGenerating = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xFFF5F5F5),
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Color(0xFF1A1A1A)),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'分享海报',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
centerTitle: true,
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: _isGenerating ? null : _generateAndShare,
|
||||||
|
child: _isGenerating
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text(
|
||||||
|
'分享',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: RepaintBoundary(
|
||||||
|
key: _posterKey,
|
||||||
|
child: _buildPosterWidget(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建海报 Widget
|
||||||
|
Widget _buildPosterWidget() {
|
||||||
|
final movie = widget.movie;
|
||||||
|
final hasPoster = movie.posterPath != null && movie.posterPath!.isNotEmpty;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
width: 320,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.1),
|
||||||
|
blurRadius: 20,
|
||||||
|
offset: const Offset(0, 10),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 海报图片
|
||||||
|
if (hasPoster)
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
||||||
|
child: Image.file(
|
||||||
|
File(movie.posterPath!),
|
||||||
|
width: 320,
|
||||||
|
height: 200,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 内容区域
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
// 标题
|
||||||
|
Text(
|
||||||
|
movie.title,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Color(0xFF1A1A1A),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 别名
|
||||||
|
if (movie.alternateTitles.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
movie.alternateTitles.join(' / '),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Color(0xFF666666),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// 评分
|
||||||
|
if (movie.rating != null && movie.rating! > 0) ...[
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.star,
|
||||||
|
size: 18,
|
||||||
|
color: Color(0xFFFFB800),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(
|
||||||
|
movie.rating!.toStringAsFixed(1),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFFFFB800),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
const Text(
|
||||||
|
'/ 10',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
],
|
||||||
|
|
||||||
|
// 导演
|
||||||
|
if (movie.directors.isNotEmpty)
|
||||||
|
_buildInfoRow('导演', movie.directors.join(' / ')),
|
||||||
|
|
||||||
|
// 编剧
|
||||||
|
if (movie.writers.isNotEmpty)
|
||||||
|
_buildInfoRow('编剧', movie.writers.join(' / ')),
|
||||||
|
|
||||||
|
// 主演
|
||||||
|
if (movie.actors.isNotEmpty)
|
||||||
|
_buildInfoRow('主演', movie.actors.take(3).join(' / ')),
|
||||||
|
|
||||||
|
// 类型
|
||||||
|
if (movie.genres.isNotEmpty)
|
||||||
|
_buildInfoRow('类型', movie.genres.join(' / ')),
|
||||||
|
|
||||||
|
// 上映日期
|
||||||
|
if (movie.releaseDate != null)
|
||||||
|
_buildInfoRow(
|
||||||
|
'上映',
|
||||||
|
'${movie.releaseDate!.year}.${movie.releaseDate!.month.toString().padLeft(2, '0')}.${movie.releaseDate!.day.toString().padLeft(2, '0')}',
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// 简介
|
||||||
|
if (movie.summary != null && movie.summary!.isNotEmpty) ...[
|
||||||
|
const Text(
|
||||||
|
'简介',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
movie.summary!,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Color(0xFF666666),
|
||||||
|
height: 1.6,
|
||||||
|
),
|
||||||
|
maxLines: 5,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
|
// 底部标识
|
||||||
|
const Divider(height: 1, color: Color(0xFFE8E8E8)),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.movie_outlined,
|
||||||
|
size: 14,
|
||||||
|
color: const Color(0xFF1A1A1A).withOpacity(0.5),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
'来自 MookNote',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: const Color(0xFF1A1A1A).withOpacity(0.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 构建信息行
|
||||||
|
Widget _buildInfoRow(String label, String value) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 8),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'$label:',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Color(0xFF999999),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
value,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Color(0xFF333333),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 生成并分享海报
|
||||||
|
Future<void> _generateAndShare() async {
|
||||||
|
setState(() => _isGenerating = true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 捕获海报图片
|
||||||
|
final boundary = _posterKey.currentContext?.findRenderObject()
|
||||||
|
as RenderRepaintBoundary?;
|
||||||
|
if (boundary == null) {
|
||||||
|
throw Exception('无法获取海报边界');
|
||||||
|
}
|
||||||
|
|
||||||
|
final image = await boundary.toImage(pixelRatio: 3.0);
|
||||||
|
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||||
|
if (byteData == null) {
|
||||||
|
throw Exception('无法生成图片数据');
|
||||||
|
}
|
||||||
|
|
||||||
|
final bytes = byteData.buffer.asUint8List();
|
||||||
|
|
||||||
|
// 保存到临时文件
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
final fileName = 'movie_poster_${DateTime.now().millisecondsSinceEpoch}.png';
|
||||||
|
final file = File('${tempDir.path}/$fileName');
|
||||||
|
await file.writeAsBytes(bytes);
|
||||||
|
|
||||||
|
// 分享
|
||||||
|
await Share.shareXFiles(
|
||||||
|
[XFile(file.path)],
|
||||||
|
text: '分享影视:${widget.movie.title}',
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
ToastUtil.show(context, '生成海报失败:$e');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _isGenerating = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -177,8 +177,19 @@ class _NoteTabPageState extends State<NoteTabPage> {
|
|||||||
final displayedIds = _displayedNotes.map((n) => n.id).toSet();
|
final displayedIds = _displayedNotes.map((n) => n.id).toSet();
|
||||||
final hasNewNotes = allNotes.any((note) => !displayedIds.contains(note.id));
|
final hasNewNotes = allNotes.any((note) => !displayedIds.contains(note.id));
|
||||||
|
|
||||||
// 如果有笔记被移除或有新增,更新列表
|
// 检查已存在的笔记是否有更新(通过比较updatedAt)
|
||||||
if (_displayedNotes.length < initialLength || hasNewNotes) {
|
bool hasUpdates = false;
|
||||||
|
for (int i = 0; i < _displayedNotes.length; i++) {
|
||||||
|
final localNote = _displayedNotes[i];
|
||||||
|
final providerNote = allNotes.firstWhere((n) => n.id == localNote.id);
|
||||||
|
if (localNote.updatedAt != providerNote.updatedAt) {
|
||||||
|
hasUpdates = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果有笔记被移除、有新增、或有更新,更新列表
|
||||||
|
if (_displayedNotes.length < initialLength || hasNewNotes || hasUpdates) {
|
||||||
// 清空并重新加载所有数据
|
// 清空并重新加载所有数据
|
||||||
_displayedNotes.clear();
|
_displayedNotes.clear();
|
||||||
_displayedNotes.addAll(allNotes);
|
_displayedNotes.addAll(allNotes);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: mooknote
|
name: mooknote
|
||||||
description: "app for tracking movies, books, and notes"
|
description: "app for tracking movies, books, and notes"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 0.1.7+1
|
version: 0.1.7+2
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.0
|
sdk: ^3.5.0
|
||||||
|
|||||||
Reference in New Issue
Block a user