我调用的小部件未显示在颤振列中

时间:2020-07-04 11:36:40

标签: android flutter widget

我在方法中调用的小部件未显示在输出中,问题是app,没有警告或错误,但仍未在列中显示映射的小部件... 我尝试为列或其他方式设置容器以显示东西...

小部件:

    return Container(
      width: double.infinity,
      height: 300,
      child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: tr.map((trElemEnt) {
            Card(
              elevation: 5,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  CircleAvatar(
                    radius: 20,
                    child: Text(
                      trElemEnt.price.toString(),
                    ),
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(
                        trElemEnt.title,
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                      Text(
                        trElemEnt.date.toString(),
                        style: TextStyle(fontSize: 10, color: Colors.grey),
                      )
                    ],
                  )
                ],
              ),
            );
          }).toList()),
    );
  } ```


call :

```@override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        trMaker(tr),
      ],
    );
  }
} ```


[--OUTPUT--][1]


  [1]: https://i.stack.imgur.com/8dOrJ.png

1 个答案:

答案 0 :(得分:0)

问题是您没有在地图中返回任何内容。 尝试更换此部分:

...
tr.map((trElemEnt) {
    Card(...);
}
...

与此:

...
tr.map((trElemEnt) {
    return Card(...);
}
...