google_maps_flutter 지도 흰 화면

flunge·2022년 1월 12일
0

Flutter

목록 보기
9/13

문제

google_maps_flutter를 이용해 구글 지도를 사용할 때 생기는 문제로 홈 버튼을 눌러 앱이 inactive상태 혹은 background상태로 전환 후 다시 앱이 보일 때 지도가 흰색으로만 보인다.

해결

GoogleMapController _controller;

void onMapCreated(GoogleMapController controller) async {
  _controller = controller;
}

@override
void didChangeAppLifecycleState(ui.AppLifecycleState state) {
  super.didChangeAppLifecycleState(state);

  switch (state) {
    case AppLifecycleState.resumed:    


      setState(() {
        if(_controller != null)
          _controller.setMapStyle(null);
      });
      
      ...

화면의 지도의 controller객체를 준비하고 앱의 상태를 감시할 수 있게하는 didChangeAppLifecycleState를 오버라이딩한 후 다시 앱이 실행되는 AppLifecycleState.resumed의 경우일 때
_controller.setMapStyle(null);를 호출한다.
매개변수로 null이 아닌 다른 스타일을 줘도 상관 없다.

0개의 댓글