screenshots_view.dart 9.8 KB

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