如何解决在 Provider 方法中抛出错误 NoSuchMethod:The getter ' ' was called on null
我试图调用一个变量 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(....)
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。