插件 `geocoder` 使用了 Android 嵌入的弃用版本

The plugin `geocoder` uses a deprecated version of the Android embedding

当我运行 pub get时,我遇到以下错误:

The plugin geocoder uses a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

这只是意味着您要使用的包已过时,并且 flutter 新更新删除了该包正在使用的一些功能。

快速解决方案:

  • 在终端'flutter pub outdated' 中 运行 过时的抖动,我不推荐
  • 或者为这个包使用一个替代品,并确保这个替代品是新升级的,以与你的 flutter 版本兼容

这是因为最新的 flutter 更新了 2.5 版本。在我的例子中,我已经通过命令 flutter downgrade 降级了我的 flutter 版本,它显示了一个降级 flutter 版本的选项,它解决了我的错误。

较新的 flutter 版本已弃用 GeoCoder 包。但是您可以使用这种替代方法。这与较新的 flutter 版本兼容并且工作正常。 使用此替代方法:https://pub.dev/packages/geocode

您可以使用 Geocoding 插件来查找地址,而不是使用该插件:

import 'package:geocoding/geocoding.dart';

List<Placemark> placemarks = await placemarkFromCoordinates(52.2165157, 6.9437819);

用它来修复所有错误
https://pub.dev/packages/geocoder2

import 'package:geocoder2/geocoder2.dart';

获取地址

    FetchGeocoder fetchGeocoder = await Geocoder2.getAddressFromCoordinates(
        latitude: 40.714224,
        longitude: -73.961452,
        googleMapApiKey: "GOOGLE_MAP_API_KEY");
    var first = fetchGeocoder.results.first;
    print(first.formattedAddress);

获取坐标

FetchGeocoder fetchGeocoder = await Geocoder2.getCoordinatesFromAddress(
        address: "277 Bedford Ave, Brooklyn, NY 11211, USA",
        googleMapApiKey: "GOOGLE_MAP_API_KEY");
    var first = fetchGeocoder.results.first;
    print("${first.geometry.location.lat} , ${first.geometry.location.lng}");