App crashing when using flutter_google_places plugin along with geocoder plugin

-1

I have implemented flutter_google_places plugin in my app. It provides a list according to the search query. But whenever I select any of the output, the app crashes and the debug stops automatically. You can checkout the issue here, along with the log.

The code is based from the answer on anotherStackOverflow question here.

As per the code from the github link, you can see I want to see the latitude and Longitude of the selected place. But it doesn't seem to work. Any help?

  GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: apiKey);

  @override
  Widget build(BuildContext context) {
    return FloatingActionButton(
      mini: true,
      heroTag: "ssearch",
      onPressed: () async {
        Prediction p =
            await PlacesAutocomplete.show(context: context, apiKey: apiKey, mode: Mode.overlay);
        displayPrediction(p);
      },
      child: Icon(Icons.search),
    );
  }

  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);
    }
  }
}

Here's the log

Restarted application in 2,320ms.
W/ResourceType(12219): No package identifier when getting name for resource number 0x00000000
I/Google Maps Android API(12219): Google Play services package version: 17455021
I/art     (12219): Do full code cache collection, code=506KB, data=486KB
I/art     (12219): After code cache collection, code=490KB, data=447KB
W/ResourceType(12219): No package identifier when getting name for resource number 0x00000000
W/ResourceType(12219): No package identifier when getting name for resource number 0x00000000
E/AndroidRuntime(12219): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(12219): Process: com.example.memories, PID: 12219
E/AndroidRuntime(12219): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(12219):    at android.os.AsyncTask$3.done(AsyncTask.java:318)
E/AndroidRuntime(12219):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
E/AndroidRuntime(12219):    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
E/AndroidRuntime(12219):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime(12219):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
E/AndroidRuntime(12219):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/AndroidRuntime(12219):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/AndroidRuntime(12219):    at java.lang.Thread.run(Thread.java:760)
E/AndroidRuntime(12219): Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #2
E/AndroidRuntime(12219):    at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
E/AndroidRuntime(12219):    at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:556)
E/AndroidRuntime(12219):    at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:131)
E/AndroidRuntime(12219):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/AndroidRuntime(12219):    at com.aloisdeniel.geocoder.GeocoderPlugin$1.doInBackground(GeocoderPlugin.java:79)
E/AndroidRuntime(12219):    at com.aloisdeniel.geocoder.GeocoderPlugin$1.doInBackground(GeocoderPlugin.java:72)
E/AndroidRuntime(12219):    at android.os.AsyncTask$2.call(AsyncTask.java:304)
E/AndroidRuntime(12219):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/AndroidRuntime(12219):    ... 4 more
I/Process (12219): Sending signal. PID: 12219 SIG: 9
Lost connection to device.
Exited (sigterm)
flutter
flutter-plugin
asked on Stack Overflow Jun 17, 2019 by Pratik Singhal • edited Jun 17, 2019 by Pratik Singhal

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0