AnimatedSwitcher with IndexedStack

前端 未结 3 1120
抹茶落季
抹茶落季 2021-01-05 00:35

I have to use IndexedStack to maintain the state of my widgets for my BottomNavigationBar. Now i want to use AnimatedSwitcher (or an alternative) to create an animation when

3条回答
  •  清酒与你
    2021-01-05 01:36

    Try to add key to your IndexedStack so your code will look like:

    body: AnimatedSwitcher(  
      duration: Duration(milliseconds: 200),  
      child: IndexedStack(
        key: ValueKey(_currentIndex),
        children: _tabs.map((t) => t.widget).toList(),  
        index: _currentIndex,  
      ),  
    )
    

    The key is changed so AnimatedSwitcher will know that it's child is need to rebuild.

提交回复
热议问题