Skip to content

Commit a32052a

Browse files
committed
fix: 修复作业卡片正文缩放问题
1 parent 81b926a commit a32052a

File tree

4 files changed

+217
-131
lines changed

4 files changed

+217
-131
lines changed

lib/widgets/homework_card.dart

Lines changed: 133 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:convert';
2+
import 'package:finito_board/widgets/quill_content.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter_quill/flutter_quill.dart';
45
import 'package:intl/intl.dart';
@@ -138,147 +139,150 @@ class _HomeworkCardState extends State<HomeworkCard> {
138139
Widget build(BuildContext context) {
139140
final theme = Theme.of(context);
140141
final colorScheme = theme.colorScheme;
141-
142-
return GestureDetector(
143-
onTap: widget.onTap,
144-
child: AnimatedContainer(
145-
duration: const Duration(milliseconds: 200),
146-
margin: const EdgeInsets.only(bottom: 8),
147-
padding: const EdgeInsets.all(16), // MD3 间距
148-
decoration: BoxDecoration(
149-
color: _getCardBackgroundColor(colorScheme),
150-
borderRadius: BorderRadius.circular(12), // 与快捷菜单保持一致的圆角
151-
boxShadow: [
152-
BoxShadow(
153-
color: widget.isSelected
154-
? Colors.grey.withValues(alpha: 0.3)
155-
: Colors.black.withValues(alpha: 0.08),
156-
spreadRadius: widget.isSelected ? 2 : 1,
157-
blurRadius: widget.isSelected ? 12 : 6,
158-
offset: Offset(0, widget.isSelected ? 4 : 2),
142+
143+
return SizedBox(
144+
width: double.infinity,
145+
child: Card(
146+
elevation: 0,
147+
margin: const EdgeInsets.symmetric(vertical: 8.0),
148+
child: GestureDetector(
149+
onTap: widget.onTap,
150+
child: AnimatedContainer(
151+
duration: const Duration(milliseconds: 200),
152+
margin: const EdgeInsets.only(bottom: 8),
153+
padding: const EdgeInsets.all(16), // MD3 间距
154+
decoration: BoxDecoration(
155+
color: _getCardBackgroundColor(colorScheme),
156+
borderRadius: BorderRadius.circular(12), // 与快捷菜单保持一致的圆角
157+
boxShadow: [
158+
BoxShadow(
159+
color: widget.isSelected
160+
? Colors.grey.withValues(alpha: 0.3)
161+
: Colors.black.withValues(alpha: 0.08),
162+
spreadRadius: widget.isSelected ? 2 : 1,
163+
blurRadius: widget.isSelected ? 12 : 6,
164+
offset: Offset(0, widget.isSelected ? 4 : 2),
165+
),
166+
],
159167
),
160-
],
161-
),
162-
child: Column(
163-
crossAxisAlignment: CrossAxisAlignment.start,
164-
children: [
165-
// 富文本作业内容
166-
widget.homework.content.isNotEmpty
167-
? GestureDetector(
168-
onTap: widget.onTap,
169-
child: QuillEditor.basic(
170-
controller: _contentController,
171-
config: const QuillEditorConfig(
172-
showCursor: false,
173-
padding: EdgeInsets.zero,
174-
),
175-
focusNode: _editorFocusNode,
176-
),
177-
)
178-
: GestureDetector(
179-
onTap: widget.onTap,
180-
child: Text(
181-
'暂无内容',
182-
style: theme.textTheme.bodyMedium?.copyWith(
183-
color: colorScheme.onSurfaceVariant,
184-
fontStyle: FontStyle.italic,
185-
),
186-
),
187-
),
188-
const SizedBox(height: 12),
189-
190-
// 截止日期和标签
191-
Wrap(
192-
spacing: 8,
193-
runSpacing: 6,
194-
crossAxisAlignment: WrapCrossAlignment.center,
168+
child: Column(
169+
crossAxisAlignment: CrossAxisAlignment.start,
195170
children: [
196-
// 截止日期
197-
Row(
198-
mainAxisSize: MainAxisSize.min,
171+
// 富文本作业内容
172+
widget.homework.content.isNotEmpty
173+
? GestureDetector(
174+
onTap: widget.onTap,
175+
child: QuillContent(
176+
content: widget.homework.content,
177+
textScaler: MediaQuery.textScalerOf(context),
178+
),
179+
)
180+
: GestureDetector(
181+
onTap: widget.onTap,
182+
child: Text(
183+
'暂无内容',
184+
style: theme.textTheme.bodyMedium?.copyWith(
185+
color: colorScheme.onSurfaceVariant,
186+
fontStyle: FontStyle.italic,
187+
),
188+
),
189+
),
190+
const SizedBox(height: 12),
191+
192+
// 截止日期和标签
193+
Wrap(
194+
spacing: 8,
195+
runSpacing: 6,
196+
crossAxisAlignment: WrapCrossAlignment.center,
199197
children: [
200-
Icon(
201-
Icons.access_time,
202-
size: 16,
203-
color: _isOverdue()
204-
? colorScheme.error
205-
: colorScheme.onSurfaceVariant,
206-
),
207-
const SizedBox(width: 6),
208-
Text(
209-
_getFormattedDate(),
210-
style: theme.textTheme.bodySmall?.copyWith(
211-
color: _isOverdue()
212-
? colorScheme.error
213-
: colorScheme.onSurfaceVariant,
214-
fontWeight: FontWeight.w500,
215-
),
198+
// 截止日期
199+
Row(
200+
mainAxisSize: MainAxisSize.min,
201+
children: [
202+
Icon(
203+
Icons.access_time,
204+
size: 16,
205+
color: _isOverdue()
206+
? colorScheme.error
207+
: colorScheme.onSurfaceVariant,
208+
),
209+
const SizedBox(width: 6),
210+
Text(
211+
_getFormattedDate(),
212+
style: theme.textTheme.bodySmall?.copyWith(
213+
color: _isOverdue()
214+
? colorScheme.error
215+
: colorScheme.onSurfaceVariant,
216+
fontWeight: FontWeight.w500,
217+
),
218+
),
219+
],
216220
),
221+
222+
// 状态标签
223+
if (_getStatusTag() != null) _getStatusTag()!,
224+
225+
// 作业标签
226+
...JsonStorageService.instance.getTagNamesByUuids(widget.homework.tagUuids).map((tagName) => Container(
227+
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
228+
decoration: BoxDecoration(
229+
color: colorScheme.secondaryContainer,
230+
borderRadius: BorderRadius.circular(8),
231+
),
232+
child: Text(
233+
tagName,
234+
style: theme.textTheme.labelSmall?.copyWith(
235+
color: colorScheme.onSecondaryContainer,
236+
fontWeight: FontWeight.w500,
237+
),
238+
),
239+
)),
217240
],
218241
),
219242

220-
// 状态标签
221-
if (_getStatusTag() != null) _getStatusTag()!,
222-
223-
// 作业标签
224-
...JsonStorageService.instance.getTagNamesByUuids(widget.homework.tagUuids).map((tagName) => Container(
225-
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
226-
decoration: BoxDecoration(
227-
color: colorScheme.secondaryContainer,
228-
borderRadius: BorderRadius.circular(8),
229-
),
230-
child: Text(
231-
tagName,
232-
style: theme.textTheme.labelSmall?.copyWith(
233-
color: colorScheme.onSecondaryContainer,
234-
fontWeight: FontWeight.w500,
235-
),
236-
),
237-
)),
238-
],
239-
),
240-
241-
// 编辑和删除按钮
242-
if (widget.isSelected) ...[
243-
const SizedBox(height: 12),
244-
Row(
245-
mainAxisAlignment: MainAxisAlignment.end,
246-
children: [
247-
IconButton( // 改为填充样式的按钮
248-
icon: const Icon(Icons.edit, size: 18),
249-
onPressed: widget.onEdit,
250-
tooltip: '编辑',
251-
style: IconButton.styleFrom(
252-
foregroundColor: colorScheme.primary,
253-
backgroundColor: colorScheme.primaryContainer.withValues(alpha: 0.3),
254-
padding: const EdgeInsets.all(8),
255-
minimumSize: const Size(36, 36),
256-
shape: RoundedRectangleBorder(
257-
borderRadius: BorderRadius.circular(8),
243+
// 编辑和删除按钮
244+
if (widget.isSelected) ...[
245+
const SizedBox(height: 12),
246+
Row(
247+
mainAxisAlignment: MainAxisAlignment.end,
248+
children: [
249+
IconButton( // 改为填充样式的按钮
250+
icon: const Icon(Icons.edit, size: 18),
251+
onPressed: widget.onEdit,
252+
tooltip: '编辑',
253+
style: IconButton.styleFrom(
254+
foregroundColor: colorScheme.primary,
255+
backgroundColor: colorScheme.primaryContainer.withAlpha(77),
256+
padding: const EdgeInsets.all(8),
257+
minimumSize: const Size(36, 36),
258+
shape: RoundedRectangleBorder(
259+
borderRadius: BorderRadius.circular(8),
260+
),
261+
),
258262
),
259-
),
260-
),
261-
const SizedBox(width: 8),
262-
IconButton( // 改为填充样式的按钮
263-
icon: const Icon(Icons.delete, size: 18),
264-
onPressed: widget.onDelete,
265-
tooltip: '删除',
266-
style: IconButton.styleFrom(
267-
foregroundColor: colorScheme.error,
268-
backgroundColor: colorScheme.errorContainer.withValues(alpha: 0.3),
269-
padding: const EdgeInsets.all(8),
270-
minimumSize: const Size(36, 36),
271-
shape: RoundedRectangleBorder(
272-
borderRadius: BorderRadius.circular(8),
263+
const SizedBox(width: 8),
264+
IconButton( // 改为填充样式的按钮
265+
icon: const Icon(Icons.delete, size: 18),
266+
onPressed: widget.onDelete,
267+
tooltip: '删除',
268+
style: IconButton.styleFrom(
269+
foregroundColor: colorScheme.error,
270+
backgroundColor: colorScheme.errorContainer.withAlpha(77),
271+
padding: const EdgeInsets.all(8),
272+
minimumSize: const Size(36, 36),
273+
shape: RoundedRectangleBorder(
274+
borderRadius: BorderRadius.circular(8),
275+
),
276+
),
273277
),
274-
),
278+
],
275279
),
276280
],
277-
),
278-
],
279-
],
280-
),
281+
],
282+
),
283+
),
281284
),
285+
),
282286
);
283287
}
284288
}

lib/widgets/homework_editor.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class _HomeworkEditorState extends State<HomeworkEditor> {
3838
bool _isBold = false;
3939
bool _isItalic = false;
4040
bool _isStrikethrough = false;
41+
bool _isUnderline = false;
4142

4243
// 可选学科列表
4344
List<String> _availableSubjects = [];
@@ -241,18 +242,21 @@ class _HomeworkEditorState extends State<HomeworkEditor> {
241242
bool newIsBold = false;
242243
bool newIsItalic = false;
243244
bool newIsStrikethrough = false;
245+
bool newIsUnderline = false;
244246

245247
if (selection.isCollapsed) {
246248
// 光标位置,直接检查当前样式
247249
newIsBold = style.attributes.containsKey(Attribute.bold.key);
248250
newIsItalic = style.attributes.containsKey(Attribute.italic.key);
249251
newIsStrikethrough = style.attributes.containsKey(Attribute.strikeThrough.key);
252+
newIsUnderline = style.attributes.containsKey(Attribute.underline.key);
250253
} else {
251254
// 有选择范围,检查选择范围的格式一致性
252255
final document = _contentController.document;
253256
bool allBold = true;
254257
bool allItalic = true;
255258
bool allStrikethrough = true;
259+
bool allUnderline = true;
256260

257261
// 检查选择范围内是否所有字符都有相同的格式
258262
for (int i = selection.start; i < selection.end && i < document.length; i++) {
@@ -267,24 +271,30 @@ class _HomeworkEditorState extends State<HomeworkEditor> {
267271
if (!charStyle.attributes.containsKey(Attribute.strikeThrough.key)) {
268272
allStrikethrough = false;
269273
}
274+
if (!charStyle.attributes.containsKey(Attribute.underline.key)) {
275+
allUnderline = false;
276+
}
270277
}
271278

272279
newIsBold = allBold;
273280
newIsItalic = allItalic;
274281
newIsStrikethrough = allStrikethrough;
282+
newIsUnderline = allUnderline;
275283
}
276284

277285
// 只有状态发生变化时才更新UI
278286
if (newFontSize != _currentFontSize ||
279287
newIsBold != _isBold ||
280288
newIsItalic != _isItalic ||
281-
newIsStrikethrough != _isStrikethrough) {
289+
newIsStrikethrough != _isStrikethrough ||
290+
newIsUnderline != _isUnderline) {
282291
setState(() {
283292
_currentFontSize = newFontSize;
284293
_fontSizeController.text = _currentFontSize.toInt().toString();
285294
_isBold = newIsBold;
286295
_isItalic = newIsItalic;
287296
_isStrikethrough = newIsStrikethrough;
297+
_isUnderline = newIsUnderline;
288298
});
289299
}
290300
}

0 commit comments

Comments
 (0)