[英]Flutter: How to add a button widget at the end of a ListView.builder that contains other type of widgets?
[英]How can I delete spaces between custom widgets and fit widgets in listview.builder in flutter
我正在制作一个带有颤振的纸牌游戏。 我想在游戏桌上以连续的顺序展示我的牌。 我为卡片制作了一个自定义小部件,并将它们放在 listview.builder 中。 卡片之间出现空间并且卡片不适合屏幕。 我在互联网上搜索了这个问题,但没有解决。 我的错在哪里? 你能帮助我吗?
CardViewWidget:
Widget cardViewWidget(PlayingCard card) {
return Container(
height: 80.0,
width: MediaQuery.of(context).size.width / 5,
color: Colors.red,
child: Column(
children: <Widget>[
Text(
_returnAssetUrl(card),
style: TextStyle(fontSize: 15.0),
),
],
),
);}
建造:
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Text(
oppoHand[0].cardType.toString() +
oppoHand[0].cardSuit.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[1].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[2].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[3].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[4].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
],
),
),
Container(
child: Text("Score: " + oppoScore.toString()),
),
Container(
child: Column(children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: groundDeck.length,
itemBuilder: (BuildContext context, int index) {
return Text(groundDeck[index].cardType.toString());
},
),
]),
),
Container(
child: Text("Score: " + myScore.toString()),
),
Container(
height: 100.0,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[
ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: myHand.length,
itemBuilder: (BuildContext context, int index) {
return FlatButton(
onPressed: () {
setState(() {
_clickedCard(index);
});
},
child: cardViewWidget(myHand[index]),
);
}),
],
),
),
],
),
),
);}}
这是我的屏幕:在此处输入图像描述
运行这个。 这将解决您的问题!
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Text(
oppoHand[0].cardType.toString() + oppoHand[0].cardSuit.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[1].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[2].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[3].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
Text(
oppoHand[4].cardType.toString(),
style: TextStyle(fontSize: 20.0),
),
],
),
),
Container(
child: Text("Score: " + oppoScore.toString()),
),
Container(
child: Column(children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: groundDeck.length,
itemBuilder: (BuildContext context, int index) {
return Text(groundDeck[index].cardType.toString());
},
),
]),
),
Container(
child: Text("Score: " + myScore.toString()),
),
Container(
height: 100.0,
width: MediaQuery.of(context).size.width,
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: myHand.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
setState(() {
_clickedCard(index);
});
},
child: cardViewWidget(myHand[index]),
);
}),
),
],
),
),
);
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.