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

2024-06-06 18:04

本文主要是介绍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}');});}

这篇关于flutter封装日历选择器(单日选择)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1036837

相关文章

如何选择适合孤独症兄妹的学校?

在探索适合孤独症儿童教育的道路上,每一位家长都面临着前所未有的挑战与抉择。当这份责任落在拥有孤独症兄妹的家庭肩上时,选择一所能够同时满足两个孩子特殊需求的学校,更显得尤为关键。本文将探讨如何为这样的家庭做出明智的选择,并介绍星贝育园自闭症儿童寄宿制学校作为一个值得考虑的选项。 理解孤独症儿童的独特性 孤独症,这一复杂的神经发育障碍,影响着儿童的社交互动、沟通能力以及行为模式。对于拥有孤独症兄

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

cross-plateform 跨平台应用程序-03-如果只选择一个框架,应该选择哪一个?

跨平台系列 cross-plateform 跨平台应用程序-01-概览 cross-plateform 跨平台应用程序-02-有哪些主流技术栈? cross-plateform 跨平台应用程序-03-如果只选择一个框架,应该选择哪一个? cross-plateform 跨平台应用程序-04-React Native 介绍 cross-plateform 跨平台应用程序-05-Flutte

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

如何选择SDR无线图传方案

在开源软件定义无线电(SDR)领域,有几个项目提供了无线图传的解决方案。以下是一些开源SDR无线图传方案: 1. **OpenHD**:这是一个远程高清数字图像传输的开源解决方案,它使用SDR技术来实现高清视频的无线传输。OpenHD项目提供了一个完整的工具链,包括发射器和接收器的硬件设计以及相应的软件。 2. **USRP(Universal Software Radio Periphera

《数据结构(C语言版)第二版》第八章-排序(8.3-交换排序、8.4-选择排序)

8.3 交换排序 8.3.1 冒泡排序 【算法特点】 (1) 稳定排序。 (2) 可用于链式存储结构。 (3) 移动记录次数较多,算法平均时间性能比直接插入排序差。当初始记录无序,n较大时, 此算法不宜采用。 #include <stdio.h>#include <stdlib.h>#define MAXSIZE 26typedef int KeyType;typedef char In

JavaSE——封装、继承和多态

1. 封装 1.1 概念      面向对象程序三大特性:封装、继承、多态 。而类和对象阶段,主要研究的就是封装特性。何为封装呢?简单来说就是套壳屏蔽细节 。     比如:对于电脑这样一个复杂的设备,提供给用户的就只是:开关机、通过键盘输入,显示器, USB 插孔等,让用户来和计算机进行交互,完成日常事务。但实际上:电脑真正工作的却是CPU 、显卡、内存等一些硬件元件。

为什么现在很多人愿意选择做债务重组?债重组真的就这么好吗?

债务重组,起初作为面向优质企业客户的定制化大额融资策略,以其高效周期著称,一个月便显成效。然而,随着时代的车轮滚滚向前,它已悄然转变为负债累累、深陷网贷泥潭者的救赎之道。在此路径下,个人可先借助专业机构暂代月供,经一段时间养护征信之后,转向银行获取低成本贷款,用以替换高昂网贷,实现利息减负与成本优化的双重目标。 尽管债务重组的代价不菲,远超传统贷款成本,但其吸引力依旧强劲,背后逻辑深刻。其一

Flutter Button使用

Material 组件库中有多种按钮组件如ElevatedButton、TextButton、OutlineButton等,它们的父类是于ButtonStyleButton。         基本的按钮特点:         1.按下时都会有“水波文动画”。         2.onPressed属性设置点击回调,如果不提供该回调则按钮会处于禁用状态,禁用状态不响应用户点击。