Created
June 28, 2021 05:34
-
-
Save utgupta27/e7d5e37ae4a7a56fda80a3bb59643e20 to your computer and use it in GitHub Desktop.
Switch to Multiple Pages using Bottom Navigation Bar Widget in Flutter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:<Your-project-directory>/navigationBar/bottomNavigationBar.dart'; | |
import 'package:<Your-project-directory>/todoPage/todoPage.dart'; | |
import 'package:<Your-project-directory>/notesPage/notesPage.dart'; | |
import 'package:<Your-project-directory>/reminderPage/reminderPage.dart'; | |
import 'package:<Your-project-directory>/drawer/drawer.dart'; | |
class HomePage extends StatefulWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
int _currentIndex = 0; | |
final List<Widget> _screens = [TodoPage(), NotesPage(), ReminderPage()]; | |
void onItemTapped(int val) { | |
setState(() { | |
_currentIndex = val; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Project Name"), | |
backgroundColor: Colors.blue[800], | |
), | |
drawer: MyDrawer(), | |
body: _screens[_currentIndex], | |
bottomNavigationBar: new BottomNavyBar( | |
items: [ | |
BottomNavyBarItem( | |
icon: Icon( | |
Icons.task_alt, | |
size: 30, | |
), | |
title: Text( | |
" Item 1", | |
style: TextStyle(fontSize: 20), | |
)), | |
BottomNavyBarItem( | |
icon: Icon( | |
Icons.note_alt_outlined, | |
size: 30, | |
), | |
title: Text(" Item 2", style: TextStyle(fontSize: 20))), | |
BottomNavyBarItem( | |
icon: Icon( | |
Icons.alarm_on_outlined, | |
size: 30, | |
), | |
title: Text(" Item 3", style: TextStyle(fontSize: 20))) | |
], | |
selectedIndex: _currentIndex, | |
onItemSelected: onItemTapped, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment