颤振:ListView.builder创建列
我正在为一些计数游戏开发一个颤振应用程序。我试图让它工作,一个ListView.builder在一列中显示两个项目,在另一列中显示另外两个项目。但我不知道怎么做。有什么建议吗 这是我的密码:颤振:ListView.builder创建列,listview,flutter,Listview,Flutter,我正在为一些计数游戏开发一个颤振应用程序。我试图让它工作,一个ListView.builder在一列中显示两个项目,在另一列中显示另外两个项目。但我不知道怎么做。有什么建议吗 这是我的密码: import 'dart:math'; import 'package:flutter/material.dart'; class Teams extends StatefulWidget{ final String spieler1; final String spieler2; final
import 'dart:math';
import 'package:flutter/material.dart';
class Teams extends StatefulWidget{
final String spieler1;
final String spieler2;
final String spieler3;
final String spieler4;
Teams({Key key, this.spieler1, this.spieler2, this.spieler3, this.spieler4}) : super(key : key);
@override
State<StatefulWidget> createState() => new TeamsState();
}
class TeamsState extends State<Teams>{
@override
Widget build(BuildContext context) {
var namen = [widget.spieler1, widget.spieler2, widget.spieler3, widget.spieler4];
List<String> erstellt = shuffle(namen);
return new Scaffold(
appBar: new AppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.shuffle),
onPressed: (){setState(() {});}
),
],
),
body: new ListView.builder(
itemCount: namen.length,
itemBuilder: (BuildContext context, int index){
return new ListTile(
title: new Text(erstellt[index]), // <-- content is loading here
);
}
),
);
}
List shuffle(List items) {
var random = new Random();
// Go through all elements.
for (var i = items.length - 1; i > 0; i--) {
// Pick a pseudorandom number according to the list length
var n = random.nextInt(i + 1);
var temp = items[i];
items[i] = items[n];
items[n] = temp;
}
return items;
}
}
import'dart:math';
进口“包装:颤振/材料.省道”;
类团队扩展StatefulWidget{
最终字符串1;
最终字符串Spiler2;
最后的字符串3;
最后一个字符串Spiler4;
团队({Key-Key,this.spieler1,this.spieler2,this.spieler3,this.spieler4}):超级(Key:Key);
@凌驾
State createState()=>新团队状态();
}
类TeamsState扩展状态{
@凌驾
小部件构建(构建上下文){
var namen=[widget.spieler1,widget.spieler2,widget.spieler3,widget.spieler4];
List-erstellt=shuffle(namen);
归还新脚手架(
appBar:新的appBar(
行动:[
图标按钮(
图标:图标(Icons.shuffle),
onPressed:(){setState((){});}
),
],
),
正文:新建ListView.builder(
itemCount:namen.length,
itemBuilder:(构建上下文,int索引){
返回新的ListTile(
标题:新文本(erstellt[index]),//0;i--{
//根据列表长度选择一个伪随机数
var n=随机的nextInt(i+1);
var temp=项目[i];
项目[i]=项目[n];
项目[n]=温度;
}
退货项目;
}
}
我认为您描述的是颤振中的GridView。要实现两列,这是一个您可以做的示例:
GridView.count(
// crossAxisCount is the number of columns
crossAxisCount: 2,
// This creates two columns with two items in each column
children: List.generate(2, (index) {
return Center(
child: Text(
'Item $index',
style: Theme.of(context).textTheme.headline,
),
);
}),
);
你可以在弗利特的网站上读到更多关于它的信息:你能把你想做什么的截图放下来吗?