I am currently developing a cross platform app in which I wanted to use a Sidebar for navigation on desktop and tablet view, but a bottom navigation bar for mobile, as it isn’t really handy to use a sidebar on mobile.
I have trouble with the navigation part, as for the sidebar I can just easily use the push() function. But with the bottomNavBar I have to use the onItemTapped function with indexes etc. Is there an easy way to use them together/switch between them?
This is my navigation for the Sidebar:
@override
Widget build(BuildContext context) {
return ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => page),
);
},
And this is how I tried to do the bottomNavBar navigation:
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
body: PageNavigationItem.items.elementAt(_selectedIndex),
);
} // build method
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
2
Answers
There is, to my knowledge, no way to solve your issue unless you "make your own bottom navigation bar".
I would however ask if you don’t want to use a Drawer widget instead of a bottom navigation bar as it is a way to keep your app consistent across platforms, follows flutters guidelines for projects and permit you to use push. It is a "sidebar" in a sense.
I would do my own bottom navigation bar if I felt I needed it no matter what,something like this:
with this in the main page
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
This is the result
But seriously, it is just easier and better to use a Drawer widget
Yes it is possible and once check below example code.
Video of how it will works.
https://drive.google.com/file/d/1BxK6qevJOu4qYrmnoTXdIYtqLAVC87ya/view?usp=share_link
Here we are creating a model for Title and onTap
Here we are creating a list of DataModel so will use in Title and onTap.
Function for get device is mobile or tablet
here is full code of that page.
I Hope these things are solve your issue.