import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_settings.dart'; typedef SelectDateCallback(DateTime dateTime); class CheckingInListSeletMonthPage extends StatefulWidget { int selectYear; int selectMonth; SelectDateCallback? selectAction; CheckingInListSeletMonthPage({required this.selectYear, required this.selectMonth, required this.selectAction, Key? key}) : super(key: key); @override State createState() => _CheckingInListSeletMonthPageState(); } class _CheckingInListSeletMonthPageState extends State { @override Widget build(BuildContext context) { // AppLog.log('selectYear:${widget.selectYear} selectMonth:${widget.selectMonth}'); return Dialog( // insetPadding: EdgeInsets.all(10), //距离 shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.w))), //形状 backgroundColor: Colors.white, clipBehavior: Clip.antiAlias, //强制裁剪 elevation: 10, child: SizedBox( //需要在内部限制下高度和宽度才能更好的显示 height: 270.h, width: 1.sw - 20.w, child: Column( children: [ SizedBox(height: 10.h), SizedBox( height: 80.h, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ GestureDetector( onTap:(){ setState(() { widget.selectYear--; }); }, child: Image(width: 50.w, height: 40.w, image: const AssetImage('images/icon_left_black.png'),), ), SizedBox(width: 50.w,), Text('${widget.selectYear}', style: TextStyle(fontSize: 30.sp, color: Colors.black, fontWeight: FontWeight.w500)), SizedBox(width: 50.w), GestureDetector( onTap: (){ setState(() { widget.selectYear++; }); }, child: Image(width: 50.w, height: 40.w, image: const AssetImage('images/icon_right_black.png')), ), ] ), ), SizedBox(height: 10.h), Container( // padding: EdgeInsets.only(left: 20.w, right: 20.w), child: Expanded( child: Padding( padding: EdgeInsets.only(left: 10.w, right: 10.w), child: GridView.builder( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 6, // crossAxisSpacing: 5.w, // mainAxisSpacing: 5.h, // childAspectRatio: 1.0, ), itemCount: 12, itemBuilder: (BuildContext context, int index) { return GestureDetector( onTap: isFutureMonth(widget.selectYear, index + 1) ? null : (){ setState(() { Get.back(); widget.selectMonth = index + 1; final DateTime selectedDate = DateTime(widget.selectYear, widget.selectMonth, 1); widget.selectAction!(selectedDate); }); }, child: Container( width: 60.w, height: 60.w, alignment: Alignment.center, decoration: BoxDecoration( color: index+1 == widget.selectMonth ? Colors.blue : null, // color: Colors.blue, borderRadius: BorderRadius.circular(40.w), ), child: Text(getMonthTr(index + 1), style: TextStyle(fontSize: 24.sp, color: isFutureMonth(widget.selectYear, index + 1) ? Colors.grey : (index+1 == widget.selectMonth ? Colors.white : Colors.black)), ), )); }, ), ), ),), ], ) ), ); } bool isFutureMonth(int year, int month) { final DateTime now = DateTime.now(); if (year > now.year || (year == now.year && month > now.month)) { return true; } return false; } String getMonthTr(int index){ switch (index) { case 1: return '1月'.tr; case 2: return '2月'.tr; case 3: return '3月'.tr; case 4: return '4月'.tr; case 5: return '5月'.tr; case 6: return '6月'.tr; case 7: return '7月'.tr; case 8: return '8月'.tr; case 9: return '9月'.tr; case 10: return '10月'.tr; case 11: return '11月'.tr; case 12: return '12月'.tr; default: return ''; } } }