flutter - 列的子项不得包含任何空值,但在索引 13 处找到空值。 Flutter 函数
问题描述
我开发了一款提醒老年人服药时间的应用程序。在这里,他们必须选择药物剂量,例如一天一次和一天两次。我创建了一个函数,它接受这个剂量并返回等于这些时间的字段。例如,如果用户选择“一天三次”,则会出现 3 个字段来选择时间。
当我运行我的应用程序时,出现以下错误:
Column's children must not contain any null values, but a null value was found at index 13
我发现错误是由这个函数引起的:
Widget time(String value) {
Widget w;
if (value == "مرة واحدة في اليوم"){
w = SizedBox(
height: 1,
);}
else if (value == 'مرتان في اليوم') {
w = AddContainer(
text: DateFormat('hh:mm').format(updatedTime2), // ("وقت الدواء"),
onPressed: () {
showModalBottomSheet(
context: context, builder: buildShowModalBottomSheetMedTime2);
});
} else if (value == "ثلاث مرات في اليوم") {
w = Column(
children: [
AddContainer(
text: DateFormat('hh:mm').format(updatedTime2), // ("وقت الدواء"),
onPressed: () {
showModalBottomSheet(
context: context,
builder: buildShowModalBottomSheetMedTime2);
}),
SizedBox(height: 20),
AddContainer(
text: DateFormat('hh:mm').format(updatedTime3), // ("وقت الدواء"),
onPressed: () {
showModalBottomSheet(
context: context,
builder: buildShowModalBottomSheetMedTime3);
}),
SizedBox(height: 20),
],
);
} else if (value == "اربعة مرات في اليوم") {
w = Column(
children: [
AddContainer(
text: DateFormat('hh:mm').format(updatedTime2), // ("وقت الدواء"),
onPressed: () {
showModalBottomSheet(
context: context,
builder: buildShowModalBottomSheetMedTime2);
}),
SizedBox(height: 20),
AddContainer(
text: DateFormat('hh:mm').format(updatedTime3), // ("وقت الدواء"),
onPressed: () {
showModalBottomSheet(
context: context,
builder: buildShowModalBottomSheetMedTime3);
}),
SizedBox(height: 20),
AddContainer(
text: DateFormat('hh:mm').format(updatedTime4), // ("وقت الدواء"),
onPressed: () {
showModalBottomSheet(
context: context,
builder: buildShowModalBottomSheetMedTime4);
}),
SizedBox(height: 20),
],
);
}
return w;
}
我怎么解决这个问题?
解决方案
您可以替换所有出现的 dateFormat ,例如:
text: DateFormat('hh:mm').format(updatedTime2),
经过
text: updatedTime2 != null ? DateFormat('hh:mm').format(updatedTime2) : "",
您不能为文本赋予空值。
这将允许您的小部件工作,直到用户选择时间。
推荐阅读
- c++ - 为什么 Avira 将“CoCreateInstance()”函数视为恶意软件?
- ios - 使用 (iOS-charts) 和 LineChartData setValueTextColor 具有多种颜色的折线图 xAxis 标签
- php - 找出对象集之间的差异
- html - 点击一个 html 标签,然后调用 smarty 函数
- android - [AOSP][Android-8.0]surface.aidl 从 frameworks/base 移动到 frameworks/native
- layout - magento 1.9 在结帐页面上切换主题
- c# - 'DataTable' 是 'System.Data.DataTable' 和 'Microsoft.Office.Interop.Word.DataTable' 之间的模糊引用
- facebook - Facebook重新提交应用程序以供审核不起作用
- javascript - 使用 css :nth-child 选择器对列表项进行样式设置
- c# - 当 C# 中存在歧义时,始终使用定义的命名空间