photo_preview_view.dart 11 KB

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