Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- class HomeScreen extends StatefulWidget {
- @override
- _HomeScreenState createState() => _HomeScreenState();
- }
- class _HomeScreenState extends State<HomeScreen> {
- int position = 0;
- PageController pageController = PageController(initialPage: 0);
- navigateToPage(int index) {
- setState(() {
- position = index;
- });
- pageController.animateToPage(position,
- duration: Duration(seconds: 1), curve: Curves.bounceIn);
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("PageView"),
- ),
- body: PageView(
- controller: pageController,
- onPageChanged: (index) {
- navigateToPage(index);
- },
- children: [
- Container(
- child: Center(child: Text("Home")),
- ),
- Container(
- child: Center(child: Text("Profile")),
- ),
- Container(
- child: Center(child: Text("Feed")),
- ),
- Container(
- child: Center(child: Text("Notifications")),
- ),
- Container(
- child: Center(child: Text("Settings")),
- ),
- ],
- ),
- bottomNavigationBar: BottomNavigationBar(
- fixedColor: Colors.red,
- unselectedItemColor: Colors.black,
- type: BottomNavigationBarType.fixed,
- currentIndex: position,
- onTap: (index) {
- navigateToPage(index);
- },
- items: [
- BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
- BottomNavigationBarItem(
- icon: Icon(Icons.verified_user), label: "Profile"),
- BottomNavigationBarItem(icon: Icon(Icons.feedback), label: "Feed"),
- BottomNavigationBarItem(
- icon: Icon(Icons.notifications), label: "Notifications"),
- BottomNavigationBarItem(
- icon: Icon(Icons.settings), label: "Settings"),
- ]),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement