people_photo_view.dart 12 KB

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