similar_photo_view.dart 18 KB

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