flutter 页面缓存

    技术2026-01-28  8

    flutter页面缓存方法:

    混入AutomaticKeepAliveClientMixin部件设置页面缓存:

    //在动态部件内 class Page1 extends StatefulWidget { @override _Page1State createState() => _Page1State(); } //混入AutomaticKeepAliveClientMixin 设置缓存 class _Page1State extends State<MyHomePage> with AutomaticKeepAliveClientMixin { //重写keepAlive为ture 开启缓存功能。 @override bool get wantKeepAlive => true; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('缓存页面')), boby: IndexedStack( //用来显示第index个child, index: childIndex, children: <Widget>['这里面存放你需要缓存的页面内容'], ) ) }
    Processed: 0.011, SQL: 9