-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathbottomnavbar.dart
62 lines (56 loc) · 1.55 KB
/
bottomnavbar.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import 'package:flutter/material.dart';
import '/9_bottom-nav_bar/pages/home.dart';
import '/9_bottom-nav_bar/pages/message.dart';
import '/9_bottom-nav_bar/pages/settings.dart';
import '/9_bottom-nav_bar/pages/account.dart';
class MyBottomNavBar extends StatefulWidget {
const MyBottomNavBar({Key? key}) : super(key: key);
@override
State<MyBottomNavBar> createState() => _MyBottomNavBarState();
}
class _MyBottomNavBarState extends State<MyBottomNavBar> {
int _selectIndex = 0;
void _navigateBottomBar(int index) {
setState(() {
_selectIndex = index;
});
}
final List<Widget> _pages = [
const HomePage(),
const MessagePage(),
const SettingsPage(),
const AccountPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Bottom Nav bar"),
),
body: _pages[_selectIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _selectIndex,
onTap: _navigateBottomBar,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.message),
label: 'Message',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Account',
),
],
),
);
}
}