marchdev-tk / flutter_google_maps

A Flutter plugin for integrating Google Maps in iOS, Android and Web applications. It is a wrapper of google_maps_flutter for Mobile and google_maps for Web.
BSD 3-Clause "New" or "Revised" License
87 stars 57 forks source link

Android not showing pins in debug mode #57

Closed cedrichansen closed 4 years ago

cedrichansen commented 4 years ago

Custom markers are not displayed in debug mode (ie flutter run -d ), but are displayed when running in release mode (flutter run -d --release).

By custom pins, i mean doing the following:

Marker(
       GeoCoord(address.lat, address.long),
        info: address.fullAddress,
        icon: "assets/markers/bluepin.png", ////---THIS PARAM CAUSES ISSUE --
           .......(Other params here)
)

If I remove the "icon:" param, the default pin is displayed in both debug and release mode.

This is NOT an issue on web, but is an issue on android (not sure about ios)

cedrichansen commented 4 years ago

Have found the source of the bug. I was creating these markers in initState(), and adding these markers to a set of markers, which was then assigned to the markers param on the google maps widget - But since loading the custom markers is an async call, the images/markers may not finish loading by the time the first build method is finished.

In order to resolve this, in initState, call

 WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
       Marker m = (... Create marker with custom icon from assets folder)
        GoogleMap.of(_key).addMarker(m);
 })

Hopefully anyone else who runs into this same issue may find my solution helpful.

Other suggestions/fixes are welcome!

I will mark this issue as closed