| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- 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<UserScorePage> createState() => _UserScorePageState();
- }
- final userScoreProvider = NotifierProvider<UserScoreProvider, UserScoreData>(
- () {
- return UserScoreProvider();
- },
- );
- class _UserScorePageState extends ConsumerState<UserScorePage> {
- int pageNum = 0;
- int totalNews = 0;
- @override
- void initState() {
- super.initState();
- setImmersiveStatusBar();
- ref.read(userScoreProvider.notifier).fetchUserScoreList(pageNum);
- eventBus.on<String>().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<SystemUiOverlayStyle>(
- 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<Map<String, dynamic>> 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
- // // }
- // }
|