import 'package:easy_refresh/easy_refresh.dart'; 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/extension/base.dart'; import 'package:news_app/provider/user_score_provider.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'; import '../../main.dart'; import '../../model/user_model.dart'; import '../../model/user_score_model.dart'; import '../../util/theme_util.dart'; import '../../widget/list_animation_layout.dart'; /// @author: bo.zeng /// @email: cnhbwds@gmail.com /// @date: 2025 2025/4/9 16:00 /// @description: class UserScorePage extends ConsumerStatefulWidget { const UserScorePage({super.key}); @override ConsumerState createState() => _UserScorePageState(); } final userScoreProvider = NotifierProvider( () { return UserScoreProvider(); }, ); class _UserScorePageState extends ConsumerState { int pageNum = 0; int totalNews = 0; @override void initState() { super.initState(); setImmersiveStatusBar(); ref.read(userScoreProvider.notifier).fetchUserScoreList(pageNum); eventBus.on().listen((event) { if (event == "mainCall") { pageNum = 0; ref.read(userScoreProvider.notifier).fetchUserScoreList(pageNum); } }); } @override void dispose() { // TODO: implement dispose super.dispose(); } @override Widget build(BuildContext context) { final scoreData = ref.watch(userScoreProvider); ref.listen(userScoreProvider, (pre, next) { totalNews = next.rows?.length ?? 0; }); return AnnotatedRegion( value: SystemUiOverlayStyle.light, // or dark based on背景 child: Material( child: Stack( children: [ _buildHeader(context), Positioned( top: 180.h, bottom: 0, left: horizontalPadding, right: horizontalPadding, child: Container( padding: EdgeInsets.all(16.w), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10.w), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.start, children: [ LoadAssetImage("score_shop", width: 40.w, height: 40.h), SizedBox(width: 8.w), Expanded( child: myTxt( text: "积分商城", fontWeight: FontWeight.bold, fontSize: 16.sp, ), ), GestureDetector( onTap: () { context.push("/user/shop"); }, child: Container( width: 90.w, height: 28.h, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(14.w), gradient: LinearGradient( colors: [color5F59F7, color6592FD], begin: Alignment.centerLeft, end: Alignment.centerRight, ), ), alignment: Alignment.center, child: myTxt( text: "我要兑换", fontWeight: FontWeight.normal, fontSize: 13.sp, color: Colors.white, ), ), ), ], ), SizedBox(height: 10.h), Divider(height: 0.1.h, color: Colors.grey[300]), SizedBox(height: 10.h), myTxt( text: "积分明细", fontWeight: FontWeight.bold, fontSize: 20.sp, ), SizedBox(height: 10.h), Expanded( child: SafeArea( top: false, child: EasyRefresh.builder( onRefresh: () async { pageNum = 0; await ref .read(userScoreProvider.notifier) .fetchUserScoreList(pageNum); return IndicatorResult.success; }, onLoad: () async { if (totalNews >= scoreData.total.safeValue) { return IndicatorResult.noMore; } else { pageNum++; await ref .read(userScoreProvider.notifier) .fetchUserScoreList(pageNum); return IndicatorResult.success; } }, childBuilder: (context, py) { return (scoreData.rows ?? []).isEmpty ? ListAnimationLayout() : ListView.separated( padding: EdgeInsets.zero, separatorBuilder: (context, index) => Divider( height: 0.1.h, color: Colors.grey[300], ), itemCount: scoreData.rows?.length ?? 0, itemBuilder: (context, index) { final item = scoreData.rows?[index] ?? UserScoreModelRows(); return ListTile( contentPadding: EdgeInsets.zero, title: Text( item.opType ?? '', style: TextStyle(fontSize: 16), ), subtitle: Text( item.logTime ?? '', style: TextStyle(color: Colors.grey), ), trailing: Text( "${item.changeExp}积分", style: TextStyle( fontSize: 16, color: Colors.black, fontWeight: FontWeight.bold, ), ), ); }, ); }, ), ), ), ], ), ), ), ], ), ), ); } Widget _buildHeader(BuildContext context) { UserModel user = ref.watch(globalUserProvider); return SizedBox( width: double.infinity, height: 240.h, // 你自己项目里的适配高度 child: Stack( fit: StackFit.expand, // 横向完全撑满 children: [ Image.asset(Assets.images.scoreNewBg.path, fit: BoxFit.cover), Padding( padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 40.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 14.h), Row( children: [ GestureDetector( onTap: () { eventBus.fire('mainCall'); context.pop(); }, child: Icon(Icons.arrow_back_ios, color: Colors.white), ), Expanded( child: Center( child: myTxt( text: '积分详情', fontWeight: FontWeight.bold, fontSize: 18.sp, color: Colors.white, ), ), ), ], ), SizedBox(height: 30.h), Row( children: [ Image.asset(Assets.images.starIcon.path, width: 20.w), SizedBox(width: 10.w), Text( '我的积分', style: TextStyle(fontSize: 16.sp, color: Colors.white70), ), ], ), SizedBox(height: 5.h), Text( user.credit ?? '10345', style: TextStyle( fontSize: 30.sp, fontWeight: FontWeight.bold, color: Colors.white, ), ), ], ), ), ], ), ); } } // class PointsDetailPage extends StatelessWidget { // final List> pointsHistory = [ // { // 'type': '登录赠送', // 'date': '2025.12.25 12:00', // 'points': 10, // 'isPositive': true, // }, // { // 'type': '商品兑换', // 'date': '2025.12.25 12:00', // 'points': -10, // 'isPositive': false, // }, // { // 'type': '商品兑换', // 'date': '2025.12.25 12:00', // 'points': -10, // 'isPositive': false, // }, // { // 'type': '登录赠送', // 'date': '2025.12.25 12:00', // 'points': 10, // 'isPositive': true, // }, // { // 'type': '商品兑换', // 'date': '2025.12.25 12:00', // 'points': -10, // 'isPositive': false, // }, // { // 'type': '商品兑换', // 'date': '2025.12.25 12:00', // 'points': -10, // 'isPositive': false, // }, // { // 'type': '登录赠送', // 'date': '2025.12.25 12:00', // 'points': 10, // 'isPositive': true, // }, // { // 'type': '登录赠送', // 'date': '2025.12.25 12:00', // 'points': 10, // 'isPositive': true, // }, // ]; // // PointsDetailPage({super.key}); // // @override // Widget build(BuildContext context) { // // return Material( // child: Stack( // children: [ // _buildHeader(context), // Positioned( // top: 180.h, // bottom: 0, // left: horizontalPadding, // right: horizontalPadding, // child: Container( // padding: EdgeInsets.all(16.w), // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(10.w), // ), // child: Column( // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // myTxt(text: "积分明细", fontWeight: FontWeight.bold, fontSize: 20.sp), // SizedBox(height: 10.h), // Expanded( // child: EasyRefresh.builder( // onRefresh: () async { // pageNum = 0; // await ref // .read(userScoreProvider.notifier) // .fetchUserReadHistory(pageNum); // return IndicatorResult.success; // }, // onLoad: () async { // if (totalNews >= news.total.safeValue) { // return IndicatorResult.noMore; // } else { // pageNum++; // await ref // .read(userReadHistoryProvider.notifier) // .fetchUserReadHistory(pageNum); // return IndicatorResult.success; // } // }, // childBuilder: (context, py) {} // ), // ListView.separated( // padding: EdgeInsets.zero, // separatorBuilder: // (context, index) => // Divider(height: 0.1.h, color: Colors.grey[300]), // itemCount: pointsHistory.length, // itemBuilder: (context, index) { // final item = pointsHistory[index]; // return ListTile( // contentPadding: EdgeInsets.zero, // title: Text(item['type'], style: TextStyle(fontSize: 16)), // subtitle: Text( // item['date'], // style: TextStyle(color: Colors.grey), // ), // trailing: Text( // "${item['isPositive'] ? '+' : ''}${item['points']}积分", // style: TextStyle( // fontSize: 16, // color: item['isPositive'] ? Colors.black : Colors.red, // fontWeight: FontWeight.bold, // ), // ), // ); // }, // ), // ), // ], // ), // );, // ), // ], // ), // ); // } // // // // Widget _buildPointsList() { // // return // // } // }