calendar_month_view.dart 12 KB

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