| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import 'dart:core';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:news_app/constant/api_const.dart';
- import 'package:news_app/http/http_util.dart';
- import 'package:news_app/http/model_parser.dart';
- import '../model/activity_model.dart';
- import '../model/base_response.dart';
- import '../ui/me/user_favorite_page.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/21 10:22
- /// @description:
- class ActivityDetailProvider extends Notifier<ActivityModelRecord> {
- @override
- ActivityModelRecord build() {
- return ActivityModelRecord();
- }
- Future<void> fetchActivityDetail({required String activityId}) async {
- var jsonData = await HttpUtil().get(
- apiActivityDetail,
- queryParameters: {"activityId": activityId},
- );
- final response = ModelParser.parseObject(
- jsonData,
- ActivityModelRecord.fromJson,
- );
- state = response;
- }
- Future<void> fetchRegisterActivity({
- required String activityId,
- required String name,
- required String phone,
- }) async {
- final responseJson = await HttpUtil().post(
- apiActivityRegister,
- data: {"activityId": activityId, "name": name, "phone": phone},
- );
- BaseResponse response = BaseResponse.fromJson(responseJson);
- if (response.code == 200) {
- // 注册成功
- state.registerStatus = "1";
- }
- }
- Future<void> fetchActivityLike({
- required String? contentId,
- required bool current,
- }) async {
- if (contentId == null || contentId.isEmpty) {
- return;
- }
- final jsonData = await HttpUtil().get(
- current ? apiActivityCancelLike : apiActivityLike,
- queryParameters: {"contentId": contentId},
- );
- if (jsonData == true) {
- //修改成功后,把 likeCount+1
- if (current) {
- state = state.copyWith(
- likeCount: (state.likeCount ?? 1) - 1,
- isLiked: false,
- );
- } else {
- state = state.copyWith(
- likeCount: (state.likeCount ?? 0) + 1,
- isLiked: true,
- );
- }
- }
- }
- Future<void> fetchActivityFavorite({
- required String? contentId,
- required bool current,
- }) async {
- if (contentId == null || contentId.isEmpty) {
- return;
- }
- final jsonData = await HttpUtil().get(
- current ? apiActivityCancelFavorite : apiActivityFavorite,
- queryParameters: {"contentId": contentId},
- );
- if (jsonData == true) {
- //修改成功后,把favoriteCount+1
- if (current) {
- state = state.copyWith(
- favoriteCount: (state.favoriteCount ?? 1) - 1,
- isFavorite: false,
- );
- ref
- .read(favoriteActivityProvider.notifier)
- .removeItemByContentId(contentId);
- } else {
- state = state.copyWith(
- favoriteCount: (state.favoriteCount ?? 0) + 1,
- isFavorite: true,
- );
- }
- }
- }
- Future<void> fetchActivityShare({required String? activityId}) async {
- if (activityId == null || activityId.isEmpty) {
- return;
- }
- final jsonData = await HttpUtil().get(
- apiActivityShare,
- queryParameters: {"contentId": activityId},
- );
- if (jsonData == true) {
- //修改成功后,把favoriteCount+1
- state = state.copyWith(shareCount: (state.shareCount ?? 0) + 1);
- }
- }
- }
|