similar_photo_view.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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.put((SimilarPhotoController()));
  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(
  26. child: Column(
  27. children: [
  28. _titleCard(),
  29. Expanded(
  30. child: Obx(() {
  31. return ListView(
  32. padding: EdgeInsets.symmetric(horizontal: 16.w),
  33. children: [
  34. ...controller.photoGroups.map((group) => Column(
  35. children: [
  36. _buildPhotoGroup(
  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 FutureBuilder<double>(
  108. future: controller.getSelectedFilesSize(),
  109. builder: (context, snapshot) {
  110. if (snapshot.connectionState == ConnectionState.waiting) {
  111. return CircularProgressIndicator();
  112. } else if (snapshot.hasError) {
  113. return Text('Error: ${snapshot.error}');
  114. } else {
  115. return Text(
  116. '${controller.selectedFileCount} files selected (${snapshot.data?.toStringAsFixed(1)} KB)',
  117. textAlign: TextAlign.center,
  118. style: TextStyle(
  119. color: Colors.white.withValues(alpha: 0.9),
  120. fontSize: 13.sp,
  121. fontWeight: FontWeight.w500,
  122. ),
  123. );
  124. }
  125. },
  126. );
  127. }),
  128. Container(
  129. width: 108.w,
  130. height: 38.h,
  131. decoration: ShapeDecoration(
  132. color: Color(0xFF0279FB),
  133. shape: RoundedRectangleBorder(
  134. borderRadius: BorderRadius.circular(10.r),
  135. ),
  136. ),
  137. child: Row(
  138. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  139. children: [
  140. Text(
  141. 'Delete',
  142. textAlign: TextAlign.center,
  143. style: TextStyle(
  144. color: Colors.white,
  145. fontSize: 16.sp,
  146. fontWeight: FontWeight.w500,
  147. ),
  148. ),
  149. Assets.images.iconDelete.image(
  150. width: 18.w,
  151. height: 18.h,
  152. ),
  153. ],
  154. ),
  155. ),
  156. ],
  157. ),
  158. );
  159. }
  160. Widget _buildPhotoGroup({
  161. required String title,
  162. required int imageCount,
  163. }) {
  164. return Container(
  165. padding: EdgeInsets.symmetric(horizontal: 12.w),
  166. margin: EdgeInsets.only(top: 14.h),
  167. width: 328.w,
  168. height: 258.h,
  169. decoration: ShapeDecoration(
  170. color: Colors.white.withValues(alpha: 0.12),
  171. shape: RoundedRectangleBorder(
  172. borderRadius: BorderRadius.circular(14.sp),
  173. ),
  174. ),
  175. child: Column(
  176. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  177. children: [
  178. Row(
  179. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  180. children: [
  181. Row(
  182. children: [
  183. Text(
  184. title,
  185. textAlign: TextAlign.center,
  186. style: TextStyle(
  187. color: Colors.white,
  188. fontSize: 14.sp,
  189. fontWeight: FontWeight.w500,
  190. ),
  191. ),
  192. ],
  193. ),
  194. GestureDetector(
  195. onTap: () => controller.toggleGroupSelection(title),
  196. child: Obx(() => Text(
  197. controller.photoGroups
  198. .firstWhere((g) => g.title == title)
  199. .isSelected
  200. .value
  201. ? 'Deselect All'
  202. : 'Select All',
  203. style: TextStyle(
  204. color: Colors.white.withValues(alpha: 0.7),
  205. fontSize: 14.sp,
  206. fontWeight: FontWeight.w400,
  207. ),
  208. )),
  209. ),
  210. ],
  211. ),
  212. SizedBox(
  213. height: 148.h,
  214. child: ListView(
  215. scrollDirection: Axis.horizontal,
  216. physics: BouncingScrollPhysics(),
  217. children: [
  218. // 第一张大图
  219. if (imageCount > 0)
  220. GestureDetector(
  221. onTap: () => controller.toggleImageSelection(title, 0),
  222. child: SizedBox(
  223. width: 148.w,
  224. height: 148.h,
  225. child: Obx(() {
  226. final group = controller.photoGroups
  227. .firstWhere((g) => g.title == title);
  228. return Stack(
  229. children: [
  230. Container(
  231. decoration: ShapeDecoration(
  232. color: Colors.white.withOpacity(0.12),
  233. shape: RoundedRectangleBorder(
  234. borderRadius: BorderRadius.circular(8.r),
  235. ),
  236. image: DecorationImage(
  237. image:
  238. AssetEntityImageProvider(group.images[0]),
  239. fit: BoxFit.cover,
  240. ),
  241. ),
  242. ),
  243. Positioned(
  244. left: 8.w,
  245. top: 8.h,
  246. child: Container(
  247. width: 108.w,
  248. height: 26.h,
  249. padding: EdgeInsets.symmetric(
  250. horizontal: 8.w,
  251. vertical: 4.h,
  252. ),
  253. decoration: ShapeDecoration(
  254. color: Colors.black.withValues(alpha: 0.74),
  255. shape: RoundedRectangleBorder(
  256. borderRadius:
  257. BorderRadius.circular(14.21.r),
  258. ),
  259. ),
  260. child: Row(
  261. mainAxisAlignment:
  262. MainAxisAlignment.spaceAround,
  263. children: [
  264. Assets.images.iconSimilarBest.image(
  265. width: 11.37.w,
  266. height: 11.37.h,
  267. ),
  268. Text(
  269. 'Best result',
  270. textAlign: TextAlign.center,
  271. style: TextStyle(
  272. color: Colors.white,
  273. fontSize: 13.sp,
  274. fontWeight: FontWeight.w400,
  275. ),
  276. ),
  277. ],
  278. ),
  279. ),
  280. ),
  281. Positioned(
  282. right: 4.w,
  283. bottom: 4.h,
  284. child: Container(
  285. child: group.selectedImages[0]
  286. ? Center(
  287. child: Assets.images.iconSelected.image(
  288. width: 16.w,
  289. height: 16.h,
  290. ),
  291. )
  292. : Center(
  293. child:
  294. Assets.images.iconUnselected.image(
  295. width: 16.w,
  296. height: 16.h,
  297. ),
  298. ),
  299. ),
  300. ),
  301. ],
  302. );
  303. }),
  304. ),
  305. ),
  306. // 其他图片2x2网格
  307. if (imageCount > 1)
  308. ...List.generate(((imageCount - 1) / 4).ceil(), (gridIndex) {
  309. return Container(
  310. margin: EdgeInsets.only(left: 8.w),
  311. width: 142.w,
  312. child: GridView.count(
  313. physics: NeverScrollableScrollPhysics(),
  314. crossAxisCount: 2,
  315. mainAxisSpacing: 8.h,
  316. crossAxisSpacing: 8.w,
  317. children: List.generate(
  318. min(4, imageCount - 1 - gridIndex * 4),
  319. (index) {
  320. final realIndex = gridIndex * 4 + index + 1;
  321. return GestureDetector(
  322. onTap: () => controller.toggleImageSelection(
  323. title, realIndex),
  324. child: Obx(() {
  325. final group = controller.photoGroups
  326. .firstWhere((g) => g.title == title);
  327. return Container(
  328. decoration: ShapeDecoration(
  329. color: Colors.white.withOpacity(0.12),
  330. shape: RoundedRectangleBorder(
  331. borderRadius: BorderRadius.circular(8.r),
  332. ),
  333. image: DecorationImage(
  334. image: AssetEntityImageProvider(
  335. group.images[realIndex]),
  336. fit: BoxFit.cover,
  337. ),
  338. ),
  339. child: Stack(
  340. children: [
  341. Positioned(
  342. right: 4.w,
  343. bottom: 4.h,
  344. child: Obx(() {
  345. final isSelected =
  346. group.selectedImages[realIndex];
  347. return 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. Container(
  382. width: 162.w,
  383. height: 38.h,
  384. decoration: ShapeDecoration(
  385. color: Color(0xFF0279FB),
  386. shape: RoundedRectangleBorder(
  387. borderRadius: BorderRadius.circular(10.r),
  388. ),
  389. ),
  390. child: Center(
  391. child: Obx(() => Text(
  392. 'Move ${controller.photoGroups.firstWhere((g) => g.title == title).selectedCount} to trash',
  393. style: TextStyle(
  394. color: Colors.white,
  395. fontSize: 16.sp,
  396. fontWeight: FontWeight.w500,
  397. ),
  398. )),
  399. ),
  400. ),
  401. ],
  402. ),
  403. );
  404. }
  405. }