main_page.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:flutter/material.dart';
  2. import 'package:physigo/exercises/exercises_page.dart';
  3. import 'package:physigo/friends/friends_page.dart';
  4. import 'package:physigo/home/home_page.dart';
  5. import 'package:physigo/ranking/ranking_page.dart';
  6. class MainPage extends StatefulWidget {
  7. const MainPage({Key? key}) : super(key: key);
  8. @override
  9. State<MainPage> createState() => _MainPage();
  10. }
  11. class _MainPage extends State<MainPage> {
  12. static const List<Widget> _widgets = [
  13. HomePage(),
  14. ExercisesPage(),
  15. RankingPage(),
  16. FriendsPage(),
  17. ];
  18. int _selectedIndex = 0;
  19. void _onMenuTap(int newIndex) {
  20. setState(() {
  21. _selectedIndex = newIndex;
  22. });
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return SafeArea(
  27. child: Scaffold(
  28. bottomNavigationBar: BottomNavigationBar(
  29. type: BottomNavigationBarType.fixed, // need to specify fixed with more than 3 items
  30. currentIndex: _selectedIndex,
  31. onTap: _onMenuTap,
  32. items: const [
  33. BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
  34. BottomNavigationBarItem(icon: Icon(Icons.sports_gymnastics), label: "Exercises"),
  35. BottomNavigationBarItem(icon: Icon(Icons.emoji_events), label: "Ranking"),
  36. BottomNavigationBarItem(icon: Icon(Icons.people), label: "Social"),
  37. ],
  38. ),
  39. body: _widgets[_selectedIndex],
  40. ),
  41. );
  42. }
  43. }