|
@@ -1,37 +1,64 @@
|
|
|
|
|
+import 'package:chicken_farm/components/custom_app_bar.dart';
|
|
|
|
|
+import 'package:chicken_farm/pages/home/menu_buttons.dart';
|
|
|
import 'package:chicken_farm/stores/auth_store.dart';
|
|
import 'package:chicken_farm/stores/auth_store.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
+import 'profile.dart';
|
|
|
|
|
|
|
|
-class HomePage extends ConsumerWidget {
|
|
|
|
|
|
|
+class HomePage extends ConsumerStatefulWidget {
|
|
|
const HomePage({super.key});
|
|
const HomePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
- Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
|
|
+ ConsumerState<HomePage> createState() => _HomePageState();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class _HomePageState extends ConsumerState<HomePage> {
|
|
|
|
|
+ int _selectedIndex = 0;
|
|
|
|
|
+
|
|
|
|
|
+ static const List<String> _titles = ['功能菜单', '个人中心'];
|
|
|
|
|
+
|
|
|
|
|
+ @override
|
|
|
|
|
+ Widget build(BuildContext context) {
|
|
|
final authState = ref.watch(authStoreProvider);
|
|
final authState = ref.watch(authStoreProvider);
|
|
|
- final authStore = ref.read(authStoreProvider.notifier);
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
return Scaffold(
|
|
|
- appBar: AppBar(
|
|
|
|
|
- title: const Text('主页'),
|
|
|
|
|
- actions: [
|
|
|
|
|
- IconButton(
|
|
|
|
|
- icon: const Icon(Icons.logout),
|
|
|
|
|
- onPressed: () => authStore.logout(),
|
|
|
|
|
|
|
+ appBar: CustomAppBar(
|
|
|
|
|
+ title: _titles[_selectedIndex],
|
|
|
|
|
+ showBackButton: false, // 主页不显示返回按钮
|
|
|
|
|
+ ),
|
|
|
|
|
+ body: _buildBody(_selectedIndex, authState),
|
|
|
|
|
+ bottomNavigationBar: BottomNavigationBar(
|
|
|
|
|
+ type: BottomNavigationBarType.fixed,
|
|
|
|
|
+ currentIndex: _selectedIndex,
|
|
|
|
|
+ onTap: (index) {
|
|
|
|
|
+ setState(() {
|
|
|
|
|
+ _selectedIndex = index;
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ items: const [
|
|
|
|
|
+ BottomNavigationBarItem(
|
|
|
|
|
+ icon: Icon(Icons.home_outlined),
|
|
|
|
|
+ activeIcon: Icon(Icons.home),
|
|
|
|
|
+ label: '功能菜单',
|
|
|
|
|
+ ),
|
|
|
|
|
+ BottomNavigationBarItem(
|
|
|
|
|
+ icon: Icon(Icons.person_outline),
|
|
|
|
|
+ activeIcon: Icon(Icons.person),
|
|
|
|
|
+ label: '个人中心',
|
|
|
),
|
|
),
|
|
|
],
|
|
],
|
|
|
),
|
|
),
|
|
|
- body: Center(child: _buildContent(authState)),
|
|
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Widget _buildContent(AuthInfo authState) {
|
|
|
|
|
- switch (authState.state) {
|
|
|
|
|
- case AuthState.loading:
|
|
|
|
|
- return const CircularProgressIndicator();
|
|
|
|
|
- case AuthState.unauthenticated:
|
|
|
|
|
- return const Text('未登录');
|
|
|
|
|
- case AuthState.authenticated:
|
|
|
|
|
- return Text('欢迎回来, ${authState.user?.nickName ?? '访客'}!');
|
|
|
|
|
|
|
+ Widget _buildBody(int selectedIndex, AuthInfo authState) {
|
|
|
|
|
+ switch (selectedIndex) {
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ return const Center(child: MenuButtons());
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ return const ProfilePage();
|
|
|
|
|
+ default:
|
|
|
|
|
+ return const Center(child: Text('页面不存在'));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|