photo_preview_view.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. import 'package:clean/base/base_page.dart';
  2. import 'package:clean/data/bean/photos_type.dart';
  3. import 'package:clean/module/photo_preview/photo_preview_controller.dart';
  4. import 'package:clean/resource/assets.gen.dart';
  5. import 'package:clean/router/app_pages.dart';
  6. import 'package:clean/utils/toast_util.dart';
  7. import 'package:clean/widget/photo_swipe_card.dart';
  8. import 'package:flutter/Material.dart';
  9. import 'package:flutter/src/widgets/framework.dart';
  10. import 'package:flutter_card_swiper/flutter_card_swiper.dart';
  11. import 'package:flutter_screenutil/flutter_screenutil.dart';
  12. import 'package:get/get.dart';
  13. import 'package:lottie/lottie.dart';
  14. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  15. class PhotoPreviewPage extends BasePage<PhotoPreviewController> {
  16. PhotoPreviewPage({Key? key}) : super(key: key);
  17. static void start(PhotosType photosType, String currentImageId) {
  18. print(' PhotoPreviewPage start $photosType $currentImageId');
  19. Get.toNamed(RoutePath.photoPreview, arguments: {
  20. "photosType": photosType,
  21. "currentImageId": currentImageId,
  22. });
  23. }
  24. @override
  25. bool immersive() {
  26. // TODO: implement immersive
  27. return true;
  28. }
  29. @override
  30. bool statusBarDarkFont() {
  31. // TODO: implement statusBarDarkFont
  32. return false;
  33. }
  34. @override
  35. Widget buildBody(BuildContext context) {
  36. return Stack(children: [
  37. Container(
  38. child: PopScope(
  39. canPop: false,
  40. onPopInvokedWithResult: (didPop, result) {
  41. if (didPop) {
  42. return;
  43. }
  44. controller.clickBack();
  45. },
  46. child: SafeArea(
  47. child: Container(
  48. child: Obx(() {
  49. if (controller.isSwiperEnd.value ||
  50. controller.listAssetEntity.isEmpty) {
  51. return onSwiperEndCard();
  52. } else {
  53. return Column(
  54. children: [
  55. _titleCard(),
  56. Spacer(),
  57. SizedBox(
  58. width: 314.w,
  59. height: 392.h,
  60. child: CardSwiper(
  61. scale: 0.8,
  62. allowedSwipeDirection: AllowedSwipeDirection.only(
  63. right: true,
  64. left: true,
  65. ),
  66. isLoop: false,
  67. backCardOffset: Offset(0.w, -20.h),
  68. controller: controller.cardSwiperController.value,
  69. cardsCount: controller.listAssetEntity.length,
  70. onSwipe: controller.onSwipe,
  71. onUndo: controller.onSwiperUndo,
  72. numberOfCardsDisplayed:
  73. (controller.listAssetEntity.length == 1) ? 1 : 2,
  74. onEnd: controller.onSwiperEnd,
  75. cardBuilder: (context,
  76. index,
  77. horizontalOffsetPercentage,
  78. verticalOffsetPercentage) {
  79. // print(
  80. // 'index: $index, horizontalOffsetPercentage: $horizontalOffsetPercentage, verticalOffsetPercentage: $verticalOffsetPercentage');
  81. final assetEntity = controller.listAssetEntity[index];
  82. return Stack(
  83. children: [
  84. ClipRRect(
  85. borderRadius: BorderRadius.circular(20.r),
  86. child:
  87. // 判断这个是不是视频
  88. assetEntity.type == AssetType.video
  89. ? Stack(
  90. alignment: Alignment.center,
  91. children: [
  92. AssetEntityImage(
  93. assetEntity,
  94. width: 314.w,
  95. height: 392.h,
  96. fit: BoxFit.cover,
  97. ),
  98. GestureDetector(
  99. // 点击播放视频
  100. onTap: () => controller
  101. .playVideo(assetEntity),
  102. child: Icon(
  103. Icons.play_circle_filled,
  104. size: 50.w,
  105. color: Colors.white
  106. .withValues(alpha: 0.8),
  107. ),
  108. )
  109. ],
  110. )
  111. : AssetEntityImage(
  112. assetEntity,
  113. width: 314.w,
  114. height: 392.h,
  115. fit: BoxFit.cover,
  116. ),
  117. ),
  118. if (horizontalOffsetPercentage != 0)
  119. Positioned(
  120. top: 0,
  121. right: horizontalOffsetPercentage < -10.w
  122. ? 0
  123. : null,
  124. left: horizontalOffsetPercentage > 10.w
  125. ? 0
  126. : null,
  127. child: Container(
  128. child: Column(
  129. children: [
  130. (horizontalOffsetPercentage < -10.w)
  131. ? Assets.images.iconPhotoPreviewDelete
  132. .image(
  133. width: 60.w,
  134. height: 60.w,
  135. )
  136. : (horizontalOffsetPercentage > 10.w)
  137. ? Assets
  138. .images.iconPhotoPreviewKeep
  139. .image(
  140. width: 60.w,
  141. height: 60.w,
  142. )
  143. : SizedBox(),
  144. (horizontalOffsetPercentage < -10.w)
  145. ? Text(
  146. 'Delete ',
  147. style: TextStyle(
  148. color: Colors.white,
  149. fontSize: 24.sp,
  150. fontWeight: FontWeight.w500,
  151. ),
  152. )
  153. : (horizontalOffsetPercentage > 10.w)
  154. ? Text(
  155. 'Keep',
  156. style: TextStyle(
  157. color: Colors.white,
  158. fontSize: 24.sp,
  159. fontWeight: FontWeight.w500,
  160. ),
  161. )
  162. : SizedBox(),
  163. ],
  164. )),
  165. ),
  166. ],
  167. );
  168. },
  169. ),
  170. ),
  171. Spacer(),
  172. bottomButtonCard(),
  173. _bottomBarCard(),
  174. ],
  175. );
  176. }
  177. }),
  178. ),
  179. ),
  180. )),
  181. Obx(() {
  182. if (controller.isSwiperEnd.value ||
  183. controller.listAssetEntity.isEmpty) {
  184. return IgnorePointer(
  185. child: Assets.images.bgPhotoSelectedPreviewFinish.image(
  186. width: 360.w,
  187. ),
  188. );
  189. } else {
  190. return IgnorePointer(
  191. child: Assets.images.bgHome.image(
  192. width: 360.w,
  193. ),
  194. );
  195. }
  196. }),
  197. ]);
  198. }
  199. Widget _titleCard() {
  200. return Container(
  201. alignment: Alignment.centerLeft,
  202. padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
  203. child: Column(
  204. crossAxisAlignment: CrossAxisAlignment.start,
  205. children: [
  206. Row(
  207. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  208. children: [
  209. GestureDetector(
  210. onTap: controller.clickBack,
  211. child: Assets.images.iconBackArrow.image(
  212. width: 28.w,
  213. height: 28.h,
  214. ),
  215. ),
  216. Obx(() => Row(
  217. mainAxisAlignment: MainAxisAlignment.center,
  218. children: [
  219. Text(
  220. '${controller.groupIndex.value + 1}',
  221. textAlign: TextAlign.center,
  222. style: TextStyle(
  223. color: Colors.white,
  224. fontSize: 16.sp,
  225. fontWeight: FontWeight.w700,
  226. ),
  227. ),
  228. Text(
  229. ' / ${controller.listAssetEntity.length}',
  230. textAlign: TextAlign.center,
  231. style: TextStyle(
  232. color: Colors.white.withValues(alpha: 0.6),
  233. fontSize: 16.sp,
  234. fontWeight: FontWeight.w500,
  235. ),
  236. ),
  237. ],
  238. )),
  239. GestureDetector(
  240. onTap: controller.recoverSelectPhoto,
  241. child: Assets.images.iconPreviewRecover.image(
  242. width: 30.w,
  243. height: 30.h,
  244. ),
  245. ),
  246. ],
  247. ),
  248. SizedBox(height: 12.h),
  249. ],
  250. ),
  251. );
  252. }
  253. Widget _bottomBarCard() {
  254. return GestureDetector(
  255. onTap: controller.clickJumpSelected,
  256. child: Container(
  257. width: 360.w,
  258. height: 81.h,
  259. padding: EdgeInsets.symmetric(horizontal: 16.w),
  260. decoration: ShapeDecoration(
  261. color: Color(0xFF23232A),
  262. shape: RoundedRectangleBorder(
  263. side: BorderSide(
  264. width: 1.w, color: Colors.white.withValues(alpha: 0.1)),
  265. borderRadius: BorderRadius.only(
  266. topLeft: Radius.circular(14.r),
  267. topRight: Radius.circular(14.r),
  268. ),
  269. ),
  270. ),
  271. child: Row(
  272. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  273. children: [
  274. Obx(() {
  275. return Text(
  276. '${controller.selectedFileCount.value} files selected (${controller.selectedFilesSizeString} )',
  277. textAlign: TextAlign.center,
  278. style: TextStyle(
  279. color: Colors.white.withValues(alpha: 0.9),
  280. fontSize: 13.sp,
  281. fontWeight: FontWeight.w500,
  282. ),
  283. );
  284. }),
  285. GestureDetector(
  286. onTap: controller.clickDelete,
  287. child: Container(
  288. width: 108.w,
  289. height: 38.h,
  290. decoration: ShapeDecoration(
  291. color: Color(0xFF0279FB),
  292. shape: RoundedRectangleBorder(
  293. borderRadius: BorderRadius.circular(10.r),
  294. ),
  295. ),
  296. child: Row(
  297. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  298. children: [
  299. Text(
  300. 'Delete',
  301. textAlign: TextAlign.center,
  302. style: TextStyle(
  303. color: Colors.white,
  304. fontSize: 16.sp,
  305. fontWeight: FontWeight.w500,
  306. ),
  307. ),
  308. Assets.images.iconDelete.image(
  309. width: 18.w,
  310. height: 18.h,
  311. ),
  312. ],
  313. ),
  314. )),
  315. ],
  316. ),
  317. )
  318. );
  319. }
  320. Widget bottomButtonCard() {
  321. return Container(
  322. margin: EdgeInsets.only(bottom: 54.h),
  323. child: Row(
  324. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  325. children: [
  326. GestureDetector(
  327. onTap: () => controller.clickSelect(),
  328. child: Assets.images.iconPreviewSelect.image(
  329. width: 62.w,
  330. height: 62.h,
  331. ),
  332. ),
  333. GestureDetector(
  334. onTap: () => controller.clickUnselect(),
  335. child: Assets.images.iconPreviewNoSelect.image(
  336. width: 62.w,
  337. height: 62.h,
  338. ),
  339. ),
  340. ],
  341. ),
  342. );
  343. }
  344. Widget onSwiperEndCard() {
  345. return Column(
  346. children: [
  347. Container(
  348. child: Lottie.asset(
  349. Assets.anim.animFireworks,
  350. controller: controller.animationController,
  351. height: 351.h,
  352. repeat: false,
  353. ),
  354. ),
  355. Visibility(
  356. visible: controller.animationIsComplete.value,
  357. child: Center(
  358. child: Column(
  359. crossAxisAlignment: CrossAxisAlignment.center,
  360. mainAxisAlignment: MainAxisAlignment.center,
  361. children: [
  362. Text(
  363. 'Perfect!',
  364. textAlign: TextAlign.center,
  365. style: TextStyle(
  366. color: Colors.white,
  367. fontSize: 32.sp,
  368. fontWeight: FontWeight.w700,
  369. ),
  370. ),
  371. SizedBox(height: 16.h),
  372. SizedBox(
  373. child: Row(
  374. mainAxisAlignment: MainAxisAlignment.center,
  375. children: [
  376. Container(
  377. clipBehavior: Clip.antiAlias,
  378. decoration: BoxDecoration(),
  379. child:
  380. Assets.images.iconPreviewSwiperEndFirework.image(
  381. width: 40.w,
  382. height: 40.w,
  383. ),
  384. ),
  385. SizedBox(width: 4.w),
  386. Text(
  387. 'All Similar and Redundant\nPhotos Cleared',
  388. textAlign: TextAlign.center,
  389. style: TextStyle(
  390. color: Colors.white.withValues(alpha: 0.9),
  391. fontSize: 16.sp,
  392. fontWeight: FontWeight.w400,
  393. ),
  394. ),
  395. SizedBox(width: 4.w),
  396. Container(
  397. clipBehavior: Clip.antiAlias,
  398. decoration: BoxDecoration(),
  399. child:
  400. Assets.images.iconPreviewSwiperEndFirework.image(
  401. width: 40.w,
  402. height: 40.w,
  403. ),
  404. ),
  405. ],
  406. ),
  407. ),
  408. ],
  409. ),
  410. )),
  411. Spacer(
  412. flex: 5,
  413. ),
  414. controller.listAssetEntity.isEmpty ? SizedBox() : _bottomBarCard(),
  415. ],
  416. );
  417. }
  418. }