calendar_month_view.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  59. crossAxisCount: 3, // 每行显示 3 个元素
  60. mainAxisSpacing: 8.w, // 垂直间距
  61. crossAxisSpacing: 8.h, // 水平间距
  62. ),
  63. itemCount: controller.photoGroup.value.images.length,
  64. itemBuilder: _buildPhotoItem(
  65. controller.photoGroup.value.images));
  66. }),
  67. ),
  68. Obx(() {
  69. return controller.isSelectMode.value
  70. ? controller
  71. .photoGroup.value.selectedPhotosIds.isNotEmpty
  72. ? _bottomBarCard()
  73. : Container()
  74. : Container();
  75. }),
  76. SizedBox(height: 8.h),
  77. ],
  78. );
  79. }),
  80. )),
  81. IgnorePointer(
  82. child: Assets.images.bgHome.image(
  83. width: 360.w,
  84. ),
  85. ),
  86. ]);
  87. }
  88. Widget _titleCard() {
  89. return Container(
  90. alignment: Alignment.centerLeft,
  91. padding: EdgeInsets.only(left: 16.w, top: 14.h, right: 16.w),
  92. child: Column(
  93. crossAxisAlignment: CrossAxisAlignment.start,
  94. children: [
  95. Obx(() {
  96. return Row(
  97. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  98. children: [
  99. controller.isSelectMode.value
  100. ? GestureDetector(
  101. onTap: () {
  102. controller.isSelectMode.value = false;
  103. },
  104. child: Container(
  105. width: 71.w,
  106. height: 30.h,
  107. decoration: ShapeDecoration(
  108. color: Color(0xFF2A3E55),
  109. shape: RoundedRectangleBorder(
  110. borderRadius: BorderRadius.circular(83.r),
  111. ),
  112. ),
  113. child: Center(
  114. child: Text(
  115. 'Cancel',
  116. style: TextStyle(
  117. color: Colors.white,
  118. fontSize: 14.sp,
  119. fontWeight: FontWeight.w400,
  120. ),
  121. ),
  122. ),
  123. ))
  124. : GestureDetector(
  125. onTap: controller.clickBack,
  126. child: Assets.images.iconBackArrow.image(
  127. width: 28.w,
  128. height: 28.h,
  129. ),
  130. ),
  131. controller.photoGroup.value.images.isEmpty
  132. ? Container()
  133. : GestureDetector(
  134. onTap: () =>
  135. controller.isSelectMode.value
  136. ? controller.toggleGroupSelection(
  137. controller.photoGroup.value.images)
  138. : null,
  139. child: Obx(() =>
  140. controller.isSelectMode.value
  141. ? Text(
  142. controller.photoGroup.value.isSelected.value
  143. ? 'Deselect All'
  144. : 'Select All',
  145. style: TextStyle(
  146. color: Colors.white.withValues(alpha: 0.7),
  147. fontSize: 14.sp,
  148. fontWeight: FontWeight.w400,
  149. ),
  150. )
  151. : GestureDetector(
  152. onTap: () {
  153. controller.isSelectMode.value = true;
  154. },
  155. child: Container(
  156. width: 71.w,
  157. height: 30.h,
  158. alignment: Alignment.center,
  159. decoration: ShapeDecoration(
  160. color: Color(0xFF1F2D3F),
  161. shape: RoundedRectangleBorder(
  162. borderRadius: BorderRadius.circular(83.r),
  163. ),
  164. ),
  165. child: Text(
  166. 'Select',
  167. style: TextStyle(
  168. color: Colors.white,
  169. fontSize: 14.sp,
  170. fontWeight: FontWeight.w400,
  171. ),
  172. ),
  173. ),
  174. )),
  175. ),
  176. ],
  177. );
  178. }),
  179. controller.photoGroup.value.images.isEmpty
  180. ? Container()
  181. : Column(
  182. children: [
  183. SizedBox(height: 12.h),
  184. Text(
  185. CalendarState.formatMonth(
  186. controller.photoGroup.value.month ?? ""),
  187. style: TextStyle(
  188. color: Colors.white,
  189. fontSize: 24.sp,
  190. fontWeight: FontWeight.w700,
  191. ),
  192. ),
  193. SizedBox(height: 20.h),
  194. ],
  195. ),
  196. ],
  197. ),
  198. );
  199. }
  200. Widget Function(BuildContext, int) _buildPhotoItem(
  201. List<AssetEntity> images) =>
  202. (context, index) {
  203. return Obx(() {
  204. final photoId = controller.photoGroup.value.images[index].id;
  205. final isSelected =
  206. controller.photoGroup.value.selectedPhotosIds.contains(photoId);
  207. return GestureDetector(
  208. onTap: () => controller.clickImage(index),
  209. child: Stack(
  210. children: [
  211. Container(
  212. width: 104.w,
  213. height: 104.w,
  214. decoration: ShapeDecoration(
  215. color: Colors.white.withValues(alpha: 0.12),
  216. shape: RoundedRectangleBorder(
  217. borderRadius: BorderRadius.circular(9.27.sp),
  218. ),
  219. image: DecorationImage(
  220. image: AssetEntityImageProvider(
  221. controller.photoGroup.value.images[index],
  222. thumbnailSize: const ThumbnailSize.square(300),
  223. isOriginal: false,
  224. ),
  225. fit: BoxFit.cover,
  226. ),
  227. ),
  228. ),
  229. Positioned(
  230. right: 8.w,
  231. bottom: 8.h,
  232. child: Visibility(
  233. visible: controller.isSelectMode.value,
  234. child: GestureDetector(
  235. onTap: () => controller.toggleImageSelection(index),
  236. child: Container(
  237. child: isSelected
  238. ? Center(
  239. child: Assets.images.iconSelected.image(
  240. width: 20.w,
  241. height: 20.h,
  242. ),
  243. )
  244. : Center(
  245. child: Assets.images.iconUnselected.image(
  246. width: 20.w,
  247. height: 20.h,
  248. )),
  249. ))),
  250. ),
  251. ],
  252. ));
  253. });
  254. };
  255. Widget _bottomBarCard() {
  256. return GestureDetector(
  257. onTap: () {
  258. controller.clickDelete();
  259. },
  260. child: Container(
  261. width: 328.w,
  262. height: 48.h,
  263. decoration: ShapeDecoration(
  264. color: Color(0xFF0279FB),
  265. shape: RoundedRectangleBorder(
  266. borderRadius: BorderRadius.circular(10.r),
  267. ),
  268. ),
  269. padding: EdgeInsets.symmetric(horizontal: 16.w),
  270. child: Row(
  271. mainAxisAlignment: MainAxisAlignment.center,
  272. children: [
  273. Assets.images.iconDelete.image(
  274. width: 18.w,
  275. height: 18.h,
  276. ),
  277. SizedBox(width: 5.w),
  278. Obx(() {
  279. return Text(
  280. 'delete ${controller
  281. .selectedFilesSizeString}',
  282. textAlign: TextAlign.center,
  283. style: TextStyle(
  284. color: Colors.white,
  285. fontSize: 16.sp,
  286. fontWeight: FontWeight.w500,
  287. ),
  288. );
  289. }),
  290. ],
  291. ),
  292. ));
  293. }
  294. Widget _noNoPicturesCard() {
  295. return Column(
  296. children: [
  297. _titleCard(),
  298. SizedBox(
  299. height: 170.h,
  300. ),
  301. Container(
  302. child: Column(
  303. mainAxisAlignment: MainAxisAlignment.center,
  304. crossAxisAlignment: CrossAxisAlignment.center,
  305. children: [
  306. Container(
  307. width: 70.w,
  308. height: 70.h,
  309. clipBehavior: Clip.antiAlias,
  310. decoration: BoxDecoration(),
  311. child: Assets.images.iconNoPictures.image(),
  312. ),
  313. SizedBox(height: 22.h),
  314. Text(
  315. 'No pictures found',
  316. textAlign: TextAlign.center,
  317. style: TextStyle(
  318. color: Colors.white,
  319. fontSize: 20.sp,
  320. fontWeight: FontWeight.w700,
  321. ),
  322. ),
  323. SizedBox(height: 12.h),
  324. Text(
  325. 'No pictures available at the moment',
  326. textAlign: TextAlign.center,
  327. style: TextStyle(
  328. color: Colors.white.withValues(alpha: 0.6),
  329. fontSize: 14.sp,
  330. fontWeight: FontWeight.w400,
  331. ),
  332. ),
  333. ],
  334. ),
  335. ),
  336. ],
  337. );
  338. }
  339. }