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;

@override
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(
     'assets/world_map.json',
     shapeDataField: 'name',
     dataCount: data.length,
     primaryValueMapper: (int index) => data[index].country,
   );
   super.initState();
}

@override
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>[
                 MapShapeLayer(
                   source: _mapSource,
                   initialMarkersCount: 5,
                   markerBuilder: (BuildContext context, int index) {
                     return MapMarker(
                       latitude: data[index].latitude,
                       longitude: data[index].longitude,
                     );
                   },
                 ),
               ],
             ),
           ),
         )
     ),
   );
 }

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

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

See also:

Inheritance

Constructors

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

Properties

alignment AlignmentGeometry
Sets the alignment for the marker on the map. [...]
final
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. [...]
final
iconStrokeColor Color?
Sets the icon's stroke color for the marker. [...]
final
iconStrokeWidth double?
Sets the icon's stroke width for the marker. [...]
final
iconType MapIconType
Sets the icon's shape of the marker. [...]
final
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. [...]
final
longitude double
Sets the longitude for the marker on the map. [...]
final
offset Offset
Places the marker position in additional to the given offset. [...]
final
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. [...]
final

Methods

createElement() SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
inherited
createRenderObject(BuildContext context) RenderObject
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget. [...]
override
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. [...]
inherited
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. [...]
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object. [...]
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A short, textual description of this widget.
inherited
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. [...]
override

Operators

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