我正在经历以下问题:我的颤音应用程序使用GoogleMap。地图最初加载得很好。然而,如果我把应用程序放到后台,然后再继续一段时间,地图将保持空白。Google徽标仍然显示,就像未指定API键时发生的情况一样。我的多边形覆盖也没有出现。
该行为不可靠地可还原。有时,地图加载后,应用程序已在后台数小时后,有时地图是空白的几分钟后。到目前为止,我只在Android上看到过这种行为。
没有指示错误的特定日志输出。
有什么办法解决这个问题吗?
我在这里提交了一个屏幕截图问题:https://github.com/flutter/flutter/issues/40284
编辑1: i能够用一个GoogleMap作为根小部件来再现它,并且没有任何多边形/特性覆盖。另外,我发现在某个时候疯狂地放大了地图(突然,地图又变得可见了)。这可能是底层的Android Google的一个已知问题吗?
编辑2:我发现映射仍然在反应(例如,点击/手势侦听器仍然触发)。而且,地图并不是真的是空的,它只是变得半透明,所以屏幕显示地图后面的任何小部件。
发布于 2020-03-04 22:03:52
我发现,如果您点击一个标记或更改样式,则地图将重新呈现。
class TheWidgetThatHasTheMap with WidgetsBindingObserver {
//...your code
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
controller.setMapStyle("[]");
}
}
}发布于 2019-12-21 11:15:05
不是核心问题的解决方案,但我能够通过创建插件项目的分支并按以下方式修改GoogleMapController.java来解决这个bug:
@Override
public void onActivityResumed(Activity activity) {
if (disposed || activity.hashCode() != registrarActivityHashCode) {
return;
}
mapView.onResume();
// Workaround for https://github.com/flutter/flutter/issues/40284
// This apparently forces a re-render of the map.
if (googleMap != null) {
googleMap.setMapType(googleMap.getMapType());
}
}现在,在每个简历事件上,地图将被重新呈现.
发布于 2021-07-21 06:19:39
我尝试了一些东西&它似乎起作用了!
步骤01,为相关类的状态类实现WidgetsBindingObserver,如下所示:
class MainScreenState extends State<MainScreen> with WidgetsBindingObserver {....步骤02,重写didChangeAppLifecycleState方法,即:
@override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.inactive:
print('appLifeCycleState inactive');
break;
case AppLifecycleState.resumed:
print('appLifeCycleState resumed');
break;
case AppLifecycleState.paused:
print('appLifeCycleState paused');
break;
case AppLifecycleState.detached:
print('appLifeCycleState detached');
break;
}
}步骤03为init状态添加以下内容
WidgetsBinding.instance!.addObserver(this);步骤04第4步应如下所示
//onMapCreated method
void onMapCreated(GoogleMapController controller) {
controller.setMapStyle(Utils.mapStyles);
_controller.complete(controller);
}
// lifecycle
@override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.inactive:
print('appLifeCycleState inactive');
break;
case AppLifecycleState.resumed:
**//Add These lines**
final GoogleMapController controller = await _controller.future;
onMapCreated(controller);
print('appLifeCycleState resumed');
break;
case AppLifecycleState.paused:
print('appLifeCycleState paused');
break;
case AppLifecycleState.detached:
print('appLifeCycleState detached');
break;
}
}https://stackoverflow.com/questions/59374010
复制相似问题