How to refresh the map

So I am working on the map where I show different markers and I am trying to set a bool on the button click under set state and the map is not refreshing is there any way or alternate way to refresh?

I am able to have on click on the map but i want to refresh the map when button is pressed which is not working

Here is the code

 setState(() {
          if (blinkfunction) {
            blinkfunction = false;
          } else {
            blinkfunction = true;
          }
        //  _controller.insertMarker(count);

        });


How i set the marker

  markerBuilder: (BuildContext context, int index) {
                  return MapMarker(
                    latitude: _data[index].latitude!,
                    longitude: _data[index].longitude!,
                    child: InkWell(
                        onTap: () {
                          // showcolordialog(context);
                        },
                        child: markerwidget(_data, index)),
                  );
                },


every thing is working but the map is not getting refresh when button clicked


3 Replies

SK Sriram Kiran Senthilkumar Syncfusion Team September 7, 2022 11:55 AM UTC

Hi Neelay,


Greetings from Syncfusion.

We have validated your query and code snippet at our end, we are sorry that we were not able to understand what you are trying to achieve by analyzing your code snippets. In the first code snippet, you have changed the `blinkFunction` value in `setState` but we cannot suspect that where you have used that flag in the map widget and in what case you need to refresh the Map widget using that flag.  

So, we request you to kindly revert us with more information in detail about your exact requirement along with screenshots or screen recording and also, if possible, provide us with a simple replication sample about your scenario so that it will help us assist you in a better way.


Regards,

Sriram Kiran



NE Neelay September 8, 2022 03:21 AM UTC

So in the marker widget I am setting which marker i will show

here is the code 

 Widget markerwidget(List<MarkerPos> data, int index) {
    if (type == 'rectangle') {
      return Container(
        padding: EdgeInsets.all(5),
        decoration: BoxDecoration(
          color: Color(_data[index].color!),
          borderRadius: BorderRadius.all(Radius.elliptical(0, 0)),
        ),
        child: Text(
          _data[index].text!,
        ),
      );
    } else if (type == 'ellipse') {
      return Container(
        padding: EdgeInsets.all(5),
        decoration: BoxDecoration(
          color: Color(_data[index].color!),
          borderRadius: BorderRadius.all(Radius.elliptical(100, 50)),
        ),
        child: Text(
          _data[index].text!,
        ),
      );
    } else if (type == 'function') {
      if (blinkfunction) {
        return Blinkwidget(blinker: Icon(IconDataSolid(_data[index].icons!),
            color: Color(_data[index].color!)),);
      } else {
        return Icon(IconDataSolid(_data[index].icons!),
            color: Color(_data[index].color!));
      }
    } else if (type == 'problem') {
      return Icon(IconDataSolid(_data[index].icons!),
          color: Color(_data[index].color!));
    } else if (type == 'image') {
      return Container(
        height: 50,
        width: 50,
        child: Image.file(
            File(
              _data[index].url.toString(),
            ),
            fit: BoxFit.cover),
      );
    } else if (type == 'boat') {
      return Icon(IconDataSolid(_data[index].icons!),
          color: Color(_data[index].color!));
    } else if (type == 'Philosophy') {
      return Icon(IconDataSolid(_data[index].icons!),
          color: Color(_data[index].color!));
    }
    return Container();
  }


when the 'function' is selected as a marker. I want to show icon or a blinking widget but when I try to refresh the widget which already has an icon it doses not update the marker build.



SK Sriram Kiran Senthilkumar Syncfusion Team September 8, 2022 12:06 PM UTC

Hi Neelay,


Thanks for the revert. We have checked your requirement at our end, and we would like to let you know that if you need to add, remove, or update the marker in the Maps widget, then you must use MapShapeLayerController or MapTileLayerController based on the layer you have used in your widget.

We have created a simple sample in which we have rendered a few markers on the MapShapeLayer using markerBuilder and set the controller for the layer to update the marker using the updateMarker method on button click. We have attached the sample and also appended the user guide documentation for updating existing markers in the Map below for your reference.

https://help.syncfusion.com/flutter/maps/markers#updating-the-existing-markers


Please check and get back to us if you require further assistance on this.


Regards,

Sriram Kiran


Attachment: f177303_ebd6ed3d.zip

Loader.
Up arrow icon