MapSelectionSettings class

Customizes the appearance of the selected shape.

late List<DataModel> _data;
late MapShapeSource _mapSource;
int _selectedIndex = -1;

  @override
  void initState() {
    super.initState();

    _data = <DataModel>[
      DataModel('India', 280, "Low", Colors.red),
      DataModel('United States of America', 190, "High", Colors.green),
      DataModel('Pakistan', 37, "Low", Colors.yellow),
    ];

    _mapSource = MapShapeSource.asset(
      "assets/world_map.json",
      shapeDataField: "name",
      dataCount: _data.length,
      primaryValueMapper: (int index) => _data[index].country,
      shapeColorValueMapper: (int index) => _data[index].color,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Container(
        height: 350,
        child: Padding(
          padding: EdgeInsets.only(left: 15, right: 15),
          child: Column(
            children: [
              SfMaps(
                layers: <MapLayer>[
                  MapShapeLayer(
                    source: _mapSource,
                    selectedIndex: _selectedIndex,
                    selectionSettings: MapSelectionSettings(
                        color: Colors.black),
                    onSelectionChanged: (int index) {
                      setState(() {
                        _selectedIndex = (_selectedIndex == index) ?
                               -1 : index;
                      });
                    },
                  ),
                ],
              ),
            ],
          ),
        ),
      )),
    );
  }
}

class DataModel {
  const DataModel(
     this.country,
     this.usersCount,
     this.storage,
     this.color,
  );
  final String country;
  final double usersCount;
  final String storage;
  final Color color;
}
Inheritance
Annotations

Constructors

MapSelectionSettings({Color? color, Color? strokeColor, double? strokeWidth})
Creates a MapSelectionSettings.
const

Properties

color Color?
Fills the selected shape by this color.
final
hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
strokeColor Color?
Applies stroke color for the selected shape.
final
strokeWidth double?
Stroke width which applies to the selected shape.
final

Methods

debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent 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, int wrapWidth = 65}) 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 brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override