| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:go_router/go_router.dart';
- import 'package:news_app/constant/size_res.dart';
- import 'package:news_app/main.dart';
- import 'package:news_app/model/user_model.dart';
- import 'package:news_app/widget/load_image.dart';
- import 'package:news_app/widget/my_txt.dart';
- import '../../constant/color_res.dart';
- import '../../constant/config.dart';
- import '../../gen/assets.gen.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/9 16:00
- /// @description:
- class MainUserPage extends ConsumerStatefulWidget {
- const MainUserPage({super.key});
- @override
- ConsumerState<MainUserPage> createState() => _MainUserPageState();
- }
- class _MainUserPageState extends ConsumerState<MainUserPage>
- with AutomaticKeepAliveClientMixin {
- @override
- void initState() {
- super.initState();
- //获取用户积分信息
- ref.read(globalUserProvider.notifier).fetchUserInfo();
- eventBus.on<String>().listen((event){
- if (event == "mainCall") {
- ref.read(globalUserProvider.notifier).fetchUserInfo();
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- UserModel user = ref.watch(globalUserProvider);
- return Scaffold(
- backgroundColor: Colors.white,
- appBar: AppBar(
- // 移除阴影
- scrolledUnderElevation: 0,
- // 禁用滚动时的阴影变化
- title: myTxt(text: "我的", fontSize: 18.sp, fontWeight: FontWeight.bold),
- centerTitle: true,
- systemOverlayStyle: SystemUiOverlayStyle(
- statusBarColor: colorDCEAFE,
- statusBarIconBrightness: Brightness.dark,
- ),
- backgroundColor: colorDCEAFE,
- ),
- body: SingleChildScrollView(
- child: Stack(
- children: [
- Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [colorDCEAFE, colorDCEAFE, colorFDFEFF],
- ),
- ),
- width: screenWidth,
- height: 500.h,
- ),
- Column(
- children: [
- // 用户信息区域
- _buildUserInfoSection(context, ref),
- // 我的积分、积分商城卡片
- if (user.isShow == 1) Padding(
- padding: EdgeInsets.symmetric(horizontal: 5.w),
- child: Row(
- children: [
- Expanded(child: _buildScoreCard()),
- Expanded(child: _buildScoreShopCard()),
- ],
- ),
- ),
- // 功能列表
- _buildFunctionList(),
- _buildFunctionList2(),
- ],
- ),
- ],
- ),
- ),
- );
- }
- // 构建用户信息区域
- Widget _buildUserInfoSection(BuildContext context, WidgetRef ref) {
- UserModel user = ref.watch(globalUserProvider);
- return GestureDetector(
- onTap: () {
- context.push("/user/editProfile");
- },
- child: Container(
- padding: EdgeInsets.all(20.w),
- color: colorDCEAFE,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- Container(
- width: 66.w,
- height: 66.w,
- decoration: BoxDecoration(
- border: Border.all(color: Colors.white, width: 2.w),
- borderRadius: BorderRadius.circular(33.r),
- ),
- child: ClipOval(
- child: LoadImage(
- key: Key(Uri.encodeFull(user.avatar ?? '')),
- user.avatar ?? '',
- width: 66.w,
- height: 66.w,
- holderImg: "user_avatar",
- ),
- ),
- // CircleAvatar(
- // radius: 30,
- // backgroundImage: AssetImage(
- // Assets.images.userAvatar.path,
- // ), // 替换为实际头像路径
- // ),
- ),
- const SizedBox(width: 16),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- user.nickName ?? "",
- style: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 4),
- Text(
- user.description ?? "",
- style: TextStyle(
- fontSize: 12.sp,
- color: Colors.grey[600],
- ),
- ),
- ],
- ),
- ],
- ),
- Icon(Icons.arrow_forward_ios_rounded, color: color666666),
- ],
- ),
- ),
- );
- }
- Widget _buildScoreCard() {
- UserModel user = ref.watch(globalUserProvider);
- return GestureDetector(
- onTap: () {
- context.push("/user/score");
- },
- child: Stack(
- alignment: Alignment.centerLeft,
- children: [
- Image.asset(
- Assets.images.userScoreBg.path,
- height: 98.h,
- fit: BoxFit.fill,
- ),
- Positioned(
- left: 10.w,
- right: 10.w,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- Row(
- children: [
- SizedBox(width: 12.w),
- Image.asset(Assets.images.starIcon.path, width: 20.w),
- SizedBox(width: 5.w),
- myTxt(
- text: "我的积分",
- color: Colors.white,
- fontSize: 14.sp,
- ),
- ],
- ),
- myTxt(
- text: user.credit ?? '13045',
- color: Colors.white,
- fontWeight: FontWeight.bold,
- fontSize: 24.sp,
- ),
- ],
- ),
- Icon(Icons.chevron_right, color: Colors.white, size: 30.w),
- ],
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildScoreShopCard() {
- return GestureDetector(
- onTap: () {
- context.push("/user/shop");
- },
- child: Stack(
- alignment: Alignment.centerLeft,
- children: [
- Image.asset(
- Assets.images.userScoreShop.path,
- height: 98.h,
- fit: BoxFit.fill,
- ),
- Positioned(
- left: 10.w,
- right: 10.w,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- SizedBox(width: 12.w),
- Image.asset(Assets.images.starIcon.path, width: 20.w),
- SizedBox(width: 5.w),
- myTxt(
- text: "积分商城",
- color: Colors.white,
- fontSize: 14.sp,
- ),
- ],
- ),
- Padding(
- padding: EdgeInsets.only(top: 10.h, left: 10.w),
- child: myTxt(
- text: '海量礼品等你来兑',
- color: Colors.white,
- fontWeight: FontWeight.bold,
- fontSize: 12.sp,
- ),
- ),
- ],
- ),
- Icon(Icons.chevron_right, color: Colors.white, size: 30.w),
- ],
- ),
- ),
- ],
- ),
- );
- }
- // 构建功能列表
- Widget _buildFunctionList() {
- final List<Map<String, dynamic>> functionItems = [
- {'icon': Assets.images.activityIcon.path, 'title': '我的活动'},
- {'icon': Assets.images.messageIcon.path, 'title': '消息中心'},
- {'icon': Assets.images.favoriteIcon.path, 'title': '我的收藏'},
- {'icon': Assets.images.favoriteIcon.path, 'title': '阅读历史'},
- //{'icon': Icons.history_outlined, 'title': '历史阅读'},
- // {'icon': Icons.settings_outlined, 'title': '设置'},
- // {'icon': Icons.share, 'title': '分享APP'},
- // {'icon': Icons.feedback_outlined, 'title': '意见反馈'},
- ];
- return Card(
- margin: EdgeInsets.all(10.w),
- child: ListView.separated(
- physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- padding: EdgeInsets.symmetric(horizontal: 15.w),
- itemCount: functionItems.length,
- separatorBuilder:
- (context, index) => Divider(height: 0.5.h, color: Colors.grey[200]),
- itemBuilder: (context, index) {
- final item = functionItems[index];
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- _itemClick(item["title"]);
- },
- child: SizedBox(
- height: 45.h,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- Image.asset(
- item['icon'],
- color: color333333,
- width: 24.w,
- ),
- SizedBox(width: 5.w),
- myTxt(
- text: item['title'],
- fontSize: 16.sp,
- color: color333333,
- ),
- ],
- ),
- Icon(Icons.chevron_right, color: Colors.grey),
- ],
- ),
- ),
- );
- },
- ),
- );
- }
- Widget _buildFunctionList2() {
- final List<Map<String, dynamic>> functionItems = [
- // {'icon': Icons.card_giftcard, 'title': '我的活动'},
- // {'icon': Icons.message_outlined, 'title': '消息中心'},
- // {'icon': Icons.collections_bookmark_outlined, 'title': '我的收藏'},
- //{'icon': Icons.history_outlined, 'title': '历史阅读'},
- {'icon': Assets.images.settingIcon.path, 'title': '设置'},
- {'icon': Assets.images.shareIcon.path, 'title': '分享APP'},
- {'icon': Assets.images.feedbackIcon.path, 'title': '意见反馈'},
- ];
- return Card(
- margin: EdgeInsets.all(10.w),
- child: ListView.separated(
- physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- padding: EdgeInsets.symmetric(horizontal: 15.w),
- itemCount: functionItems.length,
- separatorBuilder:
- (context, index) => Divider(height: 0.5.h, color: Colors.grey[200]),
- itemBuilder: (context, index) {
- final item = functionItems[index];
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- _itemClick(item["title"]);
- },
- child: SizedBox(
- height: 45.h,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- Image.asset(
- item['icon'],
- color: color333333,
- width: 24.w,
- ),
- SizedBox(width: 5.w),
- myTxt(
- text: item['title'],
- fontSize: 16.sp,
- color: color333333,
- ),
- ],
- ),
- Icon(Icons.chevron_right, color: Colors.grey),
- ],
- ),
- ),
- );
- },
- ),
- );
- }
- void _itemClick(String title) {
- switch (title) {
- case "我的活动":
- context.push("/user/activity");
- break;
- case "消息中心":
- context.push('/user/msgCenter');
- break;
- case "我的收藏":
- context.push("/user/favorite");
- break;
- case "阅读历史":
- context.push("/user/readHistory");
- break;
- case "设置":
- context.push("/user/setting");
- break;
- case "分享APP":
- context.push("/user/share");
- break;
- case "意见反馈":
- context.push("/user/feedback");
- break;
- }
- }
- @override
- bool get wantKeepAlive => true;
- }
|