'Flutter - Google maps only shows one marker

In Flutter, I created an array to add markers.

final List<Marker> _markers = <Marker>[];

Then I iterate all values and add them to this array

 UserService().getAll().then((value) {
      setState(() {
        for (var element in value) {
          _markers.add(Marker(
            markerId: MarkerId(element.id.toString()),
            position: LatLng((element.latitude), element.longitude),
            infoWindow: InfoWindow(
              title: element.name,
            ),
            icon: BitmapDescriptor.defaultMarker,
          ));
        }
      });
    }).catchError((e) {
      debugPrint(e);
    });

Finally on Google Maps i add this array to markers

 final map = GoogleMap(
      myLocationEnabled: true,
      zoomControlsEnabled: false,
      onMapCreated: _onMapCreated,
      markers: _markers.map((e) => e).toSet(),
      initialCameraPosition: CameraPosition(
        target: _center,
        zoom: 8.0,
      ),
    );

The problem: Map only shows the first element of this array in the map. Does anybody know what´s wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source