当我的应用程序启动时,firebase的帖子不会显示在我的时间线上,除非通过刷新

当我的应用程序启动时,firebase的帖子不会显示在我的时间线上,除非通过刷新,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我试图从firebase中检索用户的帖子,并将其显示在我的时间线上。 我现在面临的问题是,当我的应用程序启动时,帖子不会立即显示,除非页面刷新(此处使用RefreshIndcator()),而且我确实调用函数在initState函数中获取帖子 这是获取帖子的函数 retrieveTimeLine()async{ List <Post>posts=[]; ///Get post of my followings for(int i=0;i<follow

我试图从firebase中检索用户的帖子,并将其显示在我的时间线上。 我现在面临的问题是,当我的应用程序启动时,帖子不会立即显示,除非页面刷新(此处使用RefreshIndcator()),而且我确实调用函数在initState函数中获取帖子

这是获取帖子的函数

 retrieveTimeLine()async{
    List <Post>posts=[];

    ///Get post of my followings
    for(int i=0;i<followingList.length;i++){
      QuerySnapshot querySnapshot= await Firestore.instance.collection('posts/${followingList[i]}/usersPosts').orderBy('timestamp',descending:true).getDocuments();
       posts+=querySnapshot.documents.map((document) =>Post.fromDocument(document)).toList();
    }
    setState(() {
    this.posts=posts;
    });
  }

这是我的刷新指示器

 Widget build(context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: header(context,isAppTitle: true),
      body:RefreshIndicator(
          color: Colors.orange,
          child: createTimeLine(),
          onRefresh:()=> retrieveTimeLine())
    );
  }

这里有几个问题,您是否用@override覆盖initState?还有为什么你不等待querysnapshot?有没有什么特别的理由不填写.then((result)=>)中的posts变量?我认为这可能是一个同步问题
 Widget build(context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: header(context,isAppTitle: true),
      body:RefreshIndicator(
          color: Colors.orange,
          child: createTimeLine(),
          onRefresh:()=> retrieveTimeLine())
    );
  }