微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我无法使用谷歌搜索地点 API 实现搜索地点

如何解决我无法使用谷歌搜索地点 API 实现搜索地点

import 'package:Flutter/cupertino.dart';
import 'package:Flutter/material.dart';
import 'package:Flutter_google_places/src/Flutter_google_places.dart'
    as googlePlaces;
import 'package:Flutter_google_places/Flutter_google_places.dart';
import 'package:geocoder/geocoder.dart';
import 'package:google_maps_webservice/places.dart';
class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);
  @override
  _HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
  TextEditingController addressController = TextEditingController();
  GoogleMapsPlaces _places =
      GoogleMapsPlaces(apiKey: "_apiKey");
  double lat;
  double lng;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: TextFormField(
          validator: (value) {
            if (value.isEmpty) {
              return 'Please enter a valid address';
            }
            return null;
          },controller: addressController,decoration: Inputdecoration(
            enabledBorder: new OutlineInputBorder(
              borderSide: const BorderSide(color: Colors.grey,width: 1),),focusedBorder: new OutlineInputBorder(
              borderSide: const BorderSide(color: Colors.grey,border: OutlineInputBorder(
              borderSide: const BorderSide(color: Colors.grey,hintText: "Address",labelText: "Address",onTap: () async {
            var prediction = await PlacesAutocomplete.show(
              context: context,apiKey: "ApiKey",logo: Container(),language: 'en',mode: googlePlaces.Mode.overlay,);
            addressController.text = prediction.description;
            displayPrediction(prediction);
          },);
  }
  Future<Null> displayPrediction(p) async {
    if (p != null) {
      PlacesDetailsResponse detail =
          await _places.getDetailsByPlaceId(p.placeId);
      
      double latt = detail.result.geometry.location.lat;
      double lngg = detail.result.geometry.location.lng;
     
      setState(() {
        lat = double.parse(latt.toStringAsFixed(4));
        lng = double.parse(lngg.toStringAsFixed(3));
      });
    }
  }
}`

我无法使用谷歌搜索地点 API 实现搜索地点。我在上面提到了我的代码,请检查它。我还在上面的代码添加了我面临的相应错误的屏幕截图。请帮我解决这个问题。 [请检查我面临的问题的图片]

[ERROR:Flutter/lib/ui/ui_dart_state.cc(186)] 未处理的异常:NoSuchMethodError:getter 'isNotEmpty' 在 null 上被调用。 E/Flutter (31426):接收器:null E/Flutter (31426):尝试调用:isNotEmptyenter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。