| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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/widget/my_txt.dart';
- import '../../model/news_data_model.dart';
- import '../../provider/user_favorite_provider.dart';
- import '../../provider/user_read_history_provider.dart';
- import '../../widget/empty_1_widget.dart';
- import '../news/news_child_main_page.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/9 16:00
- /// @description:
- class UserReadHistoryPage extends ConsumerStatefulWidget {
- const UserReadHistoryPage({super.key});
- @override
- ConsumerState<UserReadHistoryPage> createState() =>
- _UserReadHistoryPageState();
- }
- final userReadHistoryProvider =
- NotifierProvider<UserReadHistoryProvider, UserNews>(() {
- return UserReadHistoryProvider();
- });
- class _UserReadHistoryPageState extends ConsumerState<UserReadHistoryPage> {
- int pageNum = 0;
- int totalNews = 0;
- @override
- void initState() {
- super.initState();
- ref.read(userReadHistoryProvider.notifier).fetchUserReadHistory(pageNum);
- }
- @override
- Widget build(BuildContext context) {
- final news = ref.watch(userReadHistoryProvider);
- ref.listen(userReadHistoryProvider, (pre, next) {
- totalNews = next.rows?.length ?? 0;
- });
- return Scaffold(
- appBar: AppBar(
- // 移除阴影
- scrolledUnderElevation: 0,
- // 禁用滚动时的阴影变化
- backgroundColor: Colors.white,
- title: myTxt(
- text: "阅读历史",
- fontSize: 18.sp,
- fontWeight: FontWeight.bold,
- ),
- centerTitle: true,
- ),
- body:
- news.rows?.isEmpty == true
- ? Empty1widget()
- : EasyRefresh.builder(
- onRefresh: () async {
- pageNum = 0;
- await ref
- .read(userReadHistoryProvider.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) {
- return ListView.separated(
- physics: py,
- padding: EdgeInsets.symmetric(
- horizontal: horizontalPadding,
- ),
- itemBuilder: (BuildContext context, int index) {
- return buildNewsNewItem(
- news.rows?[index] ?? NewsRecord(),
- context,
- );
- },
- separatorBuilder: (BuildContext context, int index) {
- return SizedBox(height: 5.h,);
- },
- itemCount: news.rows?.length ?? 0,
- );
- },
- ),
- );
- }
- }
|