calendar_month_view.dart 12 KB

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