【问题标题】:Unhandled Exception: Bad state: Cannot add new events after calling close, on using fluttter_google_places未处理的异常:错误状态:在使用 fluttter_google_places 调用关闭后无法添加新事件
【发布时间】:2020-05-19 00:21:15
【问题描述】:

每次我使用 PlacesAutoComplete 小部件时都会收到此错误。搜索/请求/响应一切正常,没有崩溃或任何事情。但是日志在每次搜索时都会向我显示此错误。

我为它添加了两个包:flutter_google_places 和 google_web_services。

而且我根本不使用流。所以这对我来说是一个非常奇怪的错误。

我为此遵循了几个在线指南,谁能解释我做错了什么?

另外,我发现这是实现地点自动完成的一种非常基本的方法。我希望您能提供有关实施 google 地方搜索的更好方法的建议。

Future<void> _searchWithPlacesAutoComplete() async {
    Prediction _predictions = await PlacesAutocomplete.show(
      context: context,
      apiKey: GOOGLE_API_KEY,
      onError: (response) => _showError(response),
      mode: Mode.overlay,
      language: "en",
      components: [Component(Component.country, "uk")],
      location: _currentLocation,
      radius: 50,
    );

    if (_predictions != null) {
      PlacesDetailsResponse detail =
          await GoogleMapsPlaces(apiKey: GOOGLE_API_KEY)
              .getDetailsByPlaceId(_predictions.placeId);
      final lat = detail.result.geometry.location.lat;
      final lng = detail.result.geometry.location.lng;

      setState(() {
        _markedPosition = new LatLng(lat, lng);
      });
      mapController.animateCamera(
        CameraUpdate.newCameraPosition(
          CameraPosition(
            target: _markedPosition,
            zoom: 16.0,
          ),
        ),
      );
    }
  }

【问题讨论】:

    标签: flutter dart google-api google-places-api googleplacesautocomplete


    【解决方案1】:

    这是他们在 git 代码中修复的插件错误。不幸的是,它尚未更新到当前版本。

    您可以做的是将所有 src 文件集成到他们的 github lib 文件夹中。它为我解决了这个问题。

    具体步骤:

    [1] 转到https://github.com/fluttercommunity/flutter_google_places/tree/master/lib/src [2] 将所有dart文件复制到我的项目中

    【讨论】:

    • 谢谢,至少它澄清了这不是我的错误
    【解决方案2】:

      StreamController&lt;dynamic&gt; subject = StreamController&lt;dynamic&gt;.broadcast();

    【讨论】:

    • 欢迎来到 StackOverflow。虽然此代码可能会回答问题,但提供有关 如何 和/或 为什么 解决问题的附加上下文将提高​​答案的长期价值。
    猜你喜欢
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    相关资源
    最近更新 更多