Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Side Navigation Bar widget

Screenshot of what I am looking for

How can I achieve this side navigation bar (left) in Flutter? There is a widget for this if I'm not wrong, but I can't find the name anywhere.

like image 440
xyron Avatar asked Oct 19 '25 09:10

xyron


2 Answers

The widget you are searching for is called NavigationRail.
It is very well documented as part of the official Flutter API.

The example usage is as follows:

int _selectedIndex = 0;

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Row(
      children: <Widget>[
        NavigationRail(
          selectedIndex: _selectedIndex,
          onDestinationSelected: (int index) {
            setState(() {
              _selectedIndex = index;
            });
          },
          labelType: NavigationRailLabelType.selected,
          destinations: [
            NavigationRailDestination(
              icon: Icon(Icons.favorite_border),
              selectedIcon: Icon(Icons.favorite),
              label: Text('First'),
            ),
            NavigationRailDestination(
              icon: Icon(Icons.bookmark_border),
              selectedIcon: Icon(Icons.book),
              label: Text('Second'),
            ),
            NavigationRailDestination(
              icon: Icon(Icons.star_border),
              selectedIcon: Icon(Icons.star),
              label: Text('Third'),
            ),
          ],
        ),
        VerticalDivider(thickness: 1, width: 1),
        // This is the main content.
        Expanded(
          child: Center(
            child: Text('selectedIndex: $_selectedIndex'),
          ),
        )
      ],
    ),
  );
}
like image 104
creativecreatorormaybenot Avatar answered Oct 21 '25 02:10

creativecreatorormaybenot


This is called Navigation Rail. You can find out more here

Usage:

child:NavigationRail(
  selectedIndex:_currentIndex,
  onDestinationSelected: (int index) {
    setState(() {
      // Change Index When Widget is Selected.
      _currentIndex = index;
    });
  destinations:[
    // You Navigation Rail Items/Destinations
    NavigationRailDestination(
      icon: Icon(Icons.favorite_border),
      selectedIcon: Icon(Icons.favorite),
      label: Text('Home'),
    ),
  ]
  },
like image 39
Adnan karim Avatar answered Oct 21 '25 01:10

Adnan karim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!