GithubHelp home page GithubHelp logo

Comments (6)

manvirrr avatar manvirrr commented on August 14, 2024 1

I think it would be better to make fields a required parameter.

from flutter_google_places_sdk.

matanshukry avatar matanshukry commented on August 14, 2024

@manvirrr What platform are you using? do you have any more relevant logs? If not, please provide a reproducible example.

from flutter_google_places_sdk.

manvirrr avatar manvirrr commented on August 14, 2024

Hi Matan,

i am using Flutter 3.0.4 with Dart 2.17.5 on Macbook M1 pro and Macbook Pro 16 Intel variant. It's the same error on both the machines.

flutter: FlutterGooglePlacesSdk::call error: PlatformException(API_ERROR, The operation couldn’t be completed. An internal error occurred in the Places SDK library. If you believe this error represents a bug, please file a report using the instructions on our community and support page (https://developers.google.com/places/ios-sdk/support)., null, null)
[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: PlatformException(API_ERROR, The operation couldn’t be completed. An internal error occurred in the Places SDK library. If you believe this error represents a bug, please file a report using the instructions on our community and support page (https://developers.google.com/places/ios-sdk/support)., null, null)

I am able to get the list of Predictions using the package but when I pass the PlaceId to fetchPlace function, I get the above error.

So following is the base..

void initState() {
// TODO: implement initState
super.initState();
_googlePlaces = FlutterGooglePlacesSdk(key);
}

Autocomplete(
optionsBuilder: (textEditingValue) async {
if (textEditingValue.text.length > 2) {
final FindAutocompletePredictionsResponse
predictions = await _googlePlaces
.findAutocompletePredictions(
textEditingValue.text,
countries: ['PL'],
newSessionToken: false);
//print(predictions);
return predictions.predictions;
}

                          // final String request =
                          //     "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=${textEditingValue.text}&components=country:PL&key=${key}&sessiontoken=${sessionId}";
                          // final result = await client
                          //     .get(Uri.parse(request), headers: {
                          //   "referer": dotenv.env['HTTPREF']!,
                          //   "origin": dotenv.env['HTTPREF']!
                          // });
                          // print("${sessionId} - ${result.body}");
                          // if (result.statusCode == 200) {
                          //   return [result.body];
                          // }
                          return [];
                          //return jsonDecode(request)["predictions"];
                        },
                        fieldViewBuilder: (
                          BuildContext context,
                          TextEditingController mapSearch,
                          FocusNode mapFocusNode,
                          VoidCallback onFieldSubmit,
                        ) {
                          return TextFormField(
                            controller: mapSearch,
                            onChanged: (value) {},
                            onTap: () => setState(() {
                              searchHasFocus = true;
                            }),
                            decoration: const InputDecoration(
                              border: InputBorder.none,
                              contentPadding: EdgeInsets.only(
                                  left: 38, top: 0, bottom: 5),
                            ),
                            focusNode: mapFocusNode,
                            textCapitalization:
                                TextCapitalization.sentences,
                          );
                        },
                        displayStringForOption: (place) =>
                            place.primaryText,
                        optionsMaxHeight: screenHeight,
                        onSelected: (option) async {
                          final selectedPlace =
                            await _googlePlaces.fetchPlace(
                            option.placeId,
                          );
                          print(selectedPlace);
                          selectedLocation = {
                            "lat":
                                selectedPlace.place!.latLng!.lat.toString(),
                            "lng":
                                selectedPlace.place!.latLng!.lng.toString(),
                            "address": selectedPlace.place!.address,
                          };
                        },
                        optionsViewBuilder: (BuildContext context,
                            AutocompleteOnSelected<AutocompletePrediction>
                                onSelected,
                            Iterable<AutocompletePrediction> places) {
                          return Align(
                            alignment: Alignment.topLeft,
                            child: Material(
                              child: Container(
                                width: screenWidth - 30 * 2 - 22.1 * 2,
                                decoration: const BoxDecoration(
                                  color: Colors.white,
                                  boxShadow: [
                                    BoxShadow(
                                      color: Color(0x1A000000),
                                      offset: Offset(0, 3),
                                      blurRadius: 6,
                                    ),
                                  ],
                                ),
                                child: Builder(builder: (BuildContext) {
                                  List<Widget> children = [];
                                  // final List<dynamic> placesList = jsonDecode(places.first)['predictions'];
                                  print("Plaxes 0- ${places}");
                                  places.forEach(
                                    (place) {
                                      children.add(Container(
                                        alignment: Alignment.centerLeft,
                                        padding: const EdgeInsets.only(
                                            top: 20,
                                            left: 20,
                                            right: 20,
                                            bottom: 20),
                                        decoration: const BoxDecoration(
                                            border: Border(
                                                bottom: BorderSide(
                                                    color:
                                                        Color(0xfff9f9f9),
                                                    width: 2,
                                                    style: BorderStyle
                                                        .solid))),
                                        child: GestureDetector(
                                            onTap: (() async {
                                              onSelected(place);
                                            }),
                                            child: Text(place.fullText)),
                                      ));
                                    },
                                  );
                                  // for (int i = 0; i < places.length; i++) {
                                  //   children.add(Container(
                                  //     alignment: Alignment.centerLeft,
                                  //     padding: const EdgeInsets.only(top: 20, left: 20, right: 20, bottom: 20),
                                  //     decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Color(0xfff9f9f9), width: 2, style: BorderStyle.solid))),
                                  //     child: Text(),
                                  //   ));
                                  // }
                                  return ListView(
                                    children: children,
                                    shrinkWrap: true,
                                    padding:
                                        const EdgeInsets.only(bottom: 50),
                                  );
                                  // return Column(
                                  //   children: children,
                                  // );
                                }),
                              ),
                            ),
                          );
                        },
                      ),

from flutter_google_places_sdk.

manvirrr avatar manvirrr commented on August 14, 2024

Hi... I think i found the issue... I was not passing placefieldds to fetchPlace. Passing fields solved the issue... Thanks....

from flutter_google_places_sdk.

matanshukry avatar matanshukry commented on August 14, 2024

@manvirrr great.

Keeping tihs issue open since the package should return a better error than what you are getting in this case.

from flutter_google_places_sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.