当前位置: 首页 > news >正文

flutter封装日历选择器(单日选择)

在这里插入图片描述

简单封装:
引入库:table_calendar

import 'package:generated/l10n.dart';
import 'package:jade/utils/JadeColors.dart';
import 'package:jade/utils/Utils.dart';
import 'package:util/easy_loading_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:table_calendar/table_calendar.dart';class CustomCalendarSelector extends StatefulWidget{final DateTime dateTime;const CustomCalendarSelector({this.dateTime});State<StatefulWidget> createState() {// TODO: implement createStatereturn _CustomCalendarSelectorState();}
}
class _CustomCalendarSelectorState extends State<CustomCalendarSelector>{CalendarController _calendarController;DateTime _selectDateTime;void initState() {super.initState();_calendarController = CalendarController();_selectDateTime = widget.dateTime;}void dispose() {_calendarController.dispose();super.dispose();}Widget build(BuildContext context) {// TODO: implement build//return Container(height: Utils().screenWidth(context)*1.4,child: Column(children: [Expanded(child: TableCalendar(calendarController: _calendarController,startDay: DateTime.now(),endDay: DateTime(DateTime.now().year+ 1,12,31),calendarStyle: const CalendarStyle(weekendStyle: TextStyle(color: Color(0xffff415b)),todayColor: Colors.black12,selectedColor: Color(0xff44aab0),),headerStyle: HeaderStyle(centerHeaderTitle: true,leftChevronVisible: true,rightChevronVisible: true,formatButtonVisible: false,),initialSelectedDay:widget.dateTime??DateTime(DateTime.now().year,DateTime.now().month,DateTime.now().day+1),onUnavailableDaySelected: (){esLoadingToast('请选择可选日期之内的时间');},onDaySelected: (DateTime dateTime, List events, List holidays){if(dateTime.day == DateTime.now().day){esLoadingToast('请选择当期日期之后的时间');return;}_selectDateTime = dateTime;},onHeaderTapped:(DateTime dateTime){}),),Container(margin: EdgeInsets.only(top: 20.h, left: 80.w),child: Row(children: <Widget>[Image.asset('images/cinema/buy/cinema_buy_icon_q.png',width: 35.w,height: 35.h,),SizedBox(width: 10.w,),Text('从当日起的5个工作日内无法上刊',style: TextStyle(fontSize: 24.sp, color: JadeColors.green_3),)],),),Container(margin: EdgeInsets.only(top: 20.h, left: 80.w, right: 80.w,bottom: 40.w),width: double.infinity,height: 85.h,child: TextButton(style: ButtonStyle(minimumSize: MaterialStateProperty.all(Size(300, 38)),backgroundColor: MaterialStateProperty.all(JadeColors.green_3.withOpacity(1.0))),onPressed: () async {if (DateTime.now().isAfter(_selectDateTime)) {esLoadingToast('请选择当期日期之后的时间');return;}Navigator.pop(context, _selectDateTime);},child: Text(S.current.baocun,style: TextStyle(fontSize: 32.sp, color: Colors.white),)))],),);}
}

引用:

_showScheduledDateBottom() {showModalBottomSheet(context: context,isScrollControlled: true,shape: RoundedRectangleBorder(borderRadius: BorderRadius.only(topLeft: Radius.circular(25.w),topRight: Radius.circular(25.w))),builder: (BuildContext context) {return CustomCalendarSelector(dateTime: time);}).then((value) {if (value == null) return;print('${time.year}-${time.month}-${time.day}');});}
http://www.lryc.cn/news/364946.html

相关文章:

  • SwiftUI调用相机拍照
  • elasticsearch (dsl)
  • 聊聊大模型微调训练全流程的思考
  • Python变量符号:深入探索与实用指南
  • 实验八 页面置换模拟程序设计
  • Spring类加载机制揭秘:深度解析“卸载”阶段
  • Jupyter Notebook快速搭建
  • Linux C语言:数组的定义和初始化
  • spring框架限制接口是否要登录过才能访问
  • 【全开源】废品回收垃圾回收小程序APP公众号源码PHP版本
  • 勒索软件分析_目标文件扫描行为分析
  • 2024050401-重学 Java 设计模式《实战代理模式》
  • HTML跨年烟花
  • 微服务第二轮
  • 线性模型-分类
  • OpenAI前董事会成员称Sam Altman因 “ 向董事会撒谎 ” 而被解雇
  • 【启明智显分享】WIFI6开发板ZX6010:开源OpenWrt SDK,接受定制!
  • C语言能否使⽤ fflush( ) 函数清除多余的输⼊?
  • 如何把试卷上的字去掉再打印?分享三种方法
  • Android开机动画压缩包zip,自制开机动画(基于Android10.0.0-r41)
  • 手机站怎么推广
  • Mysql疑难报错排查 - Field ‘XXX‘ doesn‘t have a default value
  • YOLOv8_obb预测流程-原理解析[旋转目标检测理论篇]
  • 02JAVA字符串和集合
  • Qt如何让按钮的菜单出现在按钮的右侧
  • C++的类和new和delete和菱形继承机制
  • Redis教程(二十二):Redis的过期删除和缓存淘汰策略
  • Lodop 实现局域网打印
  • HarmonyOS(二十四)——Harmonyos通用事件之触摸事件
  • 2024-前端面试的正确打开方式(GitHub火爆场景题剖析)