main_tab_page.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'HomePage/presentation/home_page.dart';
  4. import 'HospitalPage/presentation/hospital_page.dart';
  5. import 'MallPage/presentation/mall_page.dart';
  6. import 'MinePage/presentation/mine_page.dart';
  7. class MainTabPage extends ConsumerStatefulWidget{
  8. const MainTabPage({super.key});
  9. @override
  10. ConsumerState<MainTabPage> createState() => _MainTabPageState();
  11. }
  12. class _MainTabPageState extends ConsumerState<MainTabPage>
  13. with SingleTickerProviderStateMixin {
  14. int _currentIndex = 0;
  15. final List<Widget> _pages = const [
  16. HomePage(),
  17. HospitalPage(),
  18. MallPage(),
  19. MinePage(),
  20. ];
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. body: IndexedStack(
  25. index: _currentIndex,
  26. children: _pages,
  27. ),
  28. bottomNavigationBar: BottomNavigationBar(
  29. currentIndex: _currentIndex,
  30. type: BottomNavigationBarType.fixed,
  31. onTap: (index) {
  32. setState(() {
  33. _currentIndex = index;
  34. });
  35. },
  36. items: const [
  37. BottomNavigationBarItem(
  38. icon: Icon(Icons.home_outlined),
  39. activeIcon: Icon(Icons.home),
  40. label: '首页',
  41. ),
  42. BottomNavigationBarItem(
  43. icon: Icon(Icons.local_hospital_outlined),
  44. activeIcon: Icon(Icons.local_hospital),
  45. label: '医院',
  46. ),
  47. BottomNavigationBarItem(
  48. icon: Icon(Icons.shopping_cart_outlined),
  49. activeIcon: Icon(Icons.shopping_cart),
  50. label: '商城',
  51. ),
  52. BottomNavigationBarItem(
  53. icon: Icon(Icons.person_outlined),
  54. activeIcon: Icon(Icons.person),
  55. label: '我的',
  56. ),
  57. ]
  58. ),
  59. );
  60. }
  61. }