Created with <3 with dartpad.dev.
Last active
November 2, 2023 09:42
-
-
Save iammashikur/991111dbec63dbb1589c1b5e11438112 to your computer and use it in GitHub Desktop.
elusive-cloud-1736
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
int _currentIndex = 0; | |
final List<Widget> _pages = [ | |
Page1(), | |
Page2(), | |
Page3(), | |
]; | |
void _onItemTapped(int index) { | |
setState(() { | |
_currentIndex = index; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
// appBar: AppBar( | |
// title: Text('Bottom Navigation Example'), | |
// ), | |
body: _pages[_currentIndex], | |
bottomNavigationBar: BottomNavigationBar( | |
items: [ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.home), | |
label: 'Page 1', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.business), | |
label: 'Page 2', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.school), | |
label: 'Page 3', | |
), | |
], | |
currentIndex: _currentIndex, | |
onTap: _onItemTapped, | |
), | |
), | |
); | |
} | |
} | |
class Page1 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Text('Page 1'), | |
); | |
} | |
} | |
class Page2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Text('Page 2'), | |
); | |
} | |
} | |
class Page3 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Text('Page 3'), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment