颤动:如何删除 gridview 单元格背景?
FLUTTER: How to remove the gridview cells background?
我尝试将 boxshadow 放入 gridview 内的容器中,但阴影在单元格之外,并且单元格的背景颜色与页面背景颜色不同。我想让我的容器在 gridview 中具有相同的背景颜色和干净的 boxshadow 到我的容器。如果我在 gridview 之外使用它,它会完美运行。这是我的代码:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: Center(
child: FutureBuilder(
future:
Firestore.instance.collection('rooms').document(pincode).get(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
nomines = snapshot.data['Nominés'];
thequestion = snapshot.data['Question'].toString();
return Column(children: <Widget>[
Text(thequestion),
Expanded(
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('rooms')
.document(pincode)
.collection('users')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData)
return Text("Chargement....");
else {
return new GridView.count(
crossAxisCount: 2,
children: snapshot.data.documents
.map((DocumentSnapshot document) {
if (document['id'] == nomines[0] ||
document['id'] == nomines[1])
return Container(
child: InkWell(
onTap: () {
vote(document['id']).then((a) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Waitresults(),
));
});
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 2.0, color: Color(document['couleur'])),
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(document['couleur']),
blurRadius: 0,
offset: Offset(7, 3))
],
shape: BoxShape.circle),
child: OvalPic(document['photo'],
document['couleur']),
),
),
);
else
return null;
}).toList()
..removeWhere((el) => el == null));
}
},
),
)
]);
} else
return CircularProgressIndicator();
},
),
),
);
}
您可以将 gridView
包裹在 container
中,然后在 container
中使用 属性 color
来更改背景颜色。
Container(
color : Colors.black,
child : GridView.count(
.....
),
)
),
我尝试将 boxshadow 放入 gridview 内的容器中,但阴影在单元格之外,并且单元格的背景颜色与页面背景颜色不同。我想让我的容器在 gridview 中具有相同的背景颜色和干净的 boxshadow 到我的容器。如果我在 gridview 之外使用它,它会完美运行。这是我的代码:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: Center(
child: FutureBuilder(
future:
Firestore.instance.collection('rooms').document(pincode).get(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
nomines = snapshot.data['Nominés'];
thequestion = snapshot.data['Question'].toString();
return Column(children: <Widget>[
Text(thequestion),
Expanded(
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('rooms')
.document(pincode)
.collection('users')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData)
return Text("Chargement....");
else {
return new GridView.count(
crossAxisCount: 2,
children: snapshot.data.documents
.map((DocumentSnapshot document) {
if (document['id'] == nomines[0] ||
document['id'] == nomines[1])
return Container(
child: InkWell(
onTap: () {
vote(document['id']).then((a) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Waitresults(),
));
});
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 2.0, color: Color(document['couleur'])),
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(document['couleur']),
blurRadius: 0,
offset: Offset(7, 3))
],
shape: BoxShape.circle),
child: OvalPic(document['photo'],
document['couleur']),
),
),
);
else
return null;
}).toList()
..removeWhere((el) => el == null));
}
},
),
)
]);
} else
return CircularProgressIndicator();
},
),
),
);
}
您可以将 gridView
包裹在 container
中,然后在 container
中使用 属性 color
来更改背景颜色。
Container(
color : Colors.black,
child : GridView.count(
.....
),
)
),