Пользовательский поиск с автозаполнением google api flutter - PullRequest
0 голосов
/ 03 августа 2020

У меня есть приложение flutter с местоположением поиска, я пытаюсь использовать flutter_google_places api. Но оно не работает должным образом. Если я использую функцию в контейнере, появится всплывающее окно с полем поиска, если я пытаюсь интегрироваться в текстовое поле, оно не работает

Это то, что я пытаюсь сделать

Просмотр

            Padding(
                padding: EdgeInsets.only(top: 15),
                child: GestureDetector(
                  child: Container(
                    height: 45,
                    width: 320,
                    child: TextField(
                      controller: _searchplacetextController,
                      decoration: InputDecoration(
                          border: OutlineInputBorder(),
                          hintText: "Enter Search Location",
                          contentPadding: EdgeInsets.all(10),
                          prefixIcon: Icon(
                            Icons.search,
                            color: Color.fromRGBO(34, 83, 148, 1),
                          )),
                    ),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        color: Colors.greenAccent),
                  ),
                  onTap: () async {
                    map_service.Prediction p =
                        await google_place.PlacesAutocomplete.show(
                            mode: google_place.Mode.overlay,
                            context: context,
                            apiKey: kGoogleApiKey);
                    displayPrediction(p);
                  },
                ),
              )

функция

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

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

      var address = detail.result.formattedAddress;
      SharedPrefrence().setLatitude(latitude.toString());
      SharedPrefrence().setLongitude(longitude.toString());

      setState(() {
        _searchplacetextController= address;
      });
    }
  }
...