fix(app): 修复打开已保存日记时笔迹不可见 — syncStrokes 后缺少 setState
根因:_syncCacheAfterBuild 调用 _cache.syncStrokes() 后没有触发 setState,导致 CachedStrokesPainter 不知道缓存已更新,不执行重绘。 对比正常绘画流程(addStroke 后有 setState),加载笔迹流程遗漏了 重绘触发。添加 .then(() => setState) 后,合成图重建完成即刷新画布。
This commit is contained in:
@@ -134,10 +134,15 @@ class _HandwritingCanvasState extends State<HandwritingCanvas> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 在 build 完成后同步缓存(避免在 build 中触发异步操作)
|
/// 在 build 完成后同步缓存(避免在 build 中触发异步操作)
|
||||||
|
///
|
||||||
|
/// syncStrokes 重建合成图后必须调用 setState,
|
||||||
|
/// 否则 CachedStrokesPainter 不知道缓存已更新,不会触发重绘。
|
||||||
void _syncCacheAfterBuild() {
|
void _syncCacheAfterBuild() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
_cache.syncStrokes(widget.strokes);
|
_cache.syncStrokes(widget.strokes).then((_) {
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user