gpt4 book ai didi

gridview - Flutter 中的动态 GridView 列表 UI

转载 作者:IT王子 更新时间:2023-10-29 07:21:04 26 4
gpt4 key购买 nike

我的设计是这样的:

Want to achieve

我一直在阅读关于 GridView 的文章,发现它很复杂,无法得到结果。我在这里也关注了这个问题:Flutter - Layout a Grid .发现这是针对固定列表的,加上列表有不同的 UI。

我有来自 API 的信息,我有一个名为 MoreInfo() 的小部件,它有一个要从 API 传递的文本参数。

我已经实现了我想要从列表中获取字符串的目的。只是我试图得到结果但没有很好地给出结果。

将列表添加到小部件:

GridView getOtherInfo(BuildContext context){
List<String> _yesElems = [];
List<Widget> _widget = [];

this.userBarModel.barModel.otherInfo.yes.forEach((item){
_yesElems.add(item);
});

_yesElems.forEach((o){
_widget.add(MoreInfoWidget(text: o));
});

return GridView.count(
crossAxisCount: 4,
children: _widget
);
}

用户界面代码:

Column(
corssAxisalignment: CrossAxisAlignment.stretch;
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 9.0),
child: Text("MORE INFO",
style: TextStyle(color: Color.fromRGBO(183, 193, 203, 1), fontWeight: FontWeight.bold, fontSize: 11.0))
),
SizedBox(height: 11.4),
Container(
height: 140,
child: getOtherInfo(context)
)
]
)

我现在得到的结果是:

Image I'm getting

我想得到上述结果。 UI 中添加了内置的顶部填充。我不知道为什么。伙计们,你能帮帮我吗?

我尝试使用 crossAixCount: 2,但 UI 变成了空白。任何帮助,将不胜感激。谢谢:)

最佳答案

也许我没听懂,你能试试这段代码吗,它会提示你如何按照你的方式去做,如果这就是你要找的,请告诉我。

List<int> _list = [];

math.Random random = math.Random();

@override
void initState() {
super.initState();

Timer.periodic(Duration(milliseconds: 1000), (timer) {
_list.add(random.nextInt(100));
setState(() {});
});
}

Widget build(context) {
return Scaffold(
appBar: AppBar(),
body: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 160,
childAspectRatio: 3,
children: _list.map((value) {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.all(8),
decoration: BoxDecoration(border: Border.all(color: Colors.black),),
child: Text("Item ${value}"),
);
}).toList(),
),
);
}

enter image description here

关于gridview - Flutter 中的动态 GridView 列表 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55631275/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com