import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:news_app/constant/api_const.dart'; import 'package:news_app/model/video_new_model.dart'; import '../http/http_util.dart'; import '../http/model_parser.dart'; /// @author: bo.zeng /// @email: cnhbwds@gmail.com /// @date: 2025 2025/4/16 20:20 /// @description: class VideoDetailProvider extends Notifier { @override VideoNewModel build() { return VideoNewModel(); } Future fetchVideoDetail(String videoId) async { final jsonData = await HttpUtil().get( apiVideoDetail, queryParameters: {"vid": videoId}, ); final data = ModelParser.parseObject( jsonData, VideoNewModel.fromJson, ); state = data; } void likeVideo(bool current) { if (current) { state = state.copyWith(likeCount: state.likeCount! - 1, isLiked: false); } else { state = state.copyWith(likeCount: state.likeCount! + 1, isLiked: true); } } void favoriteVideo(bool current) { if (current) { state = state.copyWith( favoriteCount: state.favoriteCount! - 1, isFavorite: false, ); } else { state = state.copyWith( favoriteCount: state.favoriteCount! + 1, isFavorite: true, ); } } }