알쓸전컴(알아두면 쓸모있는 전자 컴퓨터)

[Flutter]TabBarView 에서 tab index 변경시 initState 안하기 본문

Flutter,Dart

[Flutter]TabBarView 에서 tab index 변경시 initState 안하기

백곳 2019. 7. 24. 00:04

TabBarView 에서 tab index 변경시 initState 안하기  

 

위와 같이 Tab 에서 index을 움직이고 

다시 원래 Index 로 돌아 오면 

 

해당 Widget 객체가 해제 되어 다시 처음 부터 

 

 

initState 부터 다시 시작 한다. 

 

하지만 텝을 움직여도 이전 위젯상태가 남아 있으면 할때가 있다. 

 

그때는  

AutomaticKeepAliveClientMixin 을 with 로 추가 한다음 

 

 

@override

// TODO: implement wantKeepAlive

bool get wantKeepAlive => true;

 

해당 함수를 override 하여 위와 같이 true 로 바꿔 주면 된다. 

위와 같이 추가 하고 

override 한다.

 

참고 자료 : 

https://medium.com/@diegoveloper/flutter-persistent-tab-bars-a26220d322bc

 

 

Comments