gpt4 book ai didi

gridview - 如何跳过项目构建器gridview.builder Flutter Firebase Stream Builder中的构建

转载 作者:行者123 更新时间:2023-12-02 02:45:01 25 4
gpt4 key购买 nike

我想删除一些firebase,并且当Streambuilder(gridview.builder)到达它的索引(该索引将为空)时,它将忽略它,并且不在该插槽中添加任何小部件并将其保留给其他人使用

这看起来像

App Screenshot

我希望左侧和右侧的空白区域消失,而其他小部件代替它

Firebase数据库镜像

Database Image

 classList(userUid) {
print("user uid: $userUid");
return StreamBuilder(
stream: FirebaseDatabase.instance
.reference()
.child("user")
.child(userUid)
.child("classData")
.onValue,
builder: (BuildContext context, AsyncSnapshot<Event> snapshot) {
if (snapshot.hasData) { // Map<dynamic, dynamic> map = snapshot.data.snapshot.value; // snapshot.data.snapshot.value.forEach((dynamic, v) => print(v["className"]));
if (snapshot.data.snapshot.value != null) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemCount: snapshot.data.snapshot.value.toList().length,
padding: EdgeInsets.all(2.0),
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
RandomColor _randomColor = RandomColor();

Color _color = _randomColor.randomColor(
colorBrightness: ColorBrightness.veryLight);

Color _color2 = _randomColor.randomColor(
colorBrightness: ColorBrightness.veryDark);
if (snapshot.data.snapshot.value.toList()[index] != null) {
return Container(
child: RaisedButton(
splashColor: _color2,
color: _color,
shape: SuperellipseShape(
borderRadius: BorderRadius.circular(90)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ClassPage(
className: snapshot.data.snapshot.value
.toList()[index]["className"]
.toString()
.toUpperCase(),
classSection: snapshot
.data.snapshot.value
.toList()[index]["classSection"]
.toString()
.toUpperCase(),
classIndex: snapshot.data.snapshot.value
.toList()[index],
)));
},
child: Text(
"${snapshot.data.snapshot.value.toList()[index]["className"].toString().toUpperCase()} \n ${snapshot.data.snapshot.value.toList()[index]["classSection"].toString().toUpperCase()}",
style: TextStyle(fontSize: 20, shadows: [
Shadow(
// bottomLeft
offset: Offset(-1.5, -1.5),
color: Colors.black),
Shadow(
// bottomRight
offset: Offset(1.5, -1.5),
color: Colors.black),
Shadow(
// topRight
offset: Offset(1.5, 1.5),
color: Colors.black),
Shadow(
// topLeft
offset: Offset(-1.5, 1.5),
color: Colors.black),
]),
),
),
padding: EdgeInsets.all(4.0),
);
} else {
return Visibility(
child: Text("Gone"),
visible: false,
);
}
},
);
}
return Center(
child: Text(
"No Class Registered",
style: TextStyle(fontSize: 42),
));
} else {
return CircularProgressIndicator();
}
}); }

最佳答案

我解决的方法是在网格中使用这些空白区域,是在网格中使用小部件之前对其进行过滤:
List visibleWidgets = allWidgets.where((widget) => widget.show == true).toList();

关于gridview - 如何跳过项目构建器gridview.builder Flutter Firebase Stream Builder中的构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55815964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com