MapMarker class Null safety

Markers can be used to denote the locations on the map.

It is possible to use the built-in symbols or display a custom widget at a specific latitude and longitude on a map.

The MapLayer.markerBuilder callback will be called number of times equal to the value specified in the MapLayer.initialMarkersCount property. The default value of this property is null.

For rendering the custom widget for the marker, pass the required widget for child in MapMarker constructor.

late List<Model> data;
late MapShapeSource _mapSource;

void initState() {
   data = const <Model>[
     Model('Brazil', -14.235004, -51.92528),
     Model('Germany', 51.16569, 10.451526),
     Model('Australia', -25.274398, 133.775136),
     Model('India', 20.593684, 78.96288),
     Model('Russia', 61.52401, 105.318756)

   _mapSource = MapShapeSource.asset(
     shapeDataField: 'name',
     dataCount: data.length,
     primaryValueMapper: (int index) => data[index].country,

Widget build(BuildContext context) {
   return Scaffold(
     body: Center(
         child: Container(
           height: 350,
           child: Padding(
             padding: EdgeInsets.only(left: 15, right: 15),
             child: SfMaps(
               layers: <MapLayer>[
                   source: _mapSource,
                   initialMarkersCount: 5,
                   markerBuilder: (BuildContext context, int index) {
                     return MapMarker(
                       latitude: data[index].latitude,
                       longitude: data[index].longitude,

class Model {
 const Model(, this.latitude, this.longitude);

 final String country;
 final double latitude;
 final double longitude;

See also:



MapMarker({Key? key, required double latitude, required double longitude, Size? size, AlignmentGeometry alignment =, Offset offset =, Color? iconColor, Color? iconStrokeColor, double? iconStrokeWidth, MapIconType iconType =, Widget? child})
Creates a MapMarker.


alignment AlignmentGeometry
Sets the alignment for the marker on the map. [...]
child Widget?
The widget below this widget in the tree. [...]
final, inherited
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
iconColor Color?
Sets the icon color for the marker. [...]
iconStrokeColor Color?
Sets the icon's stroke color for the marker. [...]
iconStrokeWidth double?
Sets the icon's stroke width for the marker. [...]
iconType MapIconType
Sets the icon's shape of the marker. [...]
key Key?
Controls how one widget replaces another widget in the tree. [...]
final, inherited
latitude double
Sets the latitude for the marker on the map. [...]
longitude double
Sets the longitude for the marker on the map. [...]
offset Offset
Places the marker position in additional to the given offset. [...]
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
size Size?
Sets the size for the marker on the map. [...]


createElement() SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
createRenderObject(BuildContext context) RenderObject
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget. [...]
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
didUnmountRenderObject(covariant RenderObject renderObject) → void
A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object's createRenderObject.
@protected, inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
toString({DiagnosticLevel minLevel =}) String
A string representation of this object. [...]
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.
updateRenderObject(BuildContext context, covariant _RenderMapMarker renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject. [...]


operator ==(Object other) bool
The equality operator. [...]
@nonVirtual, inherited