183 lines
5.5 KiB
Dart
183 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_common/utils/sp_utils.dart';
|
|
import 'package:flutter_common/widget/common_widget.dart';
|
|
import 'package:flutter_common/widget/dialog_widget.dart';
|
|
import 'package:food_hub_app/provider/app_provider.dart';
|
|
import 'package:food_hub_app/provider/user_provider.dart';
|
|
import 'package:food_hub_app/views/profile_form.dart';
|
|
import 'package:food_hub_app/widgets/profile/basic_info.dart';
|
|
import 'package:liquid_glass_widgets/liquid_glass_widgets.dart';
|
|
import 'package:liquid_glass_widgets/widgets/containers/glass_card.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class ProfilePage extends StatefulWidget {
|
|
const ProfilePage({super.key});
|
|
|
|
@override
|
|
State<ProfilePage> createState() => ProfilePageState();
|
|
}
|
|
|
|
class ProfilePageState extends State<ProfilePage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// 初始化加载数据
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.read<UserProvider>().refreshUser(SPUtil.getInt('userId'));
|
|
});
|
|
}
|
|
|
|
Widget _buildFunctionButton({
|
|
required IconData icon,
|
|
required String text,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
return ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
leading: Icon(icon, color: colors.primary),
|
|
title: Text(text),
|
|
trailing: Icon(Icons.arrow_forward_ios, size: 16, color: colors.primary),
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
void _onTapInfo(UserProvider provider) {
|
|
provider.initUserForm(provider.currentUser);
|
|
|
|
Navigator.pushNamed(context, '/profileForm');
|
|
// showModalBottomSheet(
|
|
// context: context,
|
|
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
// isScrollControlled: true,
|
|
// shape: const RoundedRectangleBorder(
|
|
// borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
// ),
|
|
// builder: (context) => ProfileForm(),
|
|
// );
|
|
}
|
|
|
|
void _onTapMoment() {
|
|
Navigator.pushNamed(context, '/momentUser');
|
|
}
|
|
|
|
Widget _buildFunctionButtons(BuildContext context) {
|
|
final provider = context.watch<UserProvider>();
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return GlassCard(
|
|
padding: EdgeInsetsGeometry.symmetric(vertical: 0, horizontal: 10),
|
|
useOwnLayer: true,
|
|
settings: LiquidGlassSettings(glassColor: colors.surface),
|
|
child: Column(
|
|
children: [
|
|
_buildFunctionButton(
|
|
icon: Icons.account_circle,
|
|
text: '基本信息',
|
|
onTap: () => _onTapInfo(provider),
|
|
),
|
|
const Divider(height: 1, thickness: 0.2),
|
|
_buildFunctionButton(
|
|
icon: Icons.group_outlined,
|
|
text: '朋友圈',
|
|
onTap: _onTapMoment,
|
|
),
|
|
const Divider(height: 1, thickness: 0.2),
|
|
_buildFunctionButton(
|
|
icon: Icons.favorite,
|
|
text: '我的收藏',
|
|
onTap: () {
|
|
// 跳转到浏览历史页面
|
|
// LogUtils.i('点击浏览历史');
|
|
},
|
|
),
|
|
const Divider(height: 1, thickness: 0.2),
|
|
_buildFunctionButton(
|
|
icon: Icons.lock,
|
|
text: '更改密码',
|
|
onTap: () {
|
|
// 跳转到帮助与反馈页面
|
|
// LogUtils.i('点击帮助与反馈');
|
|
},
|
|
),
|
|
const Divider(height: 1, thickness: 0.2),
|
|
_buildFunctionButton(icon: Icons.message, text: '反馈意见', onTap: () {}),
|
|
const Divider(height: 1, thickness: 0.2),
|
|
_buildFunctionButton(icon: Icons.refresh, text: '检查更新', onTap: () {}),
|
|
const Divider(height: 1, thickness: 0.2),
|
|
_buildFunctionButton(
|
|
icon: Icons.exit_to_app,
|
|
text: '退出登录',
|
|
onTap: _onTapLogout,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _onTapLogout() async {
|
|
final result = await showConfirmDialog(context, '确认要退出吗?');
|
|
if (result == true) {
|
|
SPUtil.remove('token');
|
|
Navigator.pop(context);
|
|
Navigator.pushNamed(context, '/login');
|
|
}
|
|
}
|
|
|
|
Widget _buildVersionInfo() {
|
|
final provider = context.read<AppProvider>();
|
|
|
|
return Text(
|
|
'版本 v${provider.fullVersion}',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildContent(UserProvider provider, BuildContext context) {
|
|
final user = provider.currentUser;
|
|
return Column(
|
|
children: [
|
|
SizedBox(width: double.infinity, child: ProfileInfo(user: user)),
|
|
const SizedBox(height: 16),
|
|
_buildFunctionButtons(context),
|
|
const SizedBox(height: 8),
|
|
_buildVersionInfo(),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = context.watch<UserProvider>();
|
|
|
|
return Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: AppBar(
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
title: Text('我的', style: Theme.of(context).textTheme.titleLarge),
|
|
centerTitle: true,
|
|
automaticallyImplyLeading: false,
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsetsGeometry.all(10),
|
|
child: Stack(
|
|
children: [
|
|
if (provider.isLoading)
|
|
buildLoadingIndicator()
|
|
else
|
|
SingleChildScrollView(
|
|
padding: const EdgeInsets.only(bottom: 90),
|
|
child: _buildContent(provider, context),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|