similar_photo_view.dart 15 KB

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