0

I have an issue with showing GoogleMaps in my Flutter app, I've implemented it in a swiper, so each page should show the location with a custom marker, would post a code sample but it's too long so I'll try to explain it as short as I can. Basically when I open the swiper with detail pages in it, it has a map in the bottom and it shows fine while swiping through the pages, but if I put the app in background and get back to it after few swipes it shows just white container with Google logo but no map.

It happens on physical devices but not on the Emulator. Found the issue opened here Also tried suggestions from this question

If anyone has an idea on how to fix it, it would be appreciated

1 Answers1

0

I had this issue but didn't realize it was a reported bug. Trying to track down the problem I tried a brute-force mark-the-whole-UI-dirty on foregrounding to see if might be a redraw issue and it stopped happening. Not elegant but it seems to work. None of our testers have reported the blank Google Maps since. I also found I had to do it once Flutter was ready to build() after foregrounding.

This is in the stateful widget that is the first child of my MultiProvider at the top of the app. The google map is in a Scaffold()->Stack() farther down the graph:

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
  if(state == AppLifecycleState.resumed) {
    setState(() { _refreshAllChildrenAfterWakeup = true; });
  }
}

void _rebuildAllChildren(BuildContext context) {
  void rebuild(Element el) {
    el.markNeedsBuild();
    el.visitChildren(rebuild);
  }
  (context as Element).visitChildren(rebuild);
}

Widget build(BuildContext context) {

  if(_refreshAllChildrenAfterWakeup == true) {
    _refreshAllChildrenAfterWakeup = false;
    _rebuildAllChildren(context);
  }
  //...
}
Pat9RB
  • 580
  • 3
  • 7
  • Thanks for the answer, will try it, though i'm not using any Provider in the app, not sure if it makes any difference – Vladan Randjelovic Sep 24 '21 at 14:10
  • Unfortunately it doesn't do the trick... :( not sure now is it just to my phone Redmi Note 10 5G, or it will appear on others too – Vladan Randjelovic Sep 24 '21 at 14:23
  • FWIW I have a Pixel 4 and a Samsung S20 for testing and I tried but couldn't get the blank map on the Pixel 4. On the S20 it happened frequently. We're in closed beta atm and none of the testers have reported this issue, but I don't know what phones they have. – Pat9RB Sep 24 '21 at 16:58