使用while循环重复3个小部件。扑朔迷离

时间:2020-09-29 15:32:32

标签: loops flutter for-loop while-loop

我想用索引值从1到n重复以下代码。如何在颤抖中做到这一点?

return ListView(
  children: <Widget>[
    SizedBox(
      height: 15.0,
    ),
    new Image.asset(
      "assets/$name/$index.jpg",
      fit: BoxFit.cover,
    ),
    SizedBox(
      height: 10.0,
    ),
    Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Text("$name $index",
            style: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 23,
                fontFamily: 'Raleway',
                color: Colors.black)),
        Container(
          margin: EdgeInsets.only(left: 100.0),
          width: 150.0,
          height: 50.0,
          child: FlatButton(
            onPressed: null,
            child: Text('Download',
                style: TextStyle(color: Colors.black, fontSize: 20)),
            textColor: Colors.white,
            shape: RoundedRectangleBorder(
                side: BorderSide(
                    color: Colors.teal, width: 2, style: BorderStyle.solid),
                borderRadius: BorderRadius.circular(50)),
          ),
        ),
      ],
    ),
  ],
);

2 个答案:

答案 0 :(得分:0)

使用while循环显示3次简单文本。

 Widget getWidgets() {
    List<Widget> list = new List<Widget>();
    int i = 0;
    while (i < 3) {
        list.add(new Text(strings[i]));
        i++;
    }
    return Row(children:list);
}

答案 1 :(得分:0)

您可以在下面复制粘贴运行完整代码
您可以将Auth.signInListView.builder结合使用,并包装itemCount
代码段

Column

工作演示

enter image description here

完整代码

ListView.builder(
          itemCount: 10,
          itemBuilder: (BuildContext ctxt, int index) {
            return Column(
              children: <Widget>[