| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:sino_med_cloud/core/utils/logger.dart'; // 添加日志引用
- import 'HomePage/presentation/home_page.dart';
- import 'HospitalPage/presentation/hospital_page.dart';
- import 'MallPage/presentation/mall_page.dart';
- import 'MinePage/presentation/mine_page.dart';
- import 'main_tab_provider.dart';
- class MainTabPage extends ConsumerWidget {
- const MainTabPage({super.key});
- static const List<Widget> _pages = [
- HomePage(),
- HospitalPage(),
- MallPage(),
- MinePage(),
- ];
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- AppLogger.d('MainTabPage - 正在构建'); // 添加构建日志
- // 使用 ref.watch 监听当前 tab 索引的变化
- final currentIndex = ref.watch(currentTabIndexProvider);
- return Scaffold(
- body: IndexedStack(
- index: currentIndex,
- children: _pages,
- ),
- bottomNavigationBar: BottomNavigationBar(
- currentIndex: currentIndex,
- type: BottomNavigationBarType.fixed,
- onTap: (index) {
- // 使用 ref.read 更新状态
- ref.read(currentTabIndexProvider.notifier).state = index;
- },
- items: const [
- BottomNavigationBarItem(
- icon: Icon(Icons.home_outlined),
- activeIcon: Icon(Icons.home),
- label: '首页',
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.local_hospital_outlined),
- activeIcon: Icon(Icons.local_hospital),
- label: '医院',
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.shopping_cart_outlined),
- activeIcon: Icon(Icons.shopping_cart),
- label: '商城',
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.person_outlined),
- activeIcon: Icon(Icons.person),
- label: '我的',
- ),
- ],
- ),
- );
- }
- }
|