calendar_preview_view.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. import 'package:clean/base/base_page.dart';
  2. import 'package:clean/module/calendar/preview/calendar_preview_controller.dart';
  3. import 'package:flutter/Material.dart';
  4. import 'package:flutter/src/widgets/framework.dart';
  5. import 'package:flutter_card_swiper/flutter_card_swiper.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:get/get.dart';
  8. import 'package:lottie/lottie.dart';
  9. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  10. import '../../../resource/assets.gen.dart';
  11. import '../../../router/app_pages.dart';
  12. import '../../../utils/styles.dart';
  13. import '../../people_photo/photo_group.dart';
  14. import 'package:video_player/video_player.dart';
  15. class CalendarPreviewPage extends BasePage<CalendarPreviewController> {
  16. const CalendarPreviewPage({Key? key}) : super(key: key);
  17. static void start(
  18. {required PhotoGroup photoGroup, required String currentImageId}) {
  19. Get.toNamed(RoutePath.calendarPreview, arguments: {
  20. "photoGroup": photoGroup,
  21. "currentImageId": currentImageId,
  22. });
  23. }
  24. @override
  25. bool statusBarDarkFont() {
  26. return false;
  27. }
  28. @override
  29. bool immersive() {
  30. return true;
  31. }
  32. @override
  33. Widget buildBody(BuildContext context) {
  34. return Stack(children: [
  35. PopScope(
  36. canPop: false,
  37. onPopInvokedWithResult: (didPop, result) {
  38. if (didPop) {
  39. return;
  40. }
  41. controller.clickBack();
  42. },
  43. child: SafeArea(
  44. child: Obx(() {
  45. if (controller.isSwiperEnd.value ||
  46. controller.photoGroup.value.images.isEmpty) {
  47. return onSwiperEndCard();
  48. } else {
  49. return Column(
  50. children: [
  51. _titleCard(),
  52. Spacer(),
  53. SizedBox(
  54. width: 314.w,
  55. height: 392.h,
  56. child: CardSwiper(
  57. scale: 0.8,
  58. allowedSwipeDirection: AllowedSwipeDirection.only(
  59. right: true,
  60. left: true,
  61. ),
  62. isLoop: false,
  63. backCardOffset: Offset(0.w, -20.h),
  64. controller: controller.cardSwiperController,
  65. cardsCount: controller.photoGroup.value.images.length,
  66. onSwipe: controller.onSwipe,
  67. onUndo: controller.onSwiperUndo,
  68. numberOfCardsDisplayed:
  69. (controller.photoGroup.value.images.length == 1)
  70. ? 1
  71. : 1,
  72. onEnd: controller.onSwiperEnd,
  73. cardBuilder: (context, index, horizontalOffsetPercentage,
  74. verticalOffsetPercentage) {
  75. final assetEntity =
  76. controller.photoGroup.value.images[index];
  77. return Stack(
  78. children: [
  79. ClipRRect(
  80. borderRadius: BorderRadius.circular(20.r),
  81. child:
  82. // 判断这个是不是视频
  83. assetEntity.type == AssetType.video
  84. ? Stack(
  85. alignment: Alignment.center,
  86. children: [
  87. AssetEntityImage(
  88. assetEntity,
  89. width: 314.w,
  90. height: 392.h,
  91. fit: BoxFit.cover,
  92. ),
  93. GestureDetector(
  94. // 点击播放视频
  95. onTap: () => controller
  96. .playVideo(assetEntity),
  97. child: Icon(
  98. Icons.play_circle_filled,
  99. size: 50.w,
  100. color: Colors.white
  101. .withValues(alpha: 0.8),
  102. ),
  103. )
  104. ],
  105. )
  106. : AssetEntityImage(
  107. assetEntity,
  108. width: 314.w,
  109. height: 392.h,
  110. fit: BoxFit.cover,
  111. isOriginal: true,
  112. // errorBuilder:
  113. // (context, error, stackTrace) {
  114. // debugPrint(
  115. // 'AssetEntityImage error $error');
  116. // return Container();
  117. // },
  118. frameBuilder: Styles.animFrameBuilder(),
  119. )),
  120. if (horizontalOffsetPercentage != 0)
  121. Positioned(
  122. top: 0,
  123. right: horizontalOffsetPercentage < -10.w
  124. ? 0
  125. : null,
  126. left: horizontalOffsetPercentage > 10.w
  127. ? 0
  128. : null,
  129. child: Container(
  130. child: Column(
  131. children: [
  132. (horizontalOffsetPercentage < -10.w)
  133. ? Assets.images.iconPhotoPreviewDelete
  134. .image(
  135. width: 60.w,
  136. height: 60.w,
  137. )
  138. : (horizontalOffsetPercentage > 10.w)
  139. ? Assets.images.iconPhotoPreviewKeep
  140. .image(
  141. width: 60.w,
  142. height: 60.w,
  143. )
  144. : SizedBox(),
  145. (horizontalOffsetPercentage < -10.w)
  146. ? Text(
  147. 'Delete ',
  148. style: TextStyle(
  149. color: Colors.white,
  150. fontSize: 24.sp,
  151. fontWeight: FontWeight.w500,
  152. ),
  153. )
  154. : (horizontalOffsetPercentage > 10.w)
  155. ? Text(
  156. 'Keep',
  157. style: TextStyle(
  158. color: Colors.white,
  159. fontSize: 24.sp,
  160. fontWeight: FontWeight.w500,
  161. ),
  162. )
  163. : SizedBox(),
  164. ],
  165. )),
  166. ),
  167. ],
  168. );
  169. },
  170. ),
  171. ),
  172. Spacer(),
  173. bottomButtonCard(),
  174. _bottomBarCard(),
  175. ],
  176. );
  177. }
  178. }),
  179. ),
  180. ),
  181. Obx(() {
  182. if (controller.isSwiperEnd.value ||
  183. controller.photoGroup.value.images.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.photoGroup.value.images.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.photoGroup.value.selectedPhotosIds.length} 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. Widget bottomButtonCard() {
  320. return Container(
  321. margin: EdgeInsets.only(bottom: 54.h),
  322. child: Row(
  323. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  324. children: [
  325. GestureDetector(
  326. onTap: () => controller.clickSelect(),
  327. child: Assets.images.iconPreviewSelect.image(
  328. width: 62.w,
  329. height: 62.h,
  330. ),
  331. ),
  332. GestureDetector(
  333. onTap: () => controller.clickUnselect(),
  334. child: Assets.images.iconPreviewNoSelect.image(
  335. width: 62.w,
  336. height: 62.h,
  337. ),
  338. ),
  339. ],
  340. ),
  341. );
  342. }
  343. Widget onSwiperEndCard() {
  344. return Column(
  345. children: [
  346. Container(
  347. child: Lottie.asset(
  348. Assets.anim.animFireworks,
  349. controller: controller.animationController,
  350. height: 351.h,
  351. repeat: false,
  352. ),
  353. ),
  354. Visibility(
  355. visible: controller.animationIsComplete.value,
  356. child: Center(
  357. child: Column(
  358. crossAxisAlignment: CrossAxisAlignment.center,
  359. mainAxisAlignment: MainAxisAlignment.center,
  360. children: [
  361. Text(
  362. 'Perfect!',
  363. textAlign: TextAlign.center,
  364. style: TextStyle(
  365. color: Colors.white,
  366. fontSize: 32.sp,
  367. fontWeight: FontWeight.w700,
  368. ),
  369. ),
  370. SizedBox(height: 16.h),
  371. SizedBox(
  372. child: Row(
  373. mainAxisAlignment: MainAxisAlignment.center,
  374. children: [
  375. Container(
  376. clipBehavior: Clip.antiAlias,
  377. decoration: BoxDecoration(),
  378. child:
  379. Assets.images.iconPreviewSwiperEndFirework.image(
  380. width: 40.w,
  381. height: 40.w,
  382. ),
  383. ),
  384. SizedBox(width: 4.w),
  385. Text(
  386. 'All Similar and Redundant\nPhotos Cleared',
  387. textAlign: TextAlign.center,
  388. style: TextStyle(
  389. color: Colors.white.withValues(alpha: 0.9),
  390. fontSize: 16.sp,
  391. fontWeight: FontWeight.w400,
  392. ),
  393. ),
  394. SizedBox(width: 4.w),
  395. Container(
  396. clipBehavior: Clip.antiAlias,
  397. decoration: BoxDecoration(),
  398. child:
  399. Assets.images.iconPreviewSwiperEndFirework.image(
  400. width: 40.w,
  401. height: 40.w,
  402. ),
  403. ),
  404. ],
  405. ),
  406. ),
  407. ],
  408. ),
  409. )),
  410. Spacer(
  411. flex: 5,
  412. ),
  413. controller.photoGroup.value.images.isEmpty
  414. ? SizedBox()
  415. : _bottomBarCard(),
  416. ],
  417. );
  418. }
  419. }