在Flutter中,可以使用RepaintBoundary widget和GlobalKey来判断部件是否被缓存。以下是示例代码:
RepaintBoundary( key: myWidgetKey, child: //widget to be cached )
final myWidgetKey = GlobalKey(); ... final isCached = myWidgetKey.currentContext?.findRenderObject()?.isRepaintBoundaryCached ?? false;
final isRefreshed = myWidgetKey.currentContext?.findRenderObject()?.debugNeedsPaint ?? true;
如果isRefreshed的值为true,则表示缓存已经被刷新,需要重新绘制缓存。
上一篇:不检测日期