| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import 'package:easy_refresh/easy_refresh.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:news_app/constant/size_res.dart';
- import 'package:news_app/extension/base.dart';
- import 'package:news_app/provider/user_favorite_provider.dart';
- import 'package:news_app/widget/empty_1_widget.dart';
- import 'package:news_app/widget/my_txt.dart';
- import '../../constant/color_res.dart';
- import '../../model/activity_model.dart';
- import '../../provider/user_activity_provider.dart';
- import '../activity/activity_card_widget.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/9 16:00
- /// @description:
- final userActivityProvider =
- NotifierProvider<UserActivityProvider, UserActivity>(
- () => UserActivityProvider(),
- );
- class UserActivityPage extends ConsumerWidget {
- const UserActivityPage({super.key});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- return DefaultTabController(
- length: 2,
- child: Scaffold(
- appBar: AppBar(
- title: myTxt(
- text: "我的活动",
- fontSize: 18.sp,
- fontWeight: FontWeight.bold,
- ),
- // 移除阴影
- scrolledUnderElevation: 0,
- // 禁用滚动时的阴影变化
- backgroundColor: Colors.white,
- centerTitle: true,
- bottom: TabBar(
- tabAlignment: TabAlignment.center,
- isScrollable: false,
- indicatorColor: color2877FF,
- dividerHeight: 0,
- labelColor: color2877FF,
- // 选中标签颜色
- unselectedLabelColor: color7788A0,
- labelStyle: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.bold),
- unselectedLabelStyle: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.bold,
- ),
- tabs: [Tab(text: "报名通过"), Tab(text: "报名未通过")],
- ),
- ),
- body: TabBarView(
- children: [
- _UserActivityListWidget(type: 1),
- _UserActivityListWidget(type: 2),
- ],
- ),
- ),
- );
- }
- }
- class _UserActivityListWidget extends ConsumerStatefulWidget {
- final int type;
- const _UserActivityListWidget({required this.type});
- @override
- ConsumerState<ConsumerStatefulWidget> createState() {
- return _UserActivityListWidgetState();
- }
- }
- class _UserActivityListWidgetState
- extends ConsumerState<_UserActivityListWidget>
- with AutomaticKeepAliveClientMixin {
- int pageNum = 0;
- int currentTotal = 0;
- @override
- void initState() {
- super.initState();
- ref
- .read(userActivityProvider.notifier)
- .fetchUserActivity(type: widget.type, pageNum: pageNum);
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- var activity = ref.watch(userActivityProvider);
- ref.listen(userActivityProvider, (pre, next) {
- currentTotal = next.rows?.length ?? 0;
- });
- return activity.rows?.isEmpty == true
- ? Empty1widget()
- : EasyRefresh.builder(
- onRefresh: () async {
- pageNum = 0;
- await ref
- .read(userActivityProvider.notifier)
- .fetchUserActivity(type: widget.type, pageNum: pageNum);
- return IndicatorResult.success;
- },
- onLoad: () async {
- if (currentTotal >= activity.total.safeValue) {
- return IndicatorResult.noMore;
- } else {
- pageNum++;
- await ref
- .read(userActivityProvider.notifier)
- .fetchUserActivity(type: widget.type, pageNum: pageNum);
- return IndicatorResult.success;
- }
- },
- childBuilder: (context, py) {
- return ListView.separated(
- physics: py,
- separatorBuilder: (context, index) {
- return SizedBox(height: 10.h);
- },
- padding: EdgeInsets.symmetric(
- horizontal: horizontalPadding,
- vertical: horizontalPadding,
- ),
- itemCount: activity.rows?.length ?? 0,
- itemBuilder: (context, index) {
- return ActivityCardWidget(
- cellData: activity.rows?[index] ?? ActivityModelRecord(),
- );
- },
- );
- },
- );
- }
- @override
- bool get wantKeepAlive => true;
- }
|