Here is an example of Navigation rail in flutter,
Here is the full code from main.dart file.
import 'package:flutter/material.dart';
main(List<String> args) {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@
override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: MyNavigationRail(),
),
);
}
}
class MyNavigationRail extends StatefulWidget {
const MyNavigationRail({Key? key}) : super(key: key);
@
override
State<MyNavigationRail> createState() => _MyNavigationRailState();
}
class _MyNavigationRailState extends State<MyNavigationRail> {
var _selectedIndex = 0;
@
override
Widget build(BuildContext context) {
return Row(
children: [
NavigationRail(
destinations: const [
NavigationRailDestination(
icon: Icon(Icons.home), label: Text('Home')),
NavigationRailDestination(
icon: Icon(Icons.school), label: Text('School')),
NavigationRailDestination(
icon: Icon(Icons.book), label: Text('Books'))
],
selectedIndex: _selectedIndex,
onDestinationSelected: (value) {
setState(() {
_selectedIndex = value;
});
},
),
Expanded(child: Center(child: Text('Selected Index: $_selectedIndex
')))
],
);
}
}
Thanks,Srikanth