| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import '../constant/api_const.dart';
- import '../http/http_util.dart';
- import '../http/model_parser.dart';
- import '../model/topic_item_model.dart';
- import '../util/toast_util.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/20 23:08
- /// @description:
- class TopicDetailProvider extends Notifier<TopicRecordModel> {
- @override
- TopicRecordModel build() {
- return TopicRecordModel();
- }
- Future<void> fetchTopicDetail(String aid) async {
- var jsonData = await HttpUtil().get(
- apiTopicDetail,
- queryParameters: {"aid": aid}, //"665168438702149"
- );
- final response = ModelParser.parseObject<TopicRecordModel>(
- jsonData,
- TopicRecordModel.fromJson,
- );
- state = response;
- }
- Future<void> fetchTopicShare({required String? contentId}) async {
- if (contentId == null || contentId.isEmpty) {
- return;
- }
- await HttpUtil().get(
- apiTopicShare,
- queryParameters: {"contentId": contentId},
- );
- }
- Future<void> reportComment(String type, String resourceId) async {
- final jsonData = await HttpUtil().post(
- apiCommentReport,
- data: {"type": type, "resourceId": resourceId},
- );
- if (jsonData != null) {
- showToast("举报成功");
- }
- }
- Future<void> updateLike() async {
- state = state.copyWith(
- isLiked: state.isLiked == true ? false : true,
- likeNum: state.isLiked == true ? state.likeNum! - 1 : state.likeNum! + 1,
- );
- }
- Future<void> updateFavorite() async {
- state = state.copyWith(isFavorite: state.isFavorite == true ? false : true);
- }
- }
|