《Flutter小红手》1.0.5之keepAlive

173 阅读1分钟

关于这方面的博客文章有很多,自己的总结如下:

1.使用AutomaticKeepAliveClientMixin,根据文档说明
/// A mixin with convenience methods for clients of [AutomaticKeepAlive]. Used
/// with [State] subclasses.
///
/// Subclasses must implement [wantKeepAlive], and their [build] methods must
/// call super.build (the return value will always return null, and should be
/// ignored).
2.state with wantKeepAlive
@override
bool get wantKeepAlive => true;
3.在build方法中,在返回你的内容之前必须调用super.build(context);
Widget build(BuildContext context) {
super.build(context);
return ...;
}