similar_photo_view.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. import 'dart:io';
  2. import 'dart:math';
  3. import 'package:clean/base/base_page.dart';
  4. import 'package:clean/data/bean/photos_type.dart';
  5. import 'package:clean/module/similar_photo/similar_photo_controller.dart';
  6. import 'package:clean/resource/assets.gen.dart';
  7. import 'package:clean/router/app_pages.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter_screenutil/flutter_screenutil.dart';
  10. import 'package:get/get.dart';
  11. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  12. import '../../utils/styles.dart';
  13. class SimilarPhotoPage extends BasePage<SimilarPhotoController> {
  14. const SimilarPhotoPage({super.key});
  15. static void start() {
  16. Get.toNamed(RoutePath.similarPhoto);
  17. }
  18. @override
  19. bool statusBarDarkFont() => false;
  20. @override
  21. bool immersive() => true;
  22. @override
  23. Widget buildBody(BuildContext context) {
  24. return Stack(children: [
  25. Container(
  26. child: SafeArea(child: Obx(() {
  27. if (controller.photoGroups.isEmpty) {
  28. return _noNoPicturesCard();
  29. }
  30. return Column(
  31. children: [
  32. _titleCard(),
  33. Flexible(
  34. child: Obx(() {
  35. return ListView(
  36. padding: EdgeInsets.symmetric(horizontal: 16.w),
  37. children: [
  38. ...controller.photoGroups.map((group) => Column(
  39. children: [
  40. _buildPhotoGroup(
  41. imagesList: group.images,
  42. imageCount: group.images.length,
  43. ),
  44. SizedBox(height: 15.h),
  45. ],
  46. ))
  47. ],
  48. );
  49. }),
  50. ),
  51. _bottomBarCard(),
  52. ],
  53. );
  54. })),
  55. ),
  56. IgnorePointer(
  57. child: Assets.images.bgHome.image(
  58. width: 360.w,
  59. ),
  60. ),
  61. ]);
  62. }
  63. Widget _titleCard() {
  64. return Container(
  65. alignment: Alignment.centerLeft,
  66. padding: EdgeInsets.only(left: 16.w, top: 14.h),
  67. child: Column(
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. children: [
  70. GestureDetector(
  71. onTap: () => Get.back(),
  72. child: Assets.images.iconBackArrow.image(
  73. width: 28.w,
  74. height: 28.h,
  75. ),
  76. ),
  77. (controller.photoGroups.isEmpty)
  78. ? SizedBox()
  79. : Container(
  80. child: Column(
  81. children: [
  82. SizedBox(height: 12.h),
  83. Text(
  84. 'Similar Photos',
  85. style: TextStyle(
  86. color: Colors.white,
  87. fontSize: 24.sp,
  88. fontWeight: FontWeight.w700,
  89. ),
  90. ),
  91. SizedBox(height: 20.h),
  92. ],
  93. ),
  94. )
  95. ],
  96. ),
  97. );
  98. }
  99. Widget _bottomBarCard() {
  100. return GestureDetector(
  101. onTap: controller.clickJumpSelect,
  102. child: Container(
  103. width: 360.w,
  104. height: 81.h,
  105. padding: EdgeInsets.symmetric(horizontal: 16.w),
  106. decoration: ShapeDecoration(
  107. color: Color(0xFF23232A),
  108. shape: RoundedRectangleBorder(
  109. side:
  110. BorderSide(width: 1.w, color: Colors.white.withOpacity(0.1)),
  111. borderRadius: BorderRadius.only(
  112. topLeft: Radius.circular(14.r),
  113. topRight: Radius.circular(14.r),
  114. ),
  115. ),
  116. ),
  117. child: Row(
  118. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  119. children: [
  120. Obx(() {
  121. return Text(
  122. '${controller.selectedFileCount.value} files selected (${controller.selectedFilesSizeString})',
  123. textAlign: TextAlign.center,
  124. style: TextStyle(
  125. color: Colors.white.withValues(alpha: 0.9),
  126. fontSize: 13.sp,
  127. fontWeight: FontWeight.w500,
  128. ),
  129. );
  130. }),
  131. GestureDetector(
  132. onTap: () => controller.clickDelete(),
  133. child: Container(
  134. width: 108.w,
  135. height: 38.h,
  136. decoration: ShapeDecoration(
  137. color: Color(0xFF0279FB),
  138. shape: RoundedRectangleBorder(
  139. borderRadius: BorderRadius.circular(10.r),
  140. ),
  141. ),
  142. child: Row(
  143. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  144. children: [
  145. Text(
  146. 'Delete',
  147. textAlign: TextAlign.center,
  148. style: TextStyle(
  149. color: Colors.white,
  150. fontSize: 16.sp,
  151. fontWeight: FontWeight.w500,
  152. ),
  153. ),
  154. Assets.images.iconDelete.image(
  155. width: 18.w,
  156. height: 18.h,
  157. ),
  158. ],
  159. ),
  160. ),
  161. )
  162. ],
  163. ),
  164. ));
  165. }
  166. Widget _buildPhotoGroup({
  167. required List<AssetEntity> imagesList,
  168. required int imageCount,
  169. }) {
  170. return Container(
  171. padding: EdgeInsets.symmetric(horizontal: 12.w),
  172. margin: EdgeInsets.only(top: 14.h),
  173. width: 328.w,
  174. height: 258.h,
  175. decoration: ShapeDecoration(
  176. color: Colors.white.withValues(alpha: 0.12),
  177. shape: RoundedRectangleBorder(
  178. borderRadius: BorderRadius.circular(14.sp),
  179. ),
  180. ),
  181. child: Column(
  182. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  183. children: [
  184. Row(
  185. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  186. children: [
  187. Row(
  188. children: [
  189. Text(
  190. "photos $imageCount",
  191. textAlign: TextAlign.center,
  192. style: TextStyle(
  193. color: Colors.white,
  194. fontSize: 14.sp,
  195. fontWeight: FontWeight.w500,
  196. ),
  197. ),
  198. ],
  199. ),
  200. GestureDetector(
  201. onTap: () => controller.toggleGroupSelection(imagesList),
  202. child: Obx(() => Text(
  203. controller.photoGroups
  204. .firstWhere((g) =>
  205. g.images.toSet().containsAll(imagesList))
  206. .isSelected
  207. .value
  208. ? 'Deselect All'
  209. : 'Select All',
  210. style: TextStyle(
  211. color: Colors.white.withValues(alpha: 0.7),
  212. fontSize: 14.sp,
  213. fontWeight: FontWeight.w400,
  214. ),
  215. )),
  216. ),
  217. ],
  218. ),
  219. SizedBox(
  220. height: 148.h,
  221. child: ListView(
  222. scrollDirection: Axis.horizontal,
  223. physics: BouncingScrollPhysics(),
  224. children: [
  225. // 第一张大图
  226. if (imageCount > 0)
  227. GestureDetector(
  228. onTap: () => controller.clickImage(
  229. imagesList, 0, PhotosType.similarPhotos),
  230. child: SizedBox(
  231. width: 148.w,
  232. height: 148.h,
  233. child: Obx(() {
  234. final group = controller.photoGroups.firstWhere(
  235. (g) => g.images.toSet().containsAll(imagesList));
  236. return Stack(
  237. children: [
  238. Container(
  239. decoration: ShapeDecoration(
  240. color: Colors.white.withValues(alpha: 0.12),
  241. shape: RoundedRectangleBorder(
  242. borderRadius: BorderRadius.circular(8.r),
  243. ),
  244. ),
  245. child: ClipRRect(
  246. borderRadius: BorderRadius.circular(8.r),
  247. child: AssetEntityImage(
  248. width: 148.w,
  249. height: 148.h,
  250. group.images[0],
  251. fit: BoxFit.cover,
  252. thumbnailSize:
  253. const ThumbnailSize.square(300),
  254. isOriginal: false,
  255. frameBuilder: Styles.customFrameBuilder(
  256. width: 120.w,
  257. height: 120.w,
  258. ),
  259. )),
  260. ),
  261. Positioned(
  262. left: 8.w,
  263. top: 8.h,
  264. child: Container(
  265. width: 108.w,
  266. height: 26.h,
  267. padding: EdgeInsets.symmetric(
  268. horizontal: 8.w,
  269. vertical: 4.h,
  270. ),
  271. decoration: ShapeDecoration(
  272. color: Colors.black.withValues(alpha: 0.74),
  273. shape: RoundedRectangleBorder(
  274. borderRadius:
  275. BorderRadius.circular(14.21.r),
  276. ),
  277. ),
  278. child: Row(
  279. mainAxisAlignment:
  280. MainAxisAlignment.spaceAround,
  281. children: [
  282. Assets.images.iconSimilarBest.image(
  283. width: 11.37.w,
  284. height: 11.37.h,
  285. ),
  286. Text(
  287. 'Best result',
  288. textAlign: TextAlign.center,
  289. style: TextStyle(
  290. color: Colors.white,
  291. fontSize: 13.sp,
  292. fontWeight: FontWeight.w400,
  293. ),
  294. ),
  295. ],
  296. ),
  297. ),
  298. ),
  299. Positioned(
  300. right: 4.w,
  301. bottom: 4.h,
  302. child: GestureDetector(
  303. onTap: () => controller.toggleImageSelection(
  304. imagesList, 0),
  305. child: Container(
  306. child: group.selectedImages[0]
  307. ? Center(
  308. child:
  309. Assets.images.iconSelected.image(
  310. width: 20.w,
  311. height: 20.h,
  312. ),
  313. )
  314. : Center(
  315. child: Assets.images.iconUnselected
  316. .image(
  317. width: 20.w,
  318. height: 20.h,
  319. ),
  320. ),
  321. ),
  322. ),
  323. ),
  324. ],
  325. );
  326. }),
  327. ),
  328. ),
  329. // 其他图片2x2网格
  330. if (imageCount > 1)
  331. ...List.generate(((imageCount - 1) / 4).ceil(), (gridIndex) {
  332. return Container(
  333. margin: EdgeInsets.only(left: 8.w),
  334. width: 142.w,
  335. child: GridView.count(
  336. physics: NeverScrollableScrollPhysics(),
  337. crossAxisCount: 2,
  338. mainAxisSpacing: 8.h,
  339. crossAxisSpacing: 8.w,
  340. children: List.generate(
  341. min(4, imageCount - 1 - gridIndex * 4),
  342. (index) {
  343. final realIndex = gridIndex * 4 + index + 1;
  344. return GestureDetector(
  345. onTap: () => controller.clickImage(imagesList,
  346. realIndex, PhotosType.similarPhotos),
  347. child: Obx(() {
  348. final group = controller.photoGroups.firstWhere(
  349. (g) => g.images
  350. .toSet()
  351. .containsAll(imagesList));
  352. return Container(
  353. decoration: ShapeDecoration(
  354. color: Colors.white.withValues(alpha: 0.12),
  355. shape: RoundedRectangleBorder(
  356. borderRadius: BorderRadius.circular(8.r),
  357. ),
  358. ),
  359. child: Stack(
  360. children: [
  361. ClipRRect(
  362. borderRadius:
  363. BorderRadius.circular(8.r),
  364. child: AssetEntityImage(
  365. group.images[realIndex],
  366. width: 142.w,
  367. frameBuilder: Styles.customFrameBuilder(
  368. width: 120.w,
  369. height: 120.w,
  370. ),
  371. thumbnailSize:
  372. const ThumbnailSize.square(300),
  373. isOriginal: false,
  374. fit: BoxFit.cover,
  375. ),
  376. ),
  377. Positioned(
  378. right: 4.w,
  379. bottom: 4.h,
  380. child: Obx(() {
  381. final isSelected =
  382. group.selectedImages[realIndex];
  383. return GestureDetector(
  384. onTap: () =>
  385. controller.toggleImageSelection(
  386. imagesList, realIndex),
  387. child: Container(
  388. child: isSelected
  389. ? Center(
  390. child: Assets
  391. .images.iconSelected
  392. .image(
  393. width: 20.w,
  394. height: 20.h,
  395. ),
  396. )
  397. : Center(
  398. child: Assets
  399. .images.iconUnselected
  400. .image(
  401. width: 20.w,
  402. height: 20.h,
  403. ),
  404. ),
  405. ),
  406. );
  407. }),
  408. ),
  409. ],
  410. ),
  411. );
  412. }),
  413. );
  414. },
  415. ),
  416. ),
  417. );
  418. }),
  419. ],
  420. ),
  421. ),
  422. GestureDetector(
  423. onTap: () => controller.clickSingleGroupDelete(imagesList),
  424. child: Container(
  425. width: 162.w,
  426. height: 38.h,
  427. decoration: ShapeDecoration(
  428. color: Color(0xFF0279FB),
  429. shape: RoundedRectangleBorder(
  430. borderRadius: BorderRadius.circular(10.r),
  431. ),
  432. ),
  433. child: Center(
  434. child: Obx(() => Text(
  435. 'Move ${controller.getGroupByImages(imagesList).selectedImages.where((e) => e).length} to trash',
  436. style: TextStyle(
  437. color: Colors.white,
  438. fontSize: 16.sp,
  439. fontWeight: FontWeight.w500,
  440. ),
  441. )),
  442. ),
  443. ),
  444. )
  445. ],
  446. ),
  447. );
  448. }
  449. Widget _noNoPicturesCard() {
  450. return Column(
  451. // mainAxisAlignment: MainAxisAlignment.start,
  452. children: [
  453. _titleCard(),
  454. Spacer(flex: 1),
  455. Column(
  456. crossAxisAlignment: CrossAxisAlignment.center,
  457. children: [
  458. Container(
  459. width: 70.w,
  460. height: 70.h,
  461. clipBehavior: Clip.antiAlias,
  462. decoration: BoxDecoration(),
  463. child: Assets.images.iconNoPictures.image(),
  464. ),
  465. SizedBox(height: 22.h),
  466. Text(
  467. 'No pictures found',
  468. textAlign: TextAlign.center,
  469. style: TextStyle(
  470. color: Colors.white,
  471. fontSize: 20.sp,
  472. fontWeight: FontWeight.w700,
  473. ),
  474. ),
  475. SizedBox(height: 12.h),
  476. Text(
  477. 'No pictures available at the moment',
  478. textAlign: TextAlign.center,
  479. style: TextStyle(
  480. color: Colors.white.withValues(alpha: 0.6),
  481. fontSize: 14.sp,
  482. fontWeight: FontWeight.w400,
  483. ),
  484. ),
  485. ],
  486. ),
  487. Spacer(
  488. flex: 3,
  489. ),
  490. ],
  491. );
  492. }
  493. }