BottomNavigationBar rebuilds Page on change of tab
None of the previous answers worked out for me.
The solution to keep the pages alive when switching the tabs is wrapping your Pages in an IndexedStack.
class Tabbar extends StatefulWidget {
Tabbar({this.screens});
static const Tag = "Tabbar";
final List<Widget> screens;
@override
State<StatefulWidget> createState() {
return _TabbarState();
}
}
class _TabbarState extends State<Tabbar> {
int _currentIndex = 0;
Widget currentScreen;
@override
Widget build(BuildContext context) {
var _l10n = PackedLocalizations.of(context);
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: widget.screens,
),
bottomNavigationBar: BottomNavigationBar(
fixedColor: Colors.black,
type: BottomNavigationBarType.fixed,
onTap: onTabTapped,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.format_list_bulleted),
title: new Text(_l10n.tripsTitle),
),
BottomNavigationBarItem(
icon: new Icon(Icons.settings),
title: new Text(_l10n.settingsTitle),
)
],
),
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
}
Also in JavaScript:
- jest manual mock node module
- split a message
- how to call function on every keypress in jquery
- set in javascript
- javascript clearinterval
- what is es11
- arrow function component react shortcut vscode
- javascript range of integers
- how to generate random string in node js
- output event angular
- how to recognize an array in javascript
- queryselector for jquery
- get current date javascript full month
- prettier config vscode
- javascript name capitalization
- document.addEventListener("backbutton
- javascript insert item into array
- how to push items in array in javascript
- nuxt js lazy load page pagination
- .fetch method
- JQuery UI Saving Sortable List
- Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
- javascript prepend element to array
- javascript string first letter lowercase