Advertisement
narimetisaigopi

page view flutter

May 31st, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class HomeScreen extends StatefulWidget {
  4. @override
  5. _HomeScreenState createState() => _HomeScreenState();
  6. }
  7.  
  8. class _HomeScreenState extends State<HomeScreen> {
  9. int position = 0;
  10.  
  11. PageController pageController = PageController(initialPage: 0);
  12.  
  13. navigateToPage(int index) {
  14. setState(() {
  15. position = index;
  16. });
  17.  
  18. pageController.animateToPage(position,
  19. duration: Duration(seconds: 1), curve: Curves.bounceIn);
  20. }
  21.  
  22. @override
  23. Widget build(BuildContext context) {
  24. return Scaffold(
  25. appBar: AppBar(
  26. title: Text("PageView"),
  27. ),
  28. body: PageView(
  29. controller: pageController,
  30. onPageChanged: (index) {
  31. navigateToPage(index);
  32. },
  33. children: [
  34. Container(
  35. child: Center(child: Text("Home")),
  36. ),
  37. Container(
  38. child: Center(child: Text("Profile")),
  39. ),
  40. Container(
  41. child: Center(child: Text("Feed")),
  42. ),
  43. Container(
  44. child: Center(child: Text("Notifications")),
  45. ),
  46. Container(
  47. child: Center(child: Text("Settings")),
  48. ),
  49. ],
  50. ),
  51. bottomNavigationBar: BottomNavigationBar(
  52. fixedColor: Colors.red,
  53. unselectedItemColor: Colors.black,
  54. type: BottomNavigationBarType.fixed,
  55. currentIndex: position,
  56. onTap: (index) {
  57. navigateToPage(index);
  58. },
  59. items: [
  60. BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
  61. BottomNavigationBarItem(
  62. icon: Icon(Icons.verified_user), label: "Profile"),
  63. BottomNavigationBarItem(icon: Icon(Icons.feedback), label: "Feed"),
  64. BottomNavigationBarItem(
  65. icon: Icon(Icons.notifications), label: "Notifications"),
  66. BottomNavigationBarItem(
  67. icon: Icon(Icons.settings), label: "Settings"),
  68. ]),
  69. );
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement