在flutter中获取initState()中的空值调用方法

时间:2020-02-05 18:38:27

标签: flutter google-cloud-firestore

   // I called widget from widget
   Navigator.of(context).pushNamed('/placebids', arguments: {
  'ProductId': productDocumentId,
  'ProductName': productName,

});


String productId, productName ;

  @override
 void initState() {
   super.initState();
   _fetchBidofAllTheUsersForCompare();
  }

 Future<void> _fetchBidofAllTheUsersForCompare() async {
 final QuerySnapshot _dbr = 
    await Firestore.instance.collection("Pro-$productName-$productId").getDocuments();
    List<DocumentSnapshot> templist;
  templist = _dbr.documents;
  List<Map<dynamic, dynamic>> list = new List();
  list = templist.map((DocumentSnapshot ds) {
      return ds.data;
  }).toList();
    list.forEach((item) => {
      item.forEach((key, value) => {
        print(value)

  })
});

}

Widget build(BuildContext context) {
final routeArguments =
    ModalRoute.of(context).settings.arguments as Map<String, String>;
productId = routeArguments['ProductId'];
productName = routeArguments['ProductName'];
return Scaffold();
}

当我尝试在initState()中调用该方法时,获取ProductId和ProductName的空值;如果我在Widget中收到这些值,那么如何在initState方法中使用它

1 个答案:

答案 0 :(得分:0)

我也遇到过类似的空值问题,即使用DocumentSnapshot时的空值问题

final DocumentSnapshot_dbr = 
    await Firestore.instance.collection("Pro-$productName-$productId").getDocuments();

documentsnapshot_dbr