// 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 { PageController _pageController; var _page = 0; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: PageView( children: [ 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(); } }