similar_photo_view.dart 20 KB

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