forked from ibhavikmakwana/FlutterPlayground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBottomNavigation.dart
More file actions
90 lines (81 loc) · 2.03 KB
/
BottomNavigation.dart
File metadata and controls
90 lines (81 loc) · 2.03 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class BottomNavigation extends StatefulWidget {
BottomNavigation({Key key, this.title}) : super(key: key);
final String title;
@override
_BottomNavigationState createState() => _BottomNavigationState();
}
class _BottomNavigationState extends State<BottomNavigation> {
PageController _pageController;
var _page = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: PageView(
children: <Widget>[
Container(
color: Colors.orangeAccent,
),
Container(
color: Colors.redAccent,
),
Container(
color: Colors.blueAccent,
),
],
controller: _pageController,
physics: BouncingScrollPhysics(),
onPageChanged: onPageChanged,
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.photo),
label: "Photo",
),
BottomNavigationBarItem(
icon: Icon(Icons.map),
label: "Map",
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite),
label: "Favorite",
),
],
onTap: navigationTapped,
currentIndex: _page,
),
);
}
///
/// Bottom Navigation tap listener
///
void navigationTapped(int page) {
_pageController.animateToPage(
page,
duration: Duration(milliseconds: 300),
curve: Curves.easeIn,
);
}
void onPageChanged(int page) {
setState(() {
this._page = page;
});
}
@override
void initState() {
super.initState();
_pageController = PageController();
}
@override
void dispose() {
super.dispose();
_pageController.dispose();
}
}