繁体   English   中英

我的 flutter 应用程序中出现此错误,您能告诉我如何解决吗?

[英]I have this error in my flutter app, can you tell how to fix it?

======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building SearchScreen(dirty, dependencies: [_InheritedProviderScope<AppData>], state: _SearchScreenState#1ae7b):
The getter 'placeName' was called on null.
Receiver: null
Tried calling: placeName

The relevant error-causing widget was: 
  SearchScreen file:///C:/Users/HECTOR/StudioProjects/catdog_app/lib/AllScreens/mainscreen.dart:206:107

**line 206:**

 GestureDetector(
                          onTap: () async
                          {

                            var res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>SearchScreen()));

                            if(res == "obtainDirection")
                              {
                                await getPlaceDirection();
                              }
                           },

**dart file searchScreen:**

oid getPlaceAddressDetails(String placeId, context) async{

    showDialog(context: context,
        builder: (BuildContext context) => ProgressDialog(message: "Setting DropOff, Please wait ...",)
    );

    String placeDetailsUrl = "https://maps.googleapis.com/maps/api/place/details/json?place_id=$placeId&key=$mapKey";

    var res = await RequestAssistant.getRequest(Uri.parse(placeDetailsUrl));

    Navigator.pop(context);

    if(res == "failed"){

      return;

    }

    if(res["status"] == "OK")
    {

      Address address = Address();
      address.placeName = res["result"]["name"];
      address.placeId = placeId;
      address.latitude = res["result"]["geometry"]["location"]["lat"];
      address.longitude = res["result"]["geometry"]["location"]["lng"];

      Provider.of<AppData>(context, listen: false).updateDropOffLocationAddress(address);
      print("This is Drop Off Location ::");
      print(address.placeName);

      Navigator.pop(context, "obtainDirection");
    }

  }

@朱利安。

根据错误日志,它说在 null object 上调用了地名。 这意味着您在代码中初始化的地址 object 变成 null 因此您可以在 log-cat 中查看这些错误日志。

因此,请更正应用程序代码中Address address = Address()的实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM