similar_photo_view.dart 18 KB

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