在 Provider 方法中抛出错误 NoSuchMethod:The getter ' ' was called on null

时间:2021-04-17 08:42:07

标签: json flutter dart null provider

我试图调用一个变量 placeName ,但只返回空值。 NoSuchMethod 错误:在 null 上调用了 getter'placeName'。接收器:空 尝试调用:placeName 好像无法从url读取当前位置!

在我的主页

  GestureDetector(
                          onTap: () async {

                            var response = await Navigator.push(context, MaterialPageRoute(
                                builder:(BuildContext context) => SearchPage()
                            ));

                            if(response == 'getDirection'){
                              showDetailSheet();
                            }

                          },


在我的搜索页面

void searchPlace(String placeName) async {
    if(placeName.length > 1 ){

      String url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$placeName&key=$mapKey&sessiontoken=1234567890&components=country:hu';
      var response = await RequestHelper.getRequest(url);

      if(response == 'failed') {
        return;
      }

      if(response['status'] == 'OK'){
        var predictionsJson = response['predictions'];
        var thisList = (predictionsJson as List).map((e) => Prediction.fromJson(e)).toList();

        setState(() {
        destinationPredictionList = thisList;
        });
      }


      print(response);

    }
  }


@override
  Widget build(BuildContext context) {


      String address = Provider.of<AppData>(context).pickupAddress.placeName ?? '';
      pickupController.text = address;


    return Scaffold(....)

谢谢!

0 个答案:

没有答案