将flutter_google_places插件与Geocoder插件一起使用时,应用崩溃

时间:2019-06-17 08:47:51

标签: flutter flutter-plugin

我已经在我的应用中实现了flutter_google_places插件。它根据搜索查询提供一个列表。但是,无论何时选择任何输出,应用程序都会崩溃,并且调试会自动停止。 您可以在此处查看问题以及日志。

代码基于对另一个StackOverflow问题的回答 here

根据github链接中的代码,您可以看到我想查看所选位置的纬度和经度。但这似乎不起作用。有帮助吗?

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

这是日志

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)

0 个答案:

没有答案