无法在Navigator(...)中加载Firestore数据。

时间:2019-04-01 00:30:00

标签: flutter google-cloud-firestore

尝试从

调用构建方法
     onTap: (){
    Navigator.of(context).push(
    MaterialPageRoute(builder: (context) => 
   AtendimentoPendingScreen(snapshot)))
    .whenComplete(buildAgenda(context));
    },

出现此错误:

FutureBuilder<QuerySnapshot>' is not a subtype of type '() => FutureOr<dynamic>'

以下是相关代码:

class AgendaTab extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return buildAgenda(context);
  }
}
buildAgenda(context){

    return FutureBuilder<QuerySnapshot>(
      future: Firestore.instance.collection("Agenda").where("proid",isEqualTo: uid).where("atendido",isEqualTo:false).orderBy('datum').getDocuments(),
      builder: (context, snapshot) {
        if (!snapshot.hasData)
          return Center(
            child: CircularProgressIndicator(),
          );
        else {
          var dividedTiles = ListTile
              .divideTiles(
              tiles: snapshot.data.documents.map((doc) {
                return AgendaTile(doc);
              }).toList(),
              color: Colors.grey[500])
              .toList();

          return ListView(
            children: dividedTiles,
          );
        }
      },
    );
  }

  class AgendaTile extends StatelessWidget {
  final DocumentSnapshot snapshot;

  AgendaTile(this.snapshot);
  @override
  Widget build(BuildContext context) {

    return 
       Padding(padding: EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0),
        child:ListTile(

leading: Container(
  width: 80.0,
  height: 80.0,
  decoration: new BoxDecoration(
    shape: BoxShape.circle,
    image: new DecorationImage(
      fit: BoxFit.fill,
      image: new CachedNetworkImageProvider(snapshot.data["icon"]),
    ),
  ),
),
      title: Text(snapshot.data["paciente"],style:TextStyle(fontSize: 18.0,fontWeight: FontWeight.bold,),),
      subtitle: Text(snapshot.data["diaHora"],style:TextStyle(fontSize: 16.0,),),
      trailing: Icon(Icons.keyboard_arrow_right),
      onTap: (){
 Navigator.of(context).push(
                MaterialPageRoute(builder: (context) => AtendimentoPendingScreen(snapshot)))
                .whenComplete(buildAgenda(context));
      },
    ),

    );
  }
}

我只希望在按AtendimentoPendingScreen上的“后退”按钮时刷新数据,因为数据是由AtendimentoPendingScreen更改的。

当我删除.whenComplete(buildAgenda(context))时,一切正常,但是当弹出AtendimentoPendingScreen时,数据不会刷新。

0 个答案:

没有答案