import 'package:flutter/material.dart'; import 'package:flutter_common/widget/common_widget.dart'; import 'package:food_hub_app/provider/user_provider.dart'; import 'package:food_hub_app/widgets/common/index.dart'; import 'package:food_hub_app/widgets/moment/list.dart'; import 'package:food_hub_app/widgets/profile/basic_info.dart'; import 'package:food_hub_app/widgets/recipe/list.dart'; import 'package:provider/provider.dart'; enum ProfileTab { profile('基础信息'), moment('朋友圈'), recipe('菜谱'); final String label; const ProfileTab(this.label); } class ProfileUserPage extends StatefulWidget { const ProfileUserPage({super.key}); @override State createState() => ProfileUserPageState(); } class ProfileUserPageState extends State { late ProfileTab currentTab = ProfileTab.profile; void _onTabChange(ProfileTab tab) { setState(() { currentTab = tab; }); // provider.onRecordTabChange(); } Widget _buildTabs({ required BuildContext context, required ProfileTab currentTab, required ValueChanged onTabChanged, }) { return Container( padding: EdgeInsets.all(8), child: buildToggleSwitch( context: context, currentTab: currentTab, tabValues: ProfileTab.values, labels: ProfileTab.values.map((e) => e.label).toList(), onTabChanged: onTabChanged, ), ); } Widget _buildContent(UserProvider provider) { return Column( children: [ _buildTabs( context: context, currentTab: currentTab, onTabChanged: (tab) => _onTabChange(tab), ), Expanded( child: IndexedStack( index: currentTab.index, children: [ SizedBox( width: double.infinity, child: ProfileInfo(user: provider.currentUser) ), MomentList(momentList: provider.momentList, isUser: false), RecipeList(userId: provider.currentUser.id!), ], ), ), ], ); } @override Widget build(BuildContext context) { final provider = context.watch(); final colors = Theme.of(context).colorScheme; return Scaffold( appBar: AppBar( title: Text( '${provider.currentUser.username}的个人信息', style: Theme.of(context).textTheme.titleLarge, ), backgroundColor: Theme.of(context).scaffoldBackgroundColor, leading: IconButton( icon: Icon(Icons.arrow_back, color: colors.primary), onPressed: () => Navigator.pop(context), ), ), body: Padding( padding: const EdgeInsets.all(10), child: Stack( children: [ if (provider.isLoading) buildLoadingIndicator() else if (provider.error.isNotEmpty) Text(provider.error) else _buildContent(provider), ], ), ), ); } }