people_photo_view.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import 'dart:io';
  2. import 'package:clean/base/base_page.dart';
  3. import 'package:clean/data/bean/photos_type.dart';
  4. import 'package:clean/module/image_picker/image_picker_util.dart';
  5. import 'package:clean/module/people_photo/people_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/cupertino.dart';
  10. import 'package:flutter_screenutil/flutter_screenutil.dart';
  11. import 'package:get/get.dart';
  12. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  13. class PeoplePhotoPage extends BasePage<PeoplePhotoController> {
  14. const PeoplePhotoPage({super.key});
  15. static start() {
  16. Get.toNamed(RoutePath.peoplePhoto, arguments: {});
  17. }
  18. @override
  19. bool statusBarDarkFont() {
  20. // TODO: implement statusBarDarkFont
  21. return false;
  22. }
  23. @override
  24. bool immersive() {
  25. // TODO: implement immersive
  26. return true;
  27. }
  28. @override
  29. Widget buildBody(BuildContext context) {
  30. return Stack(children: [
  31. PopScope(
  32. canPop: false,
  33. onPopInvokedWithResult: (didPop, result) {
  34. if (didPop) {
  35. return;
  36. }
  37. controller.clickBack();
  38. },
  39. child: Container(
  40. child: SafeArea(
  41. child: Obx(() {
  42. if (controller.photoGroups.isEmpty ||
  43. controller.photoGroups[0].images.isEmpty) {
  44. return _noNoPicturesCard();
  45. }
  46. return Column(
  47. children: [
  48. _titleCard(),
  49. // Photo groups
  50. Flexible(
  51. child: Obx(() {
  52. return ListView(
  53. padding: EdgeInsets.symmetric(horizontal: 16.w),
  54. children: [
  55. ...controller.photoGroups.map((group) => Column(
  56. children: [
  57. _buildPhotoGroup(
  58. images: group.images,
  59. title: "photo: ${group.images.length}",
  60. imageCount: group.images.length,
  61. ),
  62. SizedBox(height: 15.h),
  63. ],
  64. ))
  65. ],
  66. );
  67. }),
  68. ),
  69. _bottomBarCard(),
  70. ],
  71. );
  72. }),
  73. ),
  74. ),),
  75. IgnorePointer(
  76. child: Assets.images.bgHome.image(
  77. width: 360.w,
  78. ),
  79. ),
  80. ]);
  81. }
  82. Widget _titleCard() {
  83. return Container(
  84. alignment: Alignment.centerLeft,
  85. padding: EdgeInsets.only(left: 16.w, top: 14.h),
  86. child: Column(
  87. crossAxisAlignment: CrossAxisAlignment.start,
  88. children: [
  89. GestureDetector(
  90. onTap: controller.clickBack,
  91. child: Assets.images.iconBackArrow.image(
  92. width: 28.w,
  93. height: 28.h,
  94. ),
  95. ),
  96. (controller.photoGroups.isEmpty ||
  97. controller.photoGroups[0].images.isEmpty)
  98. ? SizedBox()
  99. : Column(
  100. children: [
  101. SizedBox(height: 12.h),
  102. Text(
  103. 'People Photos',
  104. style: TextStyle(
  105. color: Colors.white,
  106. fontSize: 24.sp,
  107. fontWeight: FontWeight.w700,
  108. ),
  109. ),
  110. SizedBox(height: 20.h),
  111. ],
  112. )
  113. ],
  114. ),
  115. );
  116. }
  117. Widget _bottomBarCard() {
  118. return GestureDetector(
  119. onTap: () {
  120. controller.clickJumpSelect();
  121. },
  122. child: Container(
  123. width: 360.w,
  124. height: 81.h,
  125. padding: EdgeInsets.symmetric(horizontal: 16.w),
  126. decoration: ShapeDecoration(
  127. color: Color(0xFF23232A),
  128. shape: RoundedRectangleBorder(
  129. side: BorderSide(
  130. width: 1.w, color: Colors.white.withValues(alpha: 0.1)),
  131. borderRadius: BorderRadius.only(
  132. topLeft: Radius.circular(14.r),
  133. topRight: Radius.circular(14.r),
  134. ),
  135. ),
  136. ),
  137. child: Row(
  138. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  139. children: [
  140. Obx(() {
  141. return Text(
  142. '${controller.selectedFileCount.value} files selected (${controller.selectedFilesSizeString})',
  143. textAlign: TextAlign.center,
  144. style: TextStyle(
  145. color: Colors.white.withOpacity(0.9),
  146. fontSize: 13.sp,
  147. fontWeight: FontWeight.w500,
  148. ),
  149. );
  150. }),
  151. GestureDetector(
  152. onTap: () {
  153. controller.clickDelete();
  154. },
  155. child:
  156. Container(
  157. width: 108.w,
  158. height: 38.h,
  159. decoration: ShapeDecoration(
  160. color: Color(0xFF0279FB),
  161. shape: RoundedRectangleBorder(
  162. borderRadius: BorderRadius.circular(10.r),
  163. ),
  164. ),
  165. child: Row(
  166. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  167. children: [
  168. Text(
  169. 'Delete',
  170. textAlign: TextAlign.center,
  171. style: TextStyle(
  172. color: Colors.white,
  173. fontSize: 16.sp,
  174. fontWeight: FontWeight.w500,
  175. ),
  176. ),
  177. Assets.images.iconDelete.image(
  178. width: 18.w,
  179. height: 18.h,
  180. ),
  181. ],
  182. ),
  183. ),
  184. ),
  185. ],
  186. ),
  187. )
  188. );
  189. }
  190. Widget _buildPhotoGroup({
  191. required List<AssetEntity> images,
  192. required String title,
  193. required int imageCount,
  194. }) {
  195. return Container(
  196. padding: EdgeInsets.symmetric(horizontal: 12.w),
  197. margin: EdgeInsets.only(top: 14.h),
  198. width: 328.w,
  199. height: imageCount < 5 ? 160.h : 230.h,
  200. decoration: ShapeDecoration(
  201. color: Colors.white.withValues(alpha: 0.12),
  202. shape: RoundedRectangleBorder(
  203. borderRadius: BorderRadius.circular(14.sp),
  204. ),
  205. ),
  206. child: Column(
  207. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  208. children: [
  209. Row(
  210. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  211. children: [
  212. Text(
  213. title,
  214. textAlign: TextAlign.center,
  215. style: TextStyle(
  216. color: Colors.white,
  217. fontSize: 14.sp,
  218. fontWeight: FontWeight.w500,
  219. ),
  220. ),
  221. GestureDetector(
  222. onTap: () => controller.toggleGroupSelection(images),
  223. child: Obx(() => Text(
  224. controller.getGroupByImages(images).isSelected.value
  225. ? 'Deselect All'
  226. : 'Select All',
  227. style: TextStyle(
  228. color: Colors.white.withValues(alpha: 0.7),
  229. fontSize: 14.sp,
  230. fontWeight: FontWeight.w400,
  231. ),
  232. )),
  233. ),
  234. ],
  235. ),
  236. SizedBox(
  237. height: imageCount < 3
  238. ? 70.h
  239. : imageCount <= 8
  240. ? null
  241. : 148.h,
  242. child: imageCount <= 8
  243. ? GridView.builder(
  244. shrinkWrap: true,
  245. physics: NeverScrollableScrollPhysics(),
  246. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  247. crossAxisCount: 4,
  248. mainAxisSpacing: 8.w,
  249. crossAxisSpacing: 8.h,
  250. ),
  251. itemCount: imageCount,
  252. itemBuilder: _buildPhotoItem(images),
  253. )
  254. : GridView.builder(
  255. scrollDirection: Axis.horizontal,
  256. physics: BouncingScrollPhysics(),
  257. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  258. crossAxisCount: 2,
  259. mainAxisSpacing: 8.w,
  260. crossAxisSpacing: 8.h,
  261. childAspectRatio: 1,
  262. ),
  263. itemCount: imageCount,
  264. itemBuilder: _buildPhotoItem(images),
  265. ),
  266. ),
  267. ],
  268. ),
  269. );
  270. }
  271. Widget Function(BuildContext, int) _buildPhotoItem(
  272. List<AssetEntity> images) =>
  273. (context, index) {
  274. final group = controller.getGroupByImages(images);
  275. final assetEntity = group.images[index];
  276. return GestureDetector(
  277. onTap: () {
  278. controller.clickImage(images, index, PhotosType.peoplePhotos);
  279. print("点击图片");
  280. },
  281. child: Obx(() {
  282. final isSelected = group.selectedImages[index];
  283. return Stack(
  284. children: [
  285. Container(
  286. width: 70.w,
  287. height: 70.w,
  288. decoration: ShapeDecoration(
  289. color: Colors.white.withValues(alpha: 0.12),
  290. shape: RoundedRectangleBorder(
  291. borderRadius: BorderRadius.circular(9.27.sp),
  292. ),
  293. image: DecorationImage(
  294. image: AssetEntityImageProvider(
  295. assetEntity,
  296. thumbnailSize: const ThumbnailSize.square(300),
  297. isOriginal: false,
  298. ),
  299. fit: BoxFit.cover,
  300. ),
  301. ),
  302. ),
  303. Positioned(
  304. right: 6.w,
  305. bottom: 6.h,
  306. child: GestureDetector(
  307. onTap: () {
  308. controller.toggleImageSelection(images, index);
  309. },
  310. child: Container(
  311. child: isSelected
  312. ? Center(
  313. child: Assets.images.iconSelected.image(
  314. width: 20.w,
  315. height: 20.h,
  316. ),
  317. )
  318. : Center(
  319. child: Assets.images.iconUnselected.image(
  320. width: 20.w,
  321. height: 20.h,
  322. )),
  323. ),
  324. )),
  325. ],
  326. );
  327. }),
  328. );
  329. };
  330. Widget _noNoPicturesCard() {
  331. return Column(
  332. // mainAxisAlignment: MainAxisAlignment.start,
  333. children: [
  334. _titleCard(),
  335. Spacer(flex: 1),
  336. Column(
  337. crossAxisAlignment: CrossAxisAlignment.center,
  338. children: [
  339. Container(
  340. width: 70.w,
  341. height: 70.h,
  342. clipBehavior: Clip.antiAlias,
  343. decoration: BoxDecoration(),
  344. child: Assets.images.iconNoPictures.image(),
  345. ),
  346. SizedBox(height: 22.h),
  347. Text(
  348. 'No pictures found',
  349. textAlign: TextAlign.center,
  350. style: TextStyle(
  351. color: Colors.white,
  352. fontSize: 20.sp,
  353. fontWeight: FontWeight.w700,
  354. ),
  355. ),
  356. SizedBox(height: 12.h),
  357. Text(
  358. 'No pictures available at the moment',
  359. textAlign: TextAlign.center,
  360. style: TextStyle(
  361. color: Colors.white.withValues(alpha: 0.6),
  362. fontSize: 14.sp,
  363. fontWeight: FontWeight.w400,
  364. ),
  365. ),
  366. ],
  367. ),
  368. Spacer(
  369. flex: 3,
  370. ),
  371. ],
  372. );
  373. }
  374. }