作者:书友48919914 | 来源:互联网 | 2022-12-11 21:44
我正在开发用于某些计数游戏的flutter应用程序。我正在尝试使其工作,一个ListView.builder在一个列中显示两个项目,在另一列中显示其他两个项目。但是我不知道该怎么做。有什么建议么?
这是我的代码:
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 createState() => new TeamsState();
}
class TeamsState extends State{
@override
Widget build(BuildContext context) {
var namen = [widget.spieler1, widget.spieler2, widget.spieler3, widget.spieler4];
List erstellt = shuffle(namen);
return new Scaffold(
appBar: new AppBar(
actions: [
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;
}
}
Adrian Avram..
5
我认为您所描述的是扑朔迷离的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,
),
);
}),
);
您可以在Flutter的网站上了解有关它的更多信息:https : //flutter.io/cookbook/lists/grid-lists/
1> Adrian Avram..:
我认为您所描述的是扑朔迷离的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,
),
);
}),
);
您可以在Flutter的网站上了解有关它的更多信息:https : //flutter.io/cookbook/lists/grid-lists/