Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when search prediction is clicked #69

Closed
pratik037 opened this issue Jun 17, 2019 · 5 comments
Closed

App crashes when search prediction is clicked #69

pratik037 opened this issue Jun 17, 2019 · 5 comments

Comments

@pratik037
Copy link

When the any of the prediction is clicked, the app crashes and the debug stops automatically.
Device: Redmi Note 4
Flutter version: 1.6.3

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)
@pratik037
Copy link
Author

Code Implementation

class _SearchBarState extends State<SearchBar> {
  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);
    }
  }
}

@ma3az33
Copy link

ma3az33 commented Jul 4, 2019

@pratik037 you can use this method Geocoder.google(Your_google_key").findAddressesFromCoordinates() instaded of Geocoder.findAddressesFromCoordinates() it will work

@sergioahv15
Copy link

sergioahv15 commented Jul 14, 2019

I had the same issue. Thanks @ma3az33, it works!
Does anyone know why Geocoder.local.findAddressesFromCoordinates() is not working?

@pratik037
Copy link
Author

@pratik037 you can use this method Geocoder.google(Your_google_key").findAddressesFromCoordinates() instaded of Geocoder.findAddressesFromCoordinates() it will work

Okay, so we can close this issue now.

@Vaibhav7894
Copy link

It Works for me....!!!!
If issue related with geocoder: ^0.1.1 then just replace with geocoder: ^0.2.1 in pubspec.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants