similar_photo_view.dart 16 KB

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