I want to show a SnackBar Widget when the bottom tab is clicked. I am trying to show it as:
Scaffold.of(context).showSnackBar(new SnackBar(
cont
Change your _handleBottomNavigationBarTap
method to take a BuildContext
argument.
void _handleBottomNavigationBarTap(int newValue, BuildContext context) {
...
}
Then change your bottomNavigationBar
argument as follows:
bottomNavigationBar: new Builder(
builder: (BuildContext context) {
return new BottomNavigationBar(
labels: bottomBarLabels,
onTap: (index) => _handleBottomNavigationBarTap(index, context),
);
}
),
This ensures that you call to Scaffold.of(context)
will be able to find a ScaffoldState
that is an ancestor of the context
.