简体   繁体   English

列的子项不得包含任何 null 值,但在索引 13 处找到 null 值。 Flutter Z866408593C2F8BDF27

[英]Column's children must not contain any null values, but a null value was found at index 13. Flutter Function

I develop an app that reminds elderly about their medication time.我开发了一款提醒老年人服药时间的应用程序。 here they have to select the dose of their medication, such as once a day and twice a day.在这里他们必须给他们服药的剂量,比如一天一次和一天两次。 and I create a function that takes this dose and return fields equals to these times.我创建了一个 function ,它采用这个剂量并返回字段等于这些时间。 such as, if user select 'three times a day', 3 fields will appear to select time.例如,如果用户 select '每天三次',则会出现 3 个字段到 select 时间。

When I run my app, there is an error appears which is:当我运行我的应用程序时,出现以下错误:

Column's children must not contain any null values, but a null value was found at index 13

and I found that error is caused by this function:我发现错误是由这个 function 引起的:

  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;
  }

How can I solve this problem?我怎么解决这个问题?

You can replace all occurences of your dateFormat like:您可以替换所有出现的 dateFormat ,例如:

text: DateFormat('hh:mm').format(updatedTime2),

by经过

text: updatedTime2 != null ? DateFormat('hh:mm').format(updatedTime2) : "",

You cannot give null value to text.您不能将 null 值赋予文本。

This will allow your widget to work until user select a time.这将允许您的小部件工作,直到用户 select 一次。

That's because you don't have a default value when all the if checking is not matching.那是因为当所有if检查都不匹配时,您没有默认值。

You need to add the else part for that.您需要为此添加else部分。 Something like this:像这样的东西:

  Widget time(String value) {
     Widget w;
     if (value == "مرة واحدة في اليوم"){
       w = SizedBox(
         height: 1,
       );
     } else if (...) {
      ///
    
     } else {
       // Add your widget here if all the `if` not matching
       w = Text('No matching');
     }

     return w;
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 函数错误:列的子项不得包含任何空值,但在索引 1 处发现空值 - Flutter function error: Column's children must not contain any null values, but a null value was found at index 1 Flutter 错误列的子项不得包含任何 null 值,但在索引 0 处找到 null 值 - Flutter error Column's children must not contain any null values, but a null value was found at index 0 Flutter 错误:列的子项不得包含任何 null 值,但在索引 0 处找到 null 值 - Flutter error: Column's children must not contain any null values, but a null value was found at index 0 如何解决 Flutter 错误列的子项不得包含任何 null 值,但在索引 0 处找到 null 值? - How to solve Flutter error Column's children must not contain any null values, but a null value was found at index 0? 列的子项不得包含任何 null 值,但在索引 0 处找到 null 值 - Column's children must not contain any null values, but null value was found at index 0 行的子项不得包含任何 null 值,但在索引 2 处找到 null 值 - Row's children must not contain any null values, but a null value was found at index 2 行的孩子不得包含任何 Null 值 Flutter 错误 - Row's Children Must Not Contain Any Null Values Flutter Error Flutter 未处理的异常:无效参数(值):不得为 null - Flutter Unhandled Exception: Invalid argument(s) (value): Must not be null 未处理的异常:无效参数(值):不得为 null Flutter 2 - Unhandled Exception: Invalid argument(s) (value): Must not be null Flutter 2 无效参数(输入):不得为 null - Flutter - Invalid argument(s) (input): Must not be null - Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM