flutter - 如何在 Flutter 的 DateTimeField 小部件中禁用键盘输入?
问题描述
我想在我的 Flutter 应用程序中创建一个DateTimeField小部件。但是在我在该字段中选择了一个日期后,我仍然可以使用单击该字段后出现的键盘来编辑该字段。我确实喜欢以下内容。如何为此小部件禁用此键盘?
DateTimeField(
textAlign: TextAlign.center,
format: format,
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none,
fontWeight: FontWeight.w600,
),
decoration: InputDecoration(
hintText: "Tanggal Lahir",
hintStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
),
border: InputBorder.none,
),
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime(1990,1,1),
initialDate: currentValue ?? DateTime(2000,6,16),
lastDate: DateTime(2010,12,30));
},
),
解决方案
只需添加只读参数
DateTimeField(
textAlign: TextAlign.center,
format: format,
readOnly: true,
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none,
fontWeight: FontWeight.w600,
),
decoration: InputDecoration(
hintText: "Tanggal Lahir",
hintStyle: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
),
border: InputBorder.none,
),
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime(1990, 1, 1),
initialDate: currentValue ?? DateTime(2000, 6, 16),
lastDate: DateTime(2010, 12, 30));
},
),
推荐阅读
- html - 多图像合一图像文件的背景图像视口
- javascript - 按字母顺序验证输入的名称
- javascript - 使用 axios 将数据放入我的数据库的问题
- apache-spark - 使用 Delta Lake 中的 Spark 更新现有行,而不影响同时由另一个作业写入的数据
- sql - SQL 函数抛出不存在错误
- sql - 等效于 Postgres 中 Oracle 的 utl_raw.cast_to_raw()
- swift - 我如何对协议及其扩展进行单元测试
- python - python selenium为windows设置带有时间戳的默认下载目录
- asp.net-core - 我无法使用 ChildCategories 获取所有类别数据
- python - Pyinstaller - Python App with Matplotlib runs from command line, but not from Explorer