mercredi 9 septembre 2020

Flutter update element create by ui.platformViewRegistry.registerViewFactory class

I am working with Google Map for flutter Website. As most tutorial said that, the map is displayed through ui.platformViewRegistry.registerViewFactory

below is the code example. As you see, i create the widget with the variable and tried to give the _lat and _lng from outside. But after i tried to give the value, the ui.platformViewRegistry.registerViewFactory is not triggered.

I just realize that the ui.platformViewRegistry.registerViewFactory objected to create the element so when the element was created, it will not executed again, but I cannot access the element via document.getElementById('map-canvas') either.

Anyone have idea about this?

Widget getMap(double _lat, double _lng) {
  String htmlId = "map-canvas";

  ui.platformViewRegistry.registerViewFactory(htmlId, (int viewId) {
    // final myLatLng = LatLng(-25.363882, 131.044922);
    final mapOptions = new MapOptions()
      ..zoom = 8
      ..center = new LatLng(_lat, _lng)
      ..mapTypeControl = false;

    final elem = DivElement()
      ..id = htmlId
      ..style.width = "100%"
      ..style.height = "100%"
      ..style.border = "none";

    final map = new GMap(elem, mapOptions);

    Marker(MarkerOptions()
      ..position = LatLng(_lat, _lng)
      ..map = map
      ..title = 'Green Energy');

    return elem;
  });
  return HtmlElementView(
    viewType: htmlId,
  );
}



Aucun commentaire:

Enregistrer un commentaire