如何在颤振的日期时间字段小部件中禁用键盘输入?



我想在我的 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));
},
), 

试试这个:

// set readOnly property to true,
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));
},
readOnly: true,  //Add this line

),

相关内容

  • 没有找到相关文章

最新更新