flutter ListView KeepAlive after some scroll

后端 未结 4 654
抹茶落季
抹茶落季 2020-12-11 18:37

I want to keepAlive my widgets which are already rendered in ListView. I was tried with addAutomaticKeepAlives:true properties which p

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 18:59

    For automaticKeepAlive to work, each item that needs to be kept alive must send a specific notification.

    A typical way to fire such notification is using AutomaticKeepAliveClientMixin

    class Foo extends StatefulWidget {
      @override
      FooState createState() {
        return new FooState();
      }
    }
    
    class FooState extends State with AutomaticKeepAliveClientMixin {
      @override
      Widget build(BuildContext context) {
        return Container(
    
        );
      }
    
      @override
      bool get wantKeepAlive => true;
    }
    

提交回复
热议问题