[英]Unhandled Exception: Bad state: Cannot add new events after calling close - Between screens
[英]Unhandled Exception: Bad state: Cannot add new events after calling close, on using fluttter_google_places
每次使用 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,
),
),
);
}
}
這是他們在 git 代碼中修復的插件錯誤。 不幸的是,它尚未在當前版本中更新。
您可以做的是將所有 src 文件集成到其 github lib 文件夾中。 它為我解決了這個問題。
具體步驟:
[1] Go 到https://github.com/fluttercommunity/flutter_google_places/tree/master/lib/src [2] 將所有 ZBB14127678960FAE97D873905 文件復制到項目中
StreamController<dynamic> subject = StreamController<dynamic>.broadcast();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.