| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:news_app/extension/base.dart';
- import '../constant/api_const.dart';
- import '../http/http_util.dart';
- import '../http/model_parser.dart';
- import '../model/user_score_model.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/22 16:03
- /// @description:
- class UserScoreProvider extends Notifier<UserScoreData> {
- @override
- UserScoreData build() {
- return UserScoreData();
- }
- Future<void> fetchUserScoreList(int pageNum) async {
- final jsonData = await HttpUtil().get(
- apiMemberScoreLevel,
- queryParameters: {"pageSize": 10, "pageNum": pageNum.toString()},
- );
- final response = ModelParser.parseObject<UserScoreData>(
- jsonData,
- UserScoreData.fromJson,
- );
- state.total = response.total;
- if (pageNum == 0) {
- state = response;
- } else {
- //把新的列表添加到旧的列表中
- state = UserScoreData(
- total: response.total,
- rows: [...state.rows ?? [], ...response.rows ?? []],
- );
- }
- }
- /* Future<void> fetchUserScore() async {
- final jsonData = await HttpUtil().get(apiMemberLevel);
- }*/
- }
- class UserScoreData {
- List<UserScoreModelRows?>? rows;
- int? total;
- UserScoreData({this.rows, this.total});
- UserScoreData.fromJson(Map<String, dynamic> json) {
- if (json['rows'] != null) {
- final v = json['rows'];
- final arr0 = <UserScoreModelRows>[];
- v.forEach((v) {
- arr0.add(UserScoreModelRows.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;
- }
- }
|