简体   繁体   English

当我搜索地址时,Flutter google 自动完成没有显示任何内容,有关如何修复它的任何想法?

[英]Flutter google places autocomplete nothing displayed when I search an address, any idea on how to fix it?

I am new in flutter and I need your help on a subject.我是颤振的新手,我需要你的帮助。 I have implemented the google_places_autocomplete package in my flutter app.我已经在我的 flutter 应用程序中实现了google_places_autocomplete包。 The problem is that when I tap an adress nothing displayed on the screen.问题是当我点击一个地址时,屏幕上没有显示任何内容。 The error displayed in my console can be read below:我的控制台中显示的错误可以在下面阅读:

forwardStream.runCatching (package:rxda<…> [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value forwardStream.runCatching (package:rxda<…> [VERBOSE-2:ui_dart_state.cc(209)] 未处理的异常:对空值使用空检查运算符

** I am using last flutter version, flutter_google_places: ^0.3.0 and geocoder: ^0.2.1 **我使用的是最后一个 flutter 版本,flutter_google_places: ^0.3.0 和 geocoder: ^0.2.1

    enum MobileVerificationState {
  SHOW_MOBILE_FORM_STATE, // The user provides the phone number
  SHOW_OTP_FORM_STATE // The user has to enter the code he received
}

class RegisterScreen2 extends StatefulWidget {
  final UsersInformations user;

  const RegisterScreen2(this.user);

  @override
  _RegisterScreen2State createState() => _RegisterScreen2State();
}

class _RegisterScreen2State extends State<RegisterScreen2> {
   @override

  void initState(){
  super.initState();
  _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);
}

  final kGoogleApiKey = "MY IPA KEY";
  GoogleMapsPlaces _places;

  final addressController = TextEditingController();
  final TextEditingController _textEditingController = TextEditingController();

....... ......

  getMobileFormWidget(context, user) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Form(
        child: SingleChildScrollView(
          child: Column(
            children: [
              Stack(
                children: [
                  Container(
                    height: 100,
                    decoration: BoxDecoration(
                        color: Colors.green.shade50,
                        borderRadius: const BorderRadius.only(
                            bottomLeft: Radius.circular(30),
                            bottomRight: Radius.circular(30))),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 70),
                    child: Stack(
                      // ignore: prefer_const_literals_to_create_immutables
                      children: [
                        Center(
                          child: CircleAvatar(
                            radius: 60,
                            backgroundColor: Colors.white,
                            backgroundImage: image != null
                                ? FileImage(image)
                                : const NetworkImage(
                                    "https://cdn-icons-png.flaticon.com/512/1177/1177568.png"),
                          ),
                        ),
                        Positioned(
                            bottom: -5,
                            right: 145,
                            child: InkWell(
                                onTap: () => getImage(),
                                child: Icon(Icons.camera_alt_rounded)))
                      ],
                    ),
                  ),
                ],
              ),
              const SizedBox(
                height: 20,
              ),
              Padding(
                padding: const EdgeInsets.all(10.0),
                child: Padding(
                  padding: EdgeInsets.only(left: 15, right: 15, top: 5),
                  child: TextFormField(
                  controller: addressController,
                    decoration: InputDecoration(
                      enabledBorder: UnderlineInputBorder(
                          borderSide: BorderSide(color: Colors.grey.shade300)),
                      focusedBorder: UnderlineInputBorder(
                          borderSide:
                              BorderSide(color: Colors.deepPurple.shade900)),
                      focusedErrorBorder: UnderlineInputBorder(
                          borderSide: BorderSide(color: Colors.red.shade900)),
                      errorBorder: UnderlineInputBorder(
                          borderSide: BorderSide(color: Colors.red.shade900)),
                      hintText: "Adresse",
                    ),
                    onChanged: (val) async {
                      Prediction p = await PlacesAutocomplete.show(
                          context: context,
                          apiKey: kGoogleApiKey,
                          mode: Mode.overlay, // Mode.fullscreen
                          language: "fr",
                          components: [
                            new Component(Component.country, "fr"),
                          ]);
                      displayPrediction(p);

                      user.setAdress = val;
                    },
                  ),
                ),
              ),

......... …………

Future<Null> displayPrediction(Prediction p) async {
    if (p != null) {
      PlacesDetailsResponse detail =
          await _places.getDetailsByPlaceId(p.placeId);

      var placeId = p.placeId;
      double lat = detail.result.geometry.location.lat;
      double lng = detail.result.geometry.location.lng;

      var address = await Geocoder.local.findAddressesFromQuery(p.description);

      print(lat);
      print(lng);
    }
  }

全屏模式下不显示任何内容

覆盖模式相同,没有显示

Remove this condition check.删除此条件检查。 if (p != null)

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

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