首页 文章

如果案件在Widget内部不起作用[Flutter]

提问于
浏览
0

如果在Widget内部的情况下我不能写,以便选择显示哪个Container?

我的代码:

return Card(
          child: Container(
              child: Row(
        children: <Widget>[
          Container(
              width: 50.0,
              height: 50.0,
              decoration: new BoxDecoration(
                  shape: BoxShape.circle,
                  image: new DecorationImage(
                      fit: BoxFit.fill,
                      image: new NetworkImage(
                          hits[index]["b"]["c"])))),
          hits[index]["f"] == null
              ? Container(
                  child: Text("if"),
                )
              : Container(
                  child: Text("else"),
                )
        ],
      )));

当我做像up这样的事情时,它会立即出错 .

错误:

flutter:抛出另一个异常:'package:flutter / src / widgets / text.dart':断言失败:第213行pos 15:'data!= null':不是真的 .

1 回答

  • 0

    这应该工作,你可以在颤动中进行条件渲染 .

    例:

    Card(
        child: Container(
          child: Row(
            children: <Widget>[
              Container(
                width: 50.0,
                height: 50.0,
                color: Colors.red,
              ),
              data == null
                  ? Container(
                      child: Text("if"),
                    )
                  : Container(
                      child: Text("else"),
                    )
            ],
          ),
        ),
      ),
    

    希望这可以帮助!

相关问题