我是Flutter的初学者,我有4个Listview,它们在屏幕上可见一些条件,并且将它们添加到SilverLists的CustomScrollView中,但是由于某些原因,我的屏幕无法滚动。这是我的代码:
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: PreferredSize( //code for preferred size
drawer: Drawer( //code for drawer
body: Container(
child: StreamBuilder<DocumentSnapshot>(
stream: Firestore.instance
.collection('users')
.document(widget._user.uid)
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Error : ${snapshot.error}');
} else if (snapshot.hasData) {
List<bool> t = checksub(snapshot.data);
print(t.length);
print(t);
return showEvents(t);
}
return LinearProgressIndicator();
}),
));
}
List<bool> checksub(DocumentSnapshot snapshot) {
if (snapshot.data['t1'] == true) {
arr[0] = true;
} else
arr[0] = false;
if (snapshot.data['t2'] == true) {
arr[1] = true;
} else
arr[1] = false;
if (snapshot.data['t3'] == true) {
arr[2] = true;
} else
arr[2] = false;
if (snapshot.data['t4'] == true) {
arr[3] = true;
} else
arr[3] = false;
return arr;
}
Widget showEvents(List<bool> t) {
return Container(
child: CustomScrollView(
scrollDirection: Axis.vertical,
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
[if (t[0] == true) sss1()]
),
),
SliverList(
delegate: SliverChildListDelegate(
[if (t[1] == true) sss2()],
),
),
SliverList(
delegate: SliverChildListDelegate(
[if (t[2] == true) sss3()],
),
),
SliverList(
delegate: SliverChildListDelegate(
[if (t[3] == true) sss4()],
),
),
],
));
}
Widget sss1(){
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('notifications')
.where('Category', isEqualTo: 't1')
.orderBy('createdAt', descending: true)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) return Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Text('Loading...');
default:
return Expanded(
child: ListView(
shrinkWrap: true,
children:
snapshot.data.documents.map((DocumentSnapshot document) {
return Card(
color: Color(0xffffffff),
child: CustomCard(
title: document['Title'],
description: document['Body'],
//topic: document['Topic'],
context: context,
isAdmin: false,
ndate: document['Date'],
stime: document['Time'],
url: document['URL'],
desc: document['Description'],
),
);
}).toList(),
));
}
},
),
);
}
sss2()
,sss3()
,sss4()
与小部件sss1()
完全相似,除了firestore.collection
中的一个条件。