[英]FLUTTER: How to change background color inside a gridview?
我在颤动中使用 gridview 并且遇到问题,屏幕的背景颜色是黑色但是当我返回 gridview 时,单元格的背景颜色是白色的。 我想更改单元格的背景颜色。 我尝试将 gridview 移动到容器内并添加一个 Boxdecoration 但它不起作用,你能帮我吗? 有我的代码:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: Center(
child: Column(
children: <Widget>[
conseil(text, lien),
SizedBox(height: 20,),
Text("GAME PIN", style: TextStyle(fontSize: 40),),
Container(
padding: EdgeInsets.fromLTRB(30, 10, 30, 10),
decoration: BoxDecoration(
border: Border.all(width: 2.0, color: Color(0xffa8277b)),
borderRadius: BorderRadius.circular(15),
),
child: Text(id, style: TextStyle(fontSize: 30),)),
Expanded(
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('rooms')
.document(id)
.collection('users')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData)
return Text("Chargement....");
else {
return GridView.count(
crossAxisCount: 6,
children: snapshot.data.documents
.map((DocumentSnapshot document) {
return OvalPic(
document['photo'], document['couleur']);
}).toList());
}
},
),
),
button(mypink, 'COMMENCER', context),
SizedBox(height: 15,)
],
),
),
);
}
将它包装在一个Container
并为其添加color
应该可以做到,
return Container(
color: Colors.black,
child: GridView.count(
crossAxisCount: 4,
children: snapshot.data.documents
.map((DocumentSnapshot document) {
return OvalPic(
document['photo'], document['couleur']);
}).toList()));
我能够使用高程属性删除网格平铺背景颜色。 我试过如下,
GridTile(
child: new Card(
elevation: 0,
color: Colors.transparent,
child:Text('Sample')))
分享这个,因为它以后可能有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.