import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:go_router/go_router.dart'; import 'package:news_app/constant/api_const.dart'; import 'package:news_app/model/video_new_model.dart'; import 'package:news_app/ui/video/video_detail_page.dart'; import 'package:news_app/ui/video/video_recommend_list_page.dart'; import 'package:news_app/util/share_util.dart'; import 'package:news_app/widget/auth_gesture_detector.dart'; import '../../gen/assets.gen.dart'; import '../../util/device_util.dart'; import '../../widget/load_image.dart'; import '../../widget/my_txt.dart'; /// @author: bo.zeng /// @email: cnhbwds@gmail.com /// @date: 2025 2025/4/9 16:00 /// @description: class VideoItemWidget extends ConsumerStatefulWidget { final VideoNewModel item; const VideoItemWidget({super.key, required this.item}); @override ConsumerState createState() => _TopicDetailPageState(); } class _TopicDetailPageState extends ConsumerState { bool _isWeChatInstalled = false; Future _checkWeChatInstallation() async { if (Platform.isAndroid) { final installed = await isWeChatInstalledOnlyAndroid(); setState(() => _isWeChatInstalled = installed); } else if (Platform.isIOS) { final installed = await fluwx.isWeChatInstalled; setState(() => _isWeChatInstalled = installed); } } @override void initState() { // TODO: implement initState super.initState(); _checkWeChatInstallation(); } Future shareAction(VideoNewModel data) async { showModalBottomSheet( context: context, builder: (context) => SafeArea( child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SizedBox(height: 10.h,), Container( width: double.infinity, height: 80.h, decoration: BoxDecoration( borderRadius: BorderRadius.only(topLeft: Radius.circular(10.r),topRight: Radius.circular(10.r)), color: Colors.white, ), child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ if (_isWeChatInstalled) GestureDetector( onTap: (){ Navigator.pop(context); shareWeiXinUrl( title: data.shareDesc ?? "", url: data.shareUrl ?? "", ); }, child: Container( width: 100.w, height: 80.h, child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ LoadAssetImage('share_wxhy',width: 40.w,height: 40.h,), SizedBox(height: 10.h,), myTxt( text: "微信好友", color: Colors.black, fontSize: 12.sp, fontWeight: FontWeight.bold, ) ], ), ), ), if (_isWeChatInstalled) GestureDetector( onTap: (){ Navigator.pop(context); shareWeiXinPYUrl( title: data.shareDesc ?? "", url: data.shareUrl ?? "", ); }, child: Container( width: 100.w, height: 80.h, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ LoadAssetImage('share_pyq',width: 40.w,height: 40.h,), SizedBox(height: 10.h,), myTxt( text: "朋友圈", color: Colors.black, fontSize: 12.sp, fontWeight: FontWeight.bold, ) ], ), ), ), GestureDetector( onTap: (){ Navigator.pop(context); shareUrl( title: data.shareDesc ?? "", url: data.shareUrl ?? "", ); }, child: Container( width: 100.w, height: 80.h, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ LoadAssetImage('share_xtfx',width: 40.w,height: 40.h,), SizedBox(height: 10.h,), myTxt( text: "系统分享", color: Colors.black, fontSize: 12.sp, fontWeight: FontWeight.bold, ) ], ), ), ), ], ), ), ], ), ), ); } @override Widget build(BuildContext context) { return Stack( alignment: Alignment.centerRight, children: [ GestureDetector( onTap: () { context.push( "/video/detail", extra: VideoParam(id: widget.item.contentId ?? ""), ); }, child: Container( decoration: BoxDecoration( image: DecorationImage( image: NetworkImage(widget.item.coverImage ?? testImageFood), fit: BoxFit.cover, ), ), alignment: Alignment.center, child: Image.asset( Assets.images.playIcon.path, width: 50.w, height: 50.w, ), ), ), Positioned( right: 10.h, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox(height: 100.h), AuthGestureDetector( onTap: () { ref .read(recommendListProvider.notifier) .fetchVideoLike( videoId: widget.item.contentId, current: widget.item.isLiked ?? false, ); }, child: Icon( Icons.favorite, color: widget.item.isLiked == true ? Colors.red : Colors.white, size: 25.sp, ), ), myTxt( text: widget.item.likeCount == null ? "" : widget.item.likeCount.toString(), color: Colors.white, fontSize: 12.sp, ), SizedBox(height: 15.h), GestureDetector( onTap: () { context.push( "/video/detail", extra: VideoParam(id: widget.item.contentId ?? ""), ); }, child: Icon(Icons.message, color: Colors.white, size: 25.sp), ), myTxt( text: widget.item.commentCount == null ? "0" : widget.item.commentCount.toString(), color: Colors.white, fontSize: 12.sp, ), SizedBox(height: 15.h), AuthGestureDetector( onTap: () { ref .read(recommendListProvider.notifier) .fetchVideoFavorite( videoId: widget.item.contentId, current: widget.item.isFavorite ?? false, ); }, child: Icon( Icons.star, color: widget.item.isFavorite == true ? Colors.red : Colors.white, size: 25.sp, ), ), myTxt( text: widget.item.favoriteCount == null ? "0" : widget.item.favoriteCount.toString(), color: Colors.white, fontSize: 12.sp, ), SizedBox(height: 15.h), AuthGestureDetector( onTap: () { // shareUrl(title: widget.item.shareDesc ?? "", url: widget.item.shareUrl ?? ""); shareAction(widget.item); }, child: Icon( Icons.screen_share, color: Colors.white, size: 25.sp, ), ), myTxt( text: widget.item.shareCount == null ? "0" : widget.item.shareCount.toString(), color: Colors.white, fontSize: 12.sp, ), SizedBox(height: 15.h), ], ), ), ], ); } }