generated from dellevin/template
支持微信读书导入摘抄
This commit is contained in:
@@ -456,9 +456,9 @@ class _EpubDetailPageState extends State<EpubDetailPage> {
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.menu_book_outlined, size: 14, color: colors.primary.withValues(alpha: 0.6)),
|
||||
const SizedBox(width: 6),
|
||||
const Spacer(),
|
||||
if (excerpt.chapter.isNotEmpty)
|
||||
Expanded(
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
@@ -469,7 +469,6 @@ class _EpubDetailPageState extends State<EpubDetailPage> {
|
||||
excerpt.chapter,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 9, color: colors.primary.withValues(alpha: 0.7), fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -270,13 +270,25 @@ class _EpubHighlightsPageState extends State<EpubHighlightsPage> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('删除句读', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
content: Text('确定删除这条句读?', style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6))),
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text('确认删除', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
content: Text('确定删除这条句读?', style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx), child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.4)))),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
style: TextButton.styleFrom(foregroundColor: colors.onSurface.withValues(alpha: 0.6), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8)),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () { Navigator.pop(ctx); _deleteHighlight(id); },
|
||||
child: Text('删除', style: TextStyle(color: colors.error)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colors.error, foregroundColor: colors.onError, elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
),
|
||||
child: const Text('删除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../utils/toast_util.dart';
|
||||
import 'highlight_share_page.dart';
|
||||
|
||||
/// 句读详情弹窗 —— 类似分享卡片的样式
|
||||
/// 从 epub_detail_page 和 epub_highlights_page 共用
|
||||
@@ -50,7 +51,7 @@ void showHighlightDetailSheet(
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||
padding: const EdgeInsets.fromLTRB(24, 20, 24, 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -128,13 +129,30 @@ void showHighlightDetailSheet(
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// 分隔线
|
||||
Container(height: 0.5, color: colors.outlineVariant),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 20),
|
||||
// 操作按钮
|
||||
Row(
|
||||
children: [
|
||||
_buildActionButton(
|
||||
colors,
|
||||
icon: Icons.ios_share_outlined,
|
||||
label: '分享',
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
String chapterLabel = '';
|
||||
if (chapterNum != null) chapterLabel = '第${chapterNum + 1}章';
|
||||
String dateLabel = '';
|
||||
if (createdAt.isNotEmpty) dateLabel = _formatDate(createdAt);
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (_) => HighlightSharePage(
|
||||
content: content,
|
||||
bookTitle: bookTitle,
|
||||
chapter: chapterLabel,
|
||||
dateStr: dateLabel,
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
_buildActionButton(
|
||||
colors,
|
||||
icon: Icons.content_copy_outlined,
|
||||
@@ -264,7 +282,7 @@ void showExcerptDetailSheet(
|
||||
),
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||
padding: const EdgeInsets.fromLTRB(24, 20, 24, 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -330,24 +348,22 @@ void showExcerptDetailSheet(
|
||||
// 感悟
|
||||
if (comment.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border(
|
||||
left: BorderSide(color: colors.primary.withValues(alpha: 0.4), width: 2),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.chat_bubble_outline, size: 14, color: colors.primary.withValues(alpha: 0.5)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
comment,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: colors.onSurface.withValues(alpha: 0.5),
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
comment,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
@@ -362,13 +378,26 @@ void showExcerptDetailSheet(
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// 分隔线
|
||||
Container(height: 0.5, color: colors.outlineVariant),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 20),
|
||||
// 操作按钮
|
||||
Row(
|
||||
children: [
|
||||
_buildActionButton(
|
||||
colors,
|
||||
icon: Icons.ios_share_outlined,
|
||||
label: '分享',
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (_) => HighlightSharePage(
|
||||
content: content,
|
||||
bookTitle: bookTitle,
|
||||
chapter: chapter,
|
||||
dateStr: _formatDateFromDateTime(createdAt),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
_buildActionButton(
|
||||
colors,
|
||||
icon: Icons.content_copy_outlined,
|
||||
|
||||
209
lib/pages/epub_reader/highlight_share_page.dart
Normal file
209
lib/pages/epub_reader/highlight_share_page.dart
Normal file
@@ -0,0 +1,209 @@
|
||||
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 '../../utils/toast_util.dart';
|
||||
|
||||
/// 句读分享海报页面
|
||||
class HighlightSharePage extends StatefulWidget {
|
||||
final String content;
|
||||
final String bookTitle;
|
||||
final String chapter;
|
||||
final String dateStr;
|
||||
|
||||
const HighlightSharePage({
|
||||
super.key,
|
||||
required this.content,
|
||||
required this.bookTitle,
|
||||
this.chapter = '',
|
||||
this.dateStr = '',
|
||||
});
|
||||
|
||||
@override
|
||||
State<HighlightSharePage> createState() => _HighlightSharePageState();
|
||||
}
|
||||
|
||||
class _HighlightSharePageState extends State<HighlightSharePage> {
|
||||
final GlobalKey _posterKey = GlobalKey();
|
||||
bool _isGenerating = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surfaceContainerHighest,
|
||||
appBar: AppBar(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.close, color: colors.onSurface),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
title: Text(
|
||||
'分享句读',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface),
|
||||
),
|
||||
centerTitle: true,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _isGenerating ? null : _generateAndShare,
|
||||
child: _isGenerating
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: Text('分享', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: RepaintBoundary(
|
||||
key: _posterKey,
|
||||
child: _buildPosterWidget(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPosterWidget() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
width: 320,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.black.withValues(alpha: 0.1), blurRadius: 20, offset: const Offset(0, 10)),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 顶部:书名
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.book_outlined, size: 16, color: const Color(0xFFFFC107)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.bookTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 分隔线
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
child: Container(height: 0.5, color: colors.outline),
|
||||
),
|
||||
|
||||
// 引号 + 内容
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'\u201C',
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
color: const Color(0xFFFFC107).withValues(alpha: 0.4),
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.content,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: colors.onSurface.withValues(alpha: 0.85),
|
||||
height: 1.9,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 底部:章节 + 日期 + 品牌
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 20, 20, 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(height: 0.5, color: colors.outline),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
if (widget.chapter.isNotEmpty) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFEB3B).withValues(alpha: 0.18),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
widget.chapter,
|
||||
style: const TextStyle(fontSize: 11, color: Color(0xFF795548), fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
if (widget.dateStr.isNotEmpty)
|
||||
Text(widget.dateStr, style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.3))),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'MookNote',
|
||||
style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.25), fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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 = 'highlight_share_${DateTime.now().millisecondsSinceEpoch}.png';
|
||||
final file = File('${tempDir.path}/$fileName');
|
||||
await file.writeAsBytes(bytes);
|
||||
|
||||
await Share.shareXFiles(
|
||||
[XFile(file.path)],
|
||||
text: '分享句读:${widget.bookTitle}',
|
||||
);
|
||||
} catch (e) {
|
||||
if (mounted) ToastUtil.show(context, '生成海报失败:$e');
|
||||
} finally {
|
||||
if (mounted) setState(() => _isGenerating = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user