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