kokserek
kokserek

Reputation: 589

flutter_map: how to make a Marker active

My task is to allow the user to build a polygon on the map. I use the flutter_map library and openstreetmaps. I do not know how to complete the building of the polygon.

Now, by the very first onTap, an IconButton appears on the map. I want to make this IconButton active so that when the user onPress on it: (1) the icon changes, (2) returns (and saves for passing to the backend) a set of points that the user tapped during the polygon building process, and (3) the polygon building process stops (adding new points became impossible).

I think, the challenge comes down to how callback setState inside another setState while retaining functionality. But maybe there is another solution.

My code is below. I can provide the whole code if needed.

I would appreciate any ideas.

class _HomePageState extends State<HomePage> {
  
...  
  List<Marker> markers = [];
  List<LatLng> polygonList = [];
  bool singleTap = false;

...

options: MapOptions(
           
            ...          
            onTap: (latlng) {
              if (singleTap) {
                setState(() {
                  if (markers.length == 0) {
                    markers.add(
                      Marker(
                        point: latlng,
                        builder: (ctx) => IconButton(
                          icon: Icon(Icons.favorite),
                          onPressed: () {***HERE the process should be stopped with changing the icon, no new points;***
                            setState(() {});
                          },
                        ),
                      ),
                    );
                  } else {
                    markers.add(
                      Marker(...),
                      ),
                    );
                  }
                  polygonList.add(latlng);
                });
              }
            }),

Upvotes: 0

Views: 1530

Answers (1)

kokserek
kokserek

Reputation: 589

An answer is very simple: nothing special to do with it, just keep in mind that "other layers may intercept the gestures". I just changed the order of layers, and now my Marker is active.

Upvotes: 4

Related Questions