問題描述:TabBar 配合TabBarView切換頁面,而後每一個頁面是一個listview加載數據,可是切換頁面後listview的數據會被重置,git
從新被加載了,解決辦法使用 with AutomaticKeepAliveClientMixin 實現 @protected bool get wantKeepAlive=>true; 便可,github
可能會出現紅色報錯,直接忽視spa
須要添加下面這個,若是沒有analysis_options.yaml這個文件的話code
https://github.com/flutter/flutter/blob/master/analysis_options.yaml#L24blog
class _OpenLogListComponentState extends State<OpenLogListComponent> with AutomaticKeepAliveClientMixin{ @protected bool get wantKeepAlive=>true; //其餘邏輯 }
方法二: 使用IndexedStack存儲頁面get
_body = IndexedStack( children: <Widget>[ BookHousePage(), FunctionPage(), ChatPage(), MinePage() ], index: _currentPageIndex, );