alrutherford
alrutherford

Reputation: 432

How to select view in IndexedStack

I can't seem to figure out how to select the displayed view for the IndexedStack class. There is an index value but it is final and can't bet set.

Upvotes: 0

Views: 957

Answers (1)

Collin Jackson
Collin Jackson

Reputation: 116818

You should be calling the IndexedStack constructor in the build() method of a State. Store the index you want in a mutable member variable of your State, e.g. _index, and use _index as the index constructor argument for the IndexedStack. To change the _index to a different value, e.g. newIndex, you can call setState(() { _index = newIndex }); anywhere in your State.

Your call to setState will notify Flutter that your State wants to rebuild itself. At the appropriate time, Flutter will call your build() method and the new value for _index will be used.

You can learn more about widgets and state in the Flutter Widget Tour.

Upvotes: 3

Related Questions