calendar_selected_preview_view.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import 'package:clean/base/base_controller.dart';
  2. import 'package:clean/base/base_page.dart';
  3. import 'package:clean/module/calendar/selected_preview/calendar_selected_preview_controller.dart';
  4. import 'package:flutter/Material.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:get/get.dart';
  7. import 'package:lottie/lottie.dart';
  8. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  9. import '../../../resource/assets.gen.dart';
  10. import '../../../router/app_pages.dart';
  11. import '../../people_photo/photo_group.dart';
  12. class CalendarSelectedPreviewPage
  13. extends BasePage<CalendarSelectedPreviewController> {
  14. const CalendarSelectedPreviewPage({Key? key}) : super(key: key);
  15. static void start(PhotoGroup photoGroup) {
  16. Get.toNamed(RoutePath.calendarSelectedPreview,
  17. arguments: {"photoGroup": photoGroup});
  18. }
  19. @override
  20. bool statusBarDarkFont() {
  21. return false;
  22. }
  23. @override
  24. bool immersive() {
  25. return true;
  26. }
  27. @override
  28. Widget buildBody(BuildContext context) {
  29. return Stack(children: [
  30. PopScope(
  31. canPop: false,
  32. onPopInvokedWithResult: (didPop, result) {
  33. if (didPop) {
  34. return;
  35. }
  36. controller.clickBack();
  37. },
  38. child: Container(
  39. child: SafeArea(
  40. child: Obx(() {
  41. if (controller.photoGroup.value.images.isEmpty) {
  42. return _noNoPicturesCard();
  43. } else if (controller.isKeepAll.value) {
  44. return _finishCleanCard();
  45. }
  46. return Column(
  47. children: [
  48. _titleCard(),
  49. Flexible(
  50. child: Obx(() {
  51. return SizedBox(
  52. child: GridView.builder(
  53. padding: EdgeInsets.symmetric(horizontal: 16.w),
  54. scrollDirection: Axis.vertical,
  55. // 设置为垂直方向滚动
  56. physics: BouncingScrollPhysics(),
  57. gridDelegate:
  58. SliverGridDelegateWithFixedCrossAxisCount(
  59. crossAxisCount: 3, // 每行显示 2 个元素
  60. mainAxisSpacing: 8.w, // 垂直间距
  61. crossAxisSpacing: 8.h, // 水平间距
  62. ),
  63. itemCount:
  64. controller.photoGroup.value.images.length,
  65. itemBuilder: _buildPhotoItem(
  66. controller.photoGroup.value.images)),
  67. );
  68. }),
  69. ),
  70. Obx(() {
  71. if (controller.photoGroup.value.images.isNotEmpty) {
  72. return _bottomBarCard();
  73. } else {
  74. return SizedBox();
  75. }
  76. }),
  77. SizedBox(height: 8.h),
  78. ],
  79. );
  80. }),
  81. ),
  82. )),
  83. Obx(() {
  84. if (controller.isKeepAll.value) {
  85. return IgnorePointer(
  86. child: Assets.images.bgPhotoSelectedPreviewFinish.image(
  87. width: 360.w,
  88. ),
  89. );
  90. } else {
  91. return IgnorePointer(
  92. child: Assets.images.bgHome.image(
  93. width: 360.w,
  94. ),
  95. );
  96. }
  97. }),
  98. ]);
  99. }
  100. Widget _titleCard() {
  101. return Container(
  102. alignment: Alignment.centerLeft,
  103. padding:
  104. EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w, bottom: 20.h),
  105. child: Column(
  106. crossAxisAlignment: CrossAxisAlignment.start,
  107. children: [
  108. Obx(() {
  109. return Row(
  110. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  111. children: [
  112. GestureDetector(
  113. onTap: () => controller.clickBack(),
  114. child: Assets.images.iconBackArrow.image(
  115. width: 28.w,
  116. height: 28.h,
  117. ),
  118. ),
  119. // 如果photoGroup数据为空,不显示全选按钮
  120. controller.photoGroup.value.images.isEmpty
  121. ? Container()
  122. : GestureDetector(
  123. onTap: () => controller.toggleGroupSelection(
  124. controller.photoGroup.value.images),
  125. child: Obx(() => Text(
  126. controller.photoGroup.value.isSelected.value
  127. ? 'Deselect All'
  128. : 'Select All',
  129. style: TextStyle(
  130. color: Colors.white.withValues(alpha: 0.7),
  131. fontSize: 14.sp,
  132. fontWeight: FontWeight.w400,
  133. ),
  134. )),
  135. ),
  136. ],
  137. );
  138. }),
  139. ],
  140. ),
  141. );
  142. }
  143. Widget _bottomBarCard() {
  144. return GestureDetector(
  145. onTap: () {
  146. controller.clickDelete();
  147. },
  148. child: Container(
  149. width: 328.w,
  150. height: 48.h,
  151. decoration: ShapeDecoration(
  152. color: Color(0xFF0279FB),
  153. shape: RoundedRectangleBorder(
  154. borderRadius: BorderRadius.circular(10.r),
  155. ),
  156. ),
  157. padding: EdgeInsets.symmetric(horizontal: 16.w),
  158. child: Row(
  159. mainAxisAlignment: MainAxisAlignment.center,
  160. children: [
  161. Assets.images.iconDelete.image(
  162. width: 18.w,
  163. height: 18.h,
  164. ),
  165. SizedBox(width: 5.w),
  166. Obx(() {
  167. if (controller.photoGroup.value.selectedPhotosIds.isNotEmpty) {
  168. return Text(
  169. 'delete ${controller.selectedFilesSizeString}',
  170. textAlign: TextAlign.center,
  171. style: TextStyle(
  172. color: Colors.white,
  173. fontSize: 16.sp,
  174. fontWeight: FontWeight.w500,
  175. ),
  176. );
  177. } else {
  178. return Text(
  179. 'Keep All',
  180. textAlign: TextAlign.center,
  181. style: TextStyle(
  182. color: Colors.white,
  183. fontSize: 16.sp,
  184. fontWeight: FontWeight.w500,
  185. ),
  186. );
  187. }
  188. }),
  189. ],
  190. ),
  191. ));
  192. }
  193. Widget Function(BuildContext, int) _buildPhotoItem(
  194. List<AssetEntity> images) =>
  195. (context, index) {
  196. return GestureDetector(
  197. onTap: () => controller.clickImage(index),
  198. child: Obx(() {
  199. final photoId = controller.photoGroup.value.images[index].id;
  200. final isSelected = controller.photoGroup.value.selectedPhotosIds.contains(photoId);
  201. return Stack(
  202. children: [
  203. Container(
  204. width: 104.w,
  205. height: 104.w,
  206. decoration: ShapeDecoration(
  207. color: Colors.white.withValues(alpha: 0.12),
  208. shape: RoundedRectangleBorder(
  209. borderRadius: BorderRadius.circular(9.27.sp),
  210. ),
  211. image: DecorationImage(
  212. image: AssetEntityImageProvider(
  213. controller.photoGroup.value.images[index],
  214. thumbnailSize: const ThumbnailSize.square(300),
  215. isOriginal: false,
  216. ),
  217. fit: BoxFit.cover,
  218. ),
  219. ),
  220. ),
  221. Positioned(
  222. right: 8.w,
  223. bottom: 8.h,
  224. child: GestureDetector(
  225. onTap: () => controller.toggleImageSelection(index),
  226. child: Container(
  227. child: isSelected
  228. ? Center(
  229. child: Assets.images.iconSelected.image(
  230. width: 20.w,
  231. height: 20.h,
  232. ),
  233. )
  234. : Center(
  235. child: Assets.images.iconUnselected.image(
  236. width: 20.w,
  237. height: 20.h,
  238. )),
  239. )),
  240. ),
  241. ],
  242. );
  243. }),
  244. );
  245. };
  246. Widget _noNoPicturesCard() {
  247. return Column(
  248. mainAxisAlignment: MainAxisAlignment.start,
  249. children: [
  250. _titleCard(),
  251. SizedBox(height: 170.h),
  252. Column(
  253. mainAxisAlignment: MainAxisAlignment.center,
  254. crossAxisAlignment: CrossAxisAlignment.center,
  255. children: [
  256. Container(
  257. width: 70.w,
  258. height: 70.h,
  259. clipBehavior: Clip.antiAlias,
  260. decoration: BoxDecoration(),
  261. child: Assets.images.iconNoPictures.image(),
  262. ),
  263. SizedBox(height: 22.h),
  264. Text(
  265. 'No pictures found',
  266. textAlign: TextAlign.center,
  267. style: TextStyle(
  268. color: Colors.white,
  269. fontSize: 20.sp,
  270. fontWeight: FontWeight.w700,
  271. ),
  272. ),
  273. SizedBox(height: 12.h),
  274. Text(
  275. 'No pictures available at the moment',
  276. textAlign: TextAlign.center,
  277. style: TextStyle(
  278. color: Colors.white.withValues(alpha: 0.6),
  279. fontSize: 14.sp,
  280. fontWeight: FontWeight.w400,
  281. ),
  282. ),
  283. ],
  284. ),
  285. ],
  286. );
  287. }
  288. Widget _finishCleanCard() {
  289. return Container(
  290. width: 360.w,
  291. child: Column(
  292. mainAxisAlignment: MainAxisAlignment.start,
  293. children: [
  294. Spacer(
  295. flex: 3,
  296. ),
  297. Text(
  298. 'Great!',
  299. textAlign: TextAlign.center,
  300. style: TextStyle(
  301. color: Colors.white,
  302. fontSize: 32.sp,
  303. fontWeight: FontWeight.w700,
  304. ),
  305. ),
  306. SizedBox(height: 14.h),
  307. Text(
  308. "You've completed 1 photo review",
  309. textAlign: TextAlign.center,
  310. style: TextStyle(
  311. color: Colors.white.withValues(alpha: 0.8),
  312. fontSize: 16.sp,
  313. fontWeight: FontWeight.w400,
  314. ),
  315. ),
  316. SizedBox(height: 47.h),
  317. // Assets.images.iconPhotoSelectedPreviewFireworks.image(
  318. // width: 158.w,
  319. // height: 158.h,
  320. // ),
  321. SizedBox(
  322. child: Lottie.asset(
  323. Assets.anim.animPhotoSelectedPreviewFireworks,
  324. width: 158.w,
  325. height: 158.w,
  326. repeat: false,
  327. )),
  328. Spacer(
  329. flex: 5,
  330. ),
  331. ],
  332. ),
  333. );
  334. }
  335. }