generated from dellevin/template
优化高亮分享
This commit is contained in:
@@ -190,40 +190,108 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 摘抄内容输入框 ──
|
// ── 摘抄内容 ── 点击跳转全屏编辑 ──
|
||||||
|
|
||||||
|
Future<void> _editContent() async {
|
||||||
|
final result = await Navigator.push<String>(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (_) => _FullTextEditPage(title: '摘抄内容', initialText: _contentController.text, hintText: '在这里粘贴或输入书中的原文段落…')),
|
||||||
|
);
|
||||||
|
if (result != null) {
|
||||||
|
_contentController.text = result;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 我的感悟 ── 点击跳转全屏编辑 ──
|
||||||
|
|
||||||
|
Future<void> _editComment() async {
|
||||||
|
final result = await Navigator.push<String>(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (_) => _FullTextEditPage(title: '我的感悟', initialText: _commentController.text, hintText: '记录思考、联想或评论…')),
|
||||||
|
);
|
||||||
|
if (result != null) {
|
||||||
|
_commentController.text = result;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildContentInput(ColorScheme colors) {
|
Widget _buildContentInput(ColorScheme colors) {
|
||||||
return TextFormField(
|
return GestureDetector(
|
||||||
controller: _contentController,
|
onTap: _editContent,
|
||||||
maxLines: null,
|
child: Container(
|
||||||
minLines: 6,
|
width: double.infinity,
|
||||||
style: TextStyle(fontSize: 15, height: 1.8, color: colors.onSurface),
|
constraints: const BoxConstraints(minHeight: 140),
|
||||||
textAlignVertical: TextAlignVertical.top,
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 14),
|
||||||
decoration: _inputDecoration(
|
decoration: BoxDecoration(
|
||||||
colors,
|
color: colors.surfaceContainerHigh,
|
||||||
hintText: '在这里粘贴或输入书中的原文段落…',
|
borderRadius: BorderRadius.circular(10),
|
||||||
charCount: _contentChars,
|
border: Border.all(color: colors.outlineVariant.withValues(alpha: 0.3), width: 1),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
_contentController.text.isEmpty ? '在这里粘贴或输入书中的原文段落…' : _contentController.text,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
height: 1.8,
|
||||||
|
color: _contentController.text.isEmpty ? colors.onSurface.withValues(alpha: 0.25) : colors.onSurface,
|
||||||
|
),
|
||||||
|
maxLines: 6,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text('$_contentChars字', style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.3))),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Icon(Icons.edit_outlined, size: 14, color: colors.onSurface.withValues(alpha: 0.25)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.trim().isEmpty) return '请输入摘抄内容';
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 感悟输入框 ──
|
|
||||||
|
|
||||||
Widget _buildCommentInput(ColorScheme colors) {
|
Widget _buildCommentInput(ColorScheme colors) {
|
||||||
return TextFormField(
|
return GestureDetector(
|
||||||
controller: _commentController,
|
onTap: _editComment,
|
||||||
maxLines: null,
|
child: Container(
|
||||||
minLines: 3,
|
width: double.infinity,
|
||||||
style: TextStyle(fontSize: 15, height: 1.8, color: colors.onSurface),
|
constraints: const BoxConstraints(minHeight: 80),
|
||||||
textAlignVertical: TextAlignVertical.top,
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 14),
|
||||||
decoration: _inputDecoration(
|
decoration: BoxDecoration(
|
||||||
colors,
|
color: colors.surfaceContainerHigh,
|
||||||
hintText: '记录思考、联想或评论…',
|
borderRadius: BorderRadius.circular(10),
|
||||||
charCount: _commentChars,
|
border: Border.all(color: colors.outlineVariant.withValues(alpha: 0.3), width: 1),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
_commentController.text.isEmpty ? '记录思考、联想或评论…' : _commentController.text,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
height: 1.8,
|
||||||
|
color: _commentController.text.isEmpty ? colors.onSurface.withValues(alpha: 0.25) : colors.onSurface,
|
||||||
|
),
|
||||||
|
maxLines: 4,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text('$_commentChars字', style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.3))),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Icon(Icons.edit_outlined, size: 14, color: colors.onSurface.withValues(alpha: 0.25)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -271,6 +339,10 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
|
|||||||
|
|
||||||
Future<void> _saveExcerpt() async {
|
Future<void> _saveExcerpt() async {
|
||||||
if (!_formKey.currentState!.validate()) return;
|
if (!_formKey.currentState!.validate()) return;
|
||||||
|
if (_contentController.text.trim().isEmpty) {
|
||||||
|
ToastUtil.show(context, '请输入摘抄内容');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
try {
|
try {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
@@ -310,3 +382,60 @@ class _BookExcerptFormPageState extends State<BookExcerptFormPage> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 全屏文本编辑页面
|
||||||
|
class _FullTextEditPage extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
final String initialText;
|
||||||
|
final String hintText;
|
||||||
|
const _FullTextEditPage({required this.title, required this.initialText, required this.hintText});
|
||||||
|
@override
|
||||||
|
State<_FullTextEditPage> createState() => _FullTextEditPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FullTextEditPageState extends State<_FullTextEditPage> {
|
||||||
|
late final TextEditingController _controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = TextEditingController(text: widget.initialText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: colors.surface,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(widget.title),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context, _controller.text.trim()),
|
||||||
|
child: Text('完成', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: colors.primary)),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: TextField(
|
||||||
|
controller: _controller,
|
||||||
|
maxLines: null,
|
||||||
|
expands: true,
|
||||||
|
textAlignVertical: TextAlignVertical.top,
|
||||||
|
style: TextStyle(fontSize: 15, color: colors.onSurface, height: 1.8),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: widget.hintText,
|
||||||
|
hintStyle: TextStyle(color: colors.onSurface.withValues(alpha: 0.3)),
|
||||||
|
contentPadding: const EdgeInsets.all(20),
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ class _HighlightSharePageState extends State<HighlightSharePage> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
if (widget.chapter.isNotEmpty) ...[
|
if (widget.chapter.isNotEmpty) ...[
|
||||||
Container(
|
Flexible(
|
||||||
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFFFEB3B).withValues(alpha: 0.18),
|
color: const Color(0xFFFFEB3B).withValues(alpha: 0.18),
|
||||||
@@ -158,6 +159,8 @@ class _HighlightSharePageState extends State<HighlightSharePage> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
widget.chapter,
|
widget.chapter,
|
||||||
style: const TextStyle(fontSize: 11, color: Color(0xFF795548), fontWeight: FontWeight.w500),
|
style: const TextStyle(fontSize: 11, color: Color(0xFF795548), fontWeight: FontWeight.w500),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
|
|||||||
Reference in New Issue
Block a user