我无法使用谷歌搜索地点 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 (将#修改为@)