locations_single_photo_view.dart 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import 'package:clean/base/base_page.dart';
  2. import 'package:clean/module/locations_photo/locations_single_photo_controller.dart';
  3. import 'package:clean/module/people_photo/photo_group.dart';
  4. import 'package:clean/resource/assets.gen.dart';
  5. import 'package:clean/router/app_pages.dart';
  6. import 'package:flutter/Material.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get.dart';
  9. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  10. class LocationsSinglePhotoPage
  11. extends BasePage<LocationsSinglePhotoController> {
  12. const LocationsSinglePhotoPage({super.key});
  13. static void start({required PhotoGroup photoGroup}) {
  14. Get.toNamed(RoutePath.locationsSinglePhoto, arguments: {
  15. "PhotoGroup": photoGroup,
  16. });
  17. }
  18. @override
  19. bool statusBarDarkFont() {
  20. return false;
  21. }
  22. @override
  23. bool immersive() {
  24. return true;
  25. }
  26. @override
  27. Widget buildBody(BuildContext context) {
  28. return Stack(children: [
  29. Container(
  30. child: SafeArea(
  31. child: Obx(() {
  32. if (controller.photoGroups.isEmpty) {
  33. return _noNoPicturesCard();
  34. }
  35. return Column(
  36. children: [
  37. _titleCard(),
  38. Expanded(
  39. child: Obx(() {
  40. return SizedBox(
  41. child: GridView.builder(
  42. padding: EdgeInsets.symmetric(horizontal: 16.w),
  43. scrollDirection: Axis.vertical,
  44. // 设置为垂直方向滚动
  45. physics: BouncingScrollPhysics(),
  46. gridDelegate:
  47. SliverGridDelegateWithFixedCrossAxisCount(
  48. crossAxisCount: 3, // 每行显示 3 个元素
  49. mainAxisSpacing: 8.w, // 垂直间距
  50. crossAxisSpacing: 8.h, // 水平间距
  51. ),
  52. itemCount: controller.photoGroups.first.images.length,
  53. itemBuilder: _buildPhotoItem(
  54. controller.photoGroups.first.location ?? "")),
  55. );
  56. }),
  57. ),
  58. Obx(() {
  59. if (controller.selectedFileCount.value == 0) {
  60. return SizedBox();
  61. } else {
  62. return _bottomBarCard();
  63. }
  64. }),
  65. SizedBox(height: 8.h),
  66. ],
  67. );
  68. }),
  69. ),
  70. ),
  71. IgnorePointer(
  72. child: Assets.images.bgHome.image(
  73. width: 360.w,
  74. height: 234.h,
  75. ),
  76. ),
  77. ]);
  78. }
  79. Widget _titleCard() {
  80. return Container(
  81. alignment: Alignment.centerLeft,
  82. padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
  83. child: Column(
  84. crossAxisAlignment: CrossAxisAlignment.start,
  85. children: [
  86. Row(
  87. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  88. children: [
  89. GestureDetector(
  90. onTap: () => Get.back(),
  91. child: Assets.images.iconBackArrow.image(
  92. width: 28.w,
  93. height: 28.h,
  94. ),
  95. ),
  96. Obx(() {
  97. if (controller.photoGroups.isEmpty) return SizedBox();
  98. return Text(
  99. controller.photoGroups.first.location ?? "",
  100. textAlign: TextAlign.center,
  101. style: TextStyle(
  102. color: Colors.white,
  103. fontSize: 17.sp,
  104. fontWeight: FontWeight.w500,
  105. ),
  106. );
  107. }),
  108. Obx(() {
  109. if (controller.photoGroups.isEmpty) return SizedBox();
  110. return GestureDetector(
  111. onTap: () => controller.toggleGroupSelection(
  112. controller.photoGroups.first.location ?? ""),
  113. child: Obx(() => Text(
  114. controller.photoGroups.first.isSelected.value
  115. ? 'Deselect All'
  116. : 'Select All',
  117. style: TextStyle(
  118. color: Colors.white.withValues(alpha: 0.7),
  119. fontSize: 14.sp,
  120. fontWeight: FontWeight.w400,
  121. ),
  122. )),
  123. );
  124. }),
  125. ],
  126. ),
  127. SizedBox(height: 30.h),
  128. ],
  129. ),
  130. );
  131. }
  132. Widget _bottomBarCard() {
  133. return GestureDetector(
  134. onTap: () => controller.clickDelete(),
  135. child: Container(
  136. width: 328.w,
  137. height: 48.h,
  138. decoration: ShapeDecoration(
  139. color: Color(0xFF0279FB),
  140. shape: RoundedRectangleBorder(
  141. borderRadius: BorderRadius.circular(10.r),
  142. ),
  143. ),
  144. padding: EdgeInsets.symmetric(horizontal: 16.w),
  145. child: Row(
  146. mainAxisAlignment: MainAxisAlignment.center,
  147. children: [
  148. Assets.images.iconDelete.image(
  149. width: 18.w,
  150. height: 18.h,
  151. ),
  152. SizedBox(width: 5.w),
  153. Obx(() {
  154. return Text(
  155. '${controller.selectedFileCount.value} files selected (${controller.selectedFilesSize.value.toStringAsFixed(1)} KB)',
  156. textAlign: TextAlign.center,
  157. style: TextStyle(
  158. color: Colors.white,
  159. fontSize: 16.sp,
  160. fontWeight: FontWeight.w500,
  161. ),
  162. );
  163. }),
  164. ],
  165. ),
  166. ),
  167. );
  168. }
  169. Widget Function(BuildContext, int) _buildPhotoItem(String location) =>
  170. (context, index) {
  171. final group = controller.getGroupByLocation(location);
  172. return GestureDetector(
  173. onTap: () => controller.clickImage(location, index),
  174. child: Obx(() {
  175. final isSelected = group.selectedImages[index];
  176. return Stack(
  177. children: [
  178. Container(
  179. width: 104.w,
  180. height: 104.w,
  181. decoration: ShapeDecoration(
  182. color: Colors.white.withValues(alpha: 0.12),
  183. shape: RoundedRectangleBorder(
  184. borderRadius: BorderRadius.circular(9.27.sp),
  185. ),
  186. image: DecorationImage(
  187. image: AssetEntityImageProvider(
  188. group.images[index],
  189. thumbnailSize: const ThumbnailSize.square(300),
  190. isOriginal: false,
  191. ),
  192. fit: BoxFit.cover,
  193. ),
  194. ),
  195. ),
  196. Positioned(
  197. right: 8.w,
  198. bottom: 8.h,
  199. child: GestureDetector(
  200. onTap: () =>
  201. controller.toggleImageSelection(location, index),
  202. child: Container(
  203. child: isSelected
  204. ? Center(
  205. child: Assets.images.iconSelected.image(
  206. width: 20.w,
  207. height: 20.h,
  208. ),
  209. )
  210. : Center(
  211. child: Assets.images.iconUnselected.image(
  212. width: 20.w,
  213. height: 20.h,
  214. )),
  215. )),
  216. ),
  217. ],
  218. );
  219. }),
  220. );
  221. };
  222. Widget _noNoPicturesCard() {
  223. return Column(
  224. children: [
  225. _titleCard(),
  226. SizedBox(
  227. height: 170.h,
  228. ),
  229. Container(
  230. child: Column(
  231. mainAxisAlignment: MainAxisAlignment.center,
  232. crossAxisAlignment: CrossAxisAlignment.center,
  233. children: [
  234. Container(
  235. width: 70.w,
  236. height: 70.h,
  237. clipBehavior: Clip.antiAlias,
  238. decoration: BoxDecoration(),
  239. child: Assets.images.iconNoPictures.image(),
  240. ),
  241. SizedBox(height: 22.h),
  242. Text(
  243. 'No pictures found',
  244. textAlign: TextAlign.center,
  245. style: TextStyle(
  246. color: Colors.white,
  247. fontSize: 20.sp,
  248. fontWeight: FontWeight.w700,
  249. ),
  250. ),
  251. SizedBox(height: 12.h),
  252. Text(
  253. 'No pictures available at the moment',
  254. textAlign: TextAlign.center,
  255. style: TextStyle(
  256. color: Colors.white.withValues(alpha: 0.6),
  257. fontSize: 14.sp,
  258. fontWeight: FontWeight.w400,
  259. ),
  260. ),
  261. ],
  262. ),
  263. ),
  264. ],
  265. );
  266. }
  267. }