| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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<VideoNewModel> {
- @override
- VideoNewModel build() {
- return VideoNewModel();
- }
- Future<void> fetchVideoDetail(String videoId) async {
- final jsonData = await HttpUtil().get(
- apiVideoDetail,
- queryParameters: {"vid": videoId},
- );
- final data = ModelParser.parseObject<VideoNewModel>(
- 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,
- );
- }
- }
- }
|