people_photo_view.dart 12 KB

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