calendar_month_view.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. if (controller.photoGroup.value.images[index].type == AssetType.video)
  230. Positioned(
  231. bottom: 8.h,
  232. left: 8.w,
  233. child: Container(
  234. padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
  235. decoration: BoxDecoration(
  236. color: Colors.black54,
  237. borderRadius: BorderRadius.circular(6.r),
  238. ),
  239. child: Text(
  240. CalendarState.formatDuration(controller.photoGroup.value.images[index].duration),
  241. style: TextStyle(color: Colors.white, fontSize: 12.sp),
  242. ),
  243. ),
  244. ),
  245. Positioned(
  246. right: 8.w,
  247. bottom: 8.h,
  248. child: Visibility(
  249. visible: controller.isSelectMode.value,
  250. child: GestureDetector(
  251. onTap: () => controller.toggleImageSelection(index),
  252. child: Container(
  253. child: isSelected
  254. ? Center(
  255. child: Assets.images.iconSelected.image(
  256. width: 20.w,
  257. height: 20.h,
  258. ),
  259. )
  260. : Center(
  261. child: Assets.images.iconUnselected.image(
  262. width: 20.w,
  263. height: 20.h,
  264. )),
  265. ))),
  266. ),
  267. ],
  268. ));
  269. });
  270. };
  271. Widget _bottomBarCard() {
  272. return GestureDetector(
  273. onTap: () {
  274. controller.clickDelete();
  275. },
  276. child: Container(
  277. width: 328.w,
  278. height: 48.h,
  279. decoration: ShapeDecoration(
  280. color: Color(0xFF0279FB),
  281. shape: RoundedRectangleBorder(
  282. borderRadius: BorderRadius.circular(10.r),
  283. ),
  284. ),
  285. padding: EdgeInsets.symmetric(horizontal: 16.w),
  286. child: Row(
  287. mainAxisAlignment: MainAxisAlignment.center,
  288. children: [
  289. Assets.images.iconDelete.image(
  290. width: 18.w,
  291. height: 18.h,
  292. ),
  293. SizedBox(width: 5.w),
  294. Obx(() {
  295. return Text(
  296. 'delete ${controller
  297. .selectedFilesSizeString}',
  298. textAlign: TextAlign.center,
  299. style: TextStyle(
  300. color: Colors.white,
  301. fontSize: 16.sp,
  302. fontWeight: FontWeight.w500,
  303. ),
  304. );
  305. }),
  306. ],
  307. ),
  308. ));
  309. }
  310. Widget _noNoPicturesCard() {
  311. return Column(
  312. children: [
  313. _titleCard(),
  314. SizedBox(
  315. height: 170.h,
  316. ),
  317. Container(
  318. child: Column(
  319. mainAxisAlignment: MainAxisAlignment.center,
  320. crossAxisAlignment: CrossAxisAlignment.center,
  321. children: [
  322. Container(
  323. width: 70.w,
  324. height: 70.h,
  325. clipBehavior: Clip.antiAlias,
  326. decoration: BoxDecoration(),
  327. child: Assets.images.iconNoPictures.image(),
  328. ),
  329. SizedBox(height: 22.h),
  330. Text(
  331. 'No pictures found',
  332. textAlign: TextAlign.center,
  333. style: TextStyle(
  334. color: Colors.white,
  335. fontSize: 20.sp,
  336. fontWeight: FontWeight.w700,
  337. ),
  338. ),
  339. SizedBox(height: 12.h),
  340. Text(
  341. 'No pictures available at the moment',
  342. textAlign: TextAlign.center,
  343. style: TextStyle(
  344. color: Colors.white.withValues(alpha: 0.6),
  345. fontSize: 14.sp,
  346. fontWeight: FontWeight.w400,
  347. ),
  348. ),
  349. ],
  350. ),
  351. ),
  352. ],
  353. );
  354. }
  355. }