video_item_widget.dart 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:go_router/go_router.dart';
  6. import 'package:news_app/constant/api_const.dart';
  7. import 'package:news_app/model/video_new_model.dart';
  8. import 'package:news_app/ui/video/video_detail_page.dart';
  9. import 'package:news_app/ui/video/video_recommend_list_page.dart';
  10. import 'package:news_app/util/share_util.dart';
  11. import 'package:news_app/widget/auth_gesture_detector.dart';
  12. import '../../gen/assets.gen.dart';
  13. import '../../util/device_util.dart';
  14. import '../../widget/load_image.dart';
  15. import '../../widget/my_txt.dart';
  16. /// @author: bo.zeng
  17. /// @email: cnhbwds@gmail.com
  18. /// @date: 2025 2025/4/9 16:00
  19. /// @description:
  20. class VideoItemWidget extends ConsumerStatefulWidget {
  21. final VideoNewModel item;
  22. const VideoItemWidget({super.key, required this.item});
  23. @override
  24. ConsumerState<ConsumerStatefulWidget> createState() =>
  25. _TopicDetailPageState();
  26. }
  27. class _TopicDetailPageState extends ConsumerState<VideoItemWidget> {
  28. bool _isWeChatInstalled = false;
  29. Future<void> _checkWeChatInstallation() async {
  30. if (Platform.isAndroid) {
  31. final installed = await isWeChatInstalledOnlyAndroid();
  32. setState(() => _isWeChatInstalled = installed);
  33. } else if (Platform.isIOS) {
  34. final installed = await fluwx.isWeChatInstalled;
  35. setState(() => _isWeChatInstalled = installed);
  36. }
  37. }
  38. @override
  39. void initState() {
  40. // TODO: implement initState
  41. super.initState();
  42. _checkWeChatInstallation();
  43. }
  44. Future<void> shareAction(VideoNewModel data) async {
  45. showModalBottomSheet(
  46. context: context,
  47. builder: (context) => SafeArea(
  48. child: Column(
  49. mainAxisSize: MainAxisSize.min,
  50. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  51. children: [
  52. SizedBox(height: 10.h,),
  53. Container(
  54. width: double.infinity,
  55. height: 80.h,
  56. decoration: BoxDecoration(
  57. borderRadius: BorderRadius.only(topLeft: Radius.circular(10.r),topRight: Radius.circular(10.r)),
  58. color: Colors.white,
  59. ),
  60. child: Row(
  61. crossAxisAlignment: CrossAxisAlignment.center,
  62. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  63. children: [
  64. if (_isWeChatInstalled)
  65. GestureDetector(
  66. onTap: (){
  67. Navigator.pop(context);
  68. shareWeiXinUrl(
  69. title: data.shareDesc ?? "",
  70. url: data.shareUrl ?? "",
  71. );
  72. },
  73. child: Container(
  74. width: 100.w,
  75. height: 80.h,
  76. child: Column(
  77. crossAxisAlignment: CrossAxisAlignment.center,
  78. mainAxisAlignment: MainAxisAlignment.center,
  79. children: [
  80. LoadAssetImage('share_wxhy',width: 40.w,height: 40.h,),
  81. SizedBox(height: 10.h,),
  82. myTxt(
  83. text: "微信好友",
  84. color: Colors.black,
  85. fontSize: 12.sp,
  86. fontWeight: FontWeight.bold,
  87. )
  88. ],
  89. ),
  90. ),
  91. ),
  92. if (_isWeChatInstalled)
  93. GestureDetector(
  94. onTap: (){
  95. Navigator.pop(context);
  96. shareWeiXinPYUrl(
  97. title: data.shareDesc ?? "",
  98. url: data.shareUrl ?? "",
  99. );
  100. },
  101. child: Container(
  102. width: 100.w,
  103. height: 80.h,
  104. child: Column(
  105. mainAxisAlignment: MainAxisAlignment.center,
  106. children: [
  107. LoadAssetImage('share_pyq',width: 40.w,height: 40.h,),
  108. SizedBox(height: 10.h,),
  109. myTxt(
  110. text: "朋友圈",
  111. color: Colors.black,
  112. fontSize: 12.sp,
  113. fontWeight: FontWeight.bold,
  114. )
  115. ],
  116. ),
  117. ),
  118. ),
  119. GestureDetector(
  120. onTap: (){
  121. Navigator.pop(context);
  122. shareUrl(
  123. title: data.shareDesc ?? "",
  124. url: data.shareUrl ?? "",
  125. );
  126. },
  127. child: Container(
  128. width: 100.w,
  129. height: 80.h,
  130. child: Column(
  131. mainAxisAlignment: MainAxisAlignment.center,
  132. children: [
  133. LoadAssetImage('share_xtfx',width: 40.w,height: 40.h,),
  134. SizedBox(height: 10.h,),
  135. myTxt(
  136. text: "系统分享",
  137. color: Colors.black,
  138. fontSize: 12.sp,
  139. fontWeight: FontWeight.bold,
  140. )
  141. ],
  142. ),
  143. ),
  144. ),
  145. ],
  146. ),
  147. ),
  148. ],
  149. ),
  150. ),
  151. );
  152. }
  153. @override
  154. Widget build(BuildContext context) {
  155. return Stack(
  156. alignment: Alignment.centerRight,
  157. children: [
  158. GestureDetector(
  159. onTap: () {
  160. context.push(
  161. "/video/detail",
  162. extra: VideoParam(id: widget.item.contentId ?? ""),
  163. );
  164. },
  165. child: Container(
  166. decoration: BoxDecoration(
  167. image: DecorationImage(
  168. image: NetworkImage(widget.item.coverImage ?? testImageFood),
  169. fit: BoxFit.cover,
  170. ),
  171. ),
  172. alignment: Alignment.center,
  173. child: Image.asset(
  174. Assets.images.playIcon.path,
  175. width: 50.w,
  176. height: 50.w,
  177. ),
  178. ),
  179. ),
  180. Positioned(
  181. right: 10.h,
  182. child: Column(
  183. mainAxisAlignment: MainAxisAlignment.center,
  184. children: [
  185. SizedBox(height: 100.h),
  186. AuthGestureDetector(
  187. onTap: () {
  188. ref
  189. .read(recommendListProvider.notifier)
  190. .fetchVideoLike(
  191. videoId: widget.item.contentId,
  192. current: widget.item.isLiked ?? false,
  193. );
  194. },
  195. child: Icon(
  196. Icons.favorite,
  197. color: widget.item.isLiked == true ? Colors.red : Colors.white,
  198. size: 25.sp,
  199. ),
  200. ),
  201. myTxt(
  202. text: widget.item.likeCount == null ? "" : widget.item.likeCount.toString(),
  203. color: Colors.white,
  204. fontSize: 12.sp,
  205. ),
  206. SizedBox(height: 15.h),
  207. GestureDetector(
  208. onTap: () {
  209. context.push(
  210. "/video/detail",
  211. extra: VideoParam(id: widget.item.contentId ?? ""),
  212. );
  213. },
  214. child: Icon(Icons.message, color: Colors.white, size: 25.sp),
  215. ),
  216. myTxt(
  217. text:
  218. widget.item.commentCount == null
  219. ? "0"
  220. : widget.item.commentCount.toString(),
  221. color: Colors.white,
  222. fontSize: 12.sp,
  223. ),
  224. SizedBox(height: 15.h),
  225. AuthGestureDetector(
  226. onTap: () {
  227. ref
  228. .read(recommendListProvider.notifier)
  229. .fetchVideoFavorite(
  230. videoId: widget.item.contentId,
  231. current: widget.item.isFavorite ?? false,
  232. );
  233. },
  234. child: Icon(
  235. Icons.star,
  236. color: widget.item.isFavorite == true ? Colors.red : Colors.white,
  237. size: 25.sp,
  238. ),
  239. ),
  240. myTxt(
  241. text:
  242. widget.item.favoriteCount == null
  243. ? "0"
  244. : widget.item.favoriteCount.toString(),
  245. color: Colors.white,
  246. fontSize: 12.sp,
  247. ),
  248. SizedBox(height: 15.h),
  249. AuthGestureDetector(
  250. onTap: () {
  251. // shareUrl(title: widget.item.shareDesc ?? "", url: widget.item.shareUrl ?? "");
  252. shareAction(widget.item);
  253. },
  254. child: Icon(
  255. Icons.screen_share,
  256. color: Colors.white,
  257. size: 25.sp,
  258. ),
  259. ),
  260. myTxt(
  261. text:
  262. widget.item.shareCount == null ? "0" : widget.item.shareCount.toString(),
  263. color: Colors.white,
  264. fontSize: 12.sp,
  265. ),
  266. SizedBox(height: 15.h),
  267. ],
  268. ),
  269. ),
  270. ],
  271. );
  272. }
  273. }