main_page.dart 1.3 KB

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