flutter日期选择器 flutter时间选择器
作者:早起的年轻人 时间:2023-09-22 04:50:15
本文实例为大家分享了flutter日期时间选择器的具体代码,供大家参考,具体内容如下
1 日期选择器
//设置默认显示的日期为当前
DateTime initialDate = DateTime.now();
void showDefaultYearPicker(BuildContext context) async {
final DateTime dateTime = await showDatePicker(
context: context,
//定义控件打开时默认选择日期
initialDate: initialDate,
//定义控件最早可以选择的日期
firstDate: DateTime(2018, 1),
//定义控件最晚可以选择的日期
lastDate: DateTime(2022, 1),
builder: (BuildContext context, Widget child) {
return Theme(
data: CommonColors.themData,
child: child,
);
},
);
if (dateTime != null && dateTime != initialDate) {}
}
2 时间选择器
//设置显示显示的时间为当前
TimeOfDay initialTime = TimeOfDay.now();
void showDefaultDatePicker(BuildContext context) async {
final TimeOfDay timeOfDay = await showTimePicker(
context: context,
initialTime: initialTime,
builder: (BuildContext context, Widget child) {
return Theme(
data: CommonColors.themData,
child: child,
);
},
);
if (timeOfDay != null && timeOfDay != initialTime) {
setState(() {
initialTime = timeOfDay;
});
}
}
来源:https://blog.csdn.net/zl18603543572/article/details/94614825
标签:flutter,选择器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Java实现缓存Cache的深入分析
2023-08-15 20:53:59
Flutter Widgets MediaQuery控件屏幕信息适配
2023-06-29 04:48:21
![](https://img.aspxhome.com/file/2023/2/120092_0s.jpg)
Android中TextView显示插入的图片实现方法
2023-08-06 00:27:42
java IO流将一个文件拆分为多个子文件代码示例
2023-08-30 12:46:15
![](https://img.aspxhome.com/file/2023/3/58193_0s.jpg)
Android View移动的六种方法小结
2023-07-06 02:43:39
Android 在程序运行时申请权限的实例讲解
2023-08-04 17:35:57
![](https://img.aspxhome.com/file/2023/7/85997_0s.jpg)
Dwr3.0纯注解(纯Java Code配置)配置与应用浅析二之前端调用后端
2023-08-19 17:32:33
![](https://img.aspxhome.com/file/2023/3/57693_0s.png)
ObjectMapper 如何忽略字段大小写
2023-07-31 07:07:18
![](https://img.aspxhome.com/file/2023/9/57799_0s.png)
Flutter瀑布流仿写原生的复用机制详解
2023-06-20 17:02:08
![](https://img.aspxhome.com/file/2023/0/98700_0s.jpg)
flutter ExpansionTile 层级菜单的实现
2023-06-15 16:04:01
![](https://img.aspxhome.com/file/2023/7/91007_0s.png)
java 进制转换实例详解
2023-07-05 11:53:45
Flutter 通过Clipper实现各种自定义形状的示例代码
2023-06-19 14:25:11
![](https://img.aspxhome.com/file/2023/7/59397_0s.jpg)
C#几种截取字符串的方法小结
2023-07-16 09:55:10
Java中Function的使用及说明
2023-08-12 03:04:29
![](https://img.aspxhome.com/file/2023/5/58025_0s.png)
C# GDI+实现时钟表盘
2023-06-20 07:11:32
![](https://img.aspxhome.com/file/2023/7/66117_0s.jpg)
合成聚合复用原则_动力节点Java学院整理
2023-06-27 22:05:20
![](https://img.aspxhome.com/file/2023/9/57599_0s.png)
android实现简易计算器
2023-06-21 04:26:09
![](https://img.aspxhome.com/file/2023/4/83514_0s.jpg)
Mybatis工具类JdbcTypeInterceptor运行时自动添加jdbcType属性
2023-08-24 03:49:59
C语言字符串操作总结大全(超详细)
2023-07-06 15:14:56
Android超清晰6.0权限申请AndPermission
2023-08-05 10:52:26