【发布时间】:2020-01-23 21:47:23
【问题描述】:
我是新来的颤振。以下是我从名为posts的firestore集合中获取数据的代码。第一次加载应用程序时的问题是加载数据需要几秒钟,直到它显示一个空白屏幕。它只发生在第一次。那么如何显示加载微调器或用户的东西,直到数据被加载? (并不是说这不是全部代码)
class ForumHome extends StatefulWidget {
@override
_ForumHomeState createState() => _ForumHomeState();
}
dbMethods dbcrud = new dbMethods();
class _ForumHomeState extends State<ForumHome> {
String title, content;
//Subscribing for post details
StreamSubscription<QuerySnapshot> subscription;
List<DocumentSnapshot> snapshot;
CollectionReference collectionReference =
Firestore.instance.collection("posts");
@override
void initState() {
super.initState();
subscription = collectionReference.snapshots().listen((datasnapshot) {
setState(() {
snapshot = datasnapshot.documents;
});
});
}
@override
Widget build(BuildContext context) {
int num = snapshot?.length ?? 0;
return Scaffold(
appBar: AppBar(title: Text('Idea Forum '), backgroundColor: Colors.pink),
body: new ListView.builder(
itemCount: num,
itemBuilder: (context, index) {
return new Card(
elevation: 15.0,
margin: EdgeInsets.all(10.0),
child: new ListTile(
onTap: () {
//For udating the view count
snapshot[index]
.reference
.updateData({'Views': snapshot[index].data['Views'] + 1});
【问题讨论】:
标签: android firebase flutter dart google-cloud-firestore