英文:
_CastError (type 'String' is not a subtype of type 'DateTime' in type cast)
问题
只返回翻译好的部分:
我正在尝试将日期(yyyy/mm/dd)添加到Firebase,但在将_selectedDate
转换为yMd格式时,在我的代码的其他位置出现了此错误:“_CastError(类型 'String'不是类型 'DateTime'中的子类型
)”
声明变量:
String _selectedDate = DateFormat("yyyy/MM/dd").format(DateTime.now()).toString();
可以输入日期的地方:
MyInputField(
title: "日期",
hint: DateFormat.yMd().format(_selectedDate))
英文:
I am trying to add a Date (yyyy/mm/dd) to Firebase and when converting the _selectedDate
to a yMd format I am getting this error somnewhere else in my code _CastError (type 'String' is not a subtype of type 'DateTime' in type cast)
Declare variable:
String _selectedDate = DateFormat("yyyy/mm/dd").format(DateTime.now()).toString();
The place where you can enter the date:
MyInputField(
title: "Date",
hint: DateFormat.yMd().format(_selectedDate))
答案1
得分: 0
我猜测提示需要一个String
,而你已经将DateTime.now()
转换为String。所以,你可能不被允许为_selectedDate
调用format
。
MyInputField(
title: "日期",
hint: _selectedDate.toString())
或者在赋值中:
DateTime _selectedTime = DateTime.now();
你应该选择一种方式,不要同时使用两种。
英文:
I guess hint requires String
and already you converted DateTime.now()
to String. So, you may not be allowed to call format
for _selectedDate
.
MyInputField(
title: "Date",
hint: _selectedDate)
or in assignment
DateTime _selectedTime = DateTime.now();
You are supposed to user either a way, not both.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论