| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:news_app/constant/api_const.dart';
- import 'package:news_app/extension/base.dart';
- import 'package:news_app/model/msg_center_model.dart';
- import '../http/http_util.dart';
- import '../http/model_parser.dart';
- class MsgCenterLikeProvider extends FamilyNotifier<UserMsgLike, String> {
- String _type = "reply"; //reply like
- @override
- UserMsgLike build(String type) {
- _type = type;
- return UserMsgLike();
- }
- Future<void> fetchMsgCenterLike({required int pageNum}) async {
- var jsonData = await HttpUtil().get(
- apiMsgCenter,
- queryParameters: {"type": _type, "pageSize": "10", "pageNum": pageNum},
- );
- final response = ModelParser.parseObject<UserMsgLike>(
- jsonData,
- UserMsgLike.fromJson,
- );
- state.total = response.total;
- if (pageNum == 0) {
- state = response;
- } else {
- //把新的列表添加到旧的列表中
- state = UserMsgLike(
- total: response.total,
- rows: [...state.rows ?? [], ...response.rows ?? []],
- );
- }
- }
- }
- class UserMsgLike {
- List<MsgCenterModelRows?>? rows;
- int? total;
- UserMsgLike({this.rows, this.total});
- UserMsgLike.fromJson(Map<String, dynamic> json) {
- if (json['rows'] != null) {
- final v = json['rows'];
- final arr0 = <MsgCenterModelRows>[];
- v.forEach((v) {
- arr0.add(MsgCenterModelRows.fromJson(v));
- });
- rows = arr0;
- }
- total = json['total']?.toString().convertInt;
- }
- Map<String, dynamic> toJson() {
- final data = <String, dynamic>{};
- if (rows != null) {
- final v = rows;
- final arr0 = [];
- for (var v in v!) {
- arr0.add(v!.toJson());
- }
- data['rows'] = arr0;
- }
- data['total'] = total;
- return data;
- }
- }
|