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