MapLegend.bar constructor

const MapLegend.bar(
  1. MapElement source, {
  2. bool shouldAlwaysShowScrollbar = false,
  3. Widget? title,
  4. MapLegendOverflowMode overflowMode = MapLegendOverflowMode.scroll,
  5. EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0),
  6. MapLegendPosition position = MapLegendPosition.top,
  7. Offset? offset,
  8. double spacing = 2.0,
  9. Size? segmentSize,
  10. TextStyle? textStyle,
  11. Axis? direction,
  12. MapLegendLabelsPlacement? labelsPlacement,
  13. MapLegendEdgeLabelsPlacement edgeLabelsPlacement = MapLegendEdgeLabelsPlacement.inside,
  14. MapLabelOverflow labelOverflow = MapLabelOverflow.visible,
  15. MapLegendPaintingStyle segmentPaintingStyle = MapLegendPaintingStyle.solid,
  16. bool showPointerOnHover = false,
  17. MapLegendPointerBuilder? pointerBuilder,
  18. Color? pointerColor,
  19. Size pointerSize = const Size(16, 12),
})

Creates a bar type legend for the bubbles or shapes.

Information provided in the legend helps to identify the data rendered in the map shapes or bubbles.

Defaults to null.

By default, legend will not be shown.

Legend for shape

Set MapLegend.source to MapElement.shape to show legend for shapes.

If MapShapeSource.shapeColorMappers is not null, then MapColorMapper.color and MapColorMapper.text will be used for the legend item's icon and the legend item's text respectively.

If MapShapeSource.shapeColorMappers is null, the color returned in the MapShapeSource.shapeColorValueMapper will be applied to the legend item's icon and the legend item's text will be taken from the MapShapeSource.shapeDataField.

If both the MapShapeSource.shapeColorMappers and the MapShapeSource.shapeColorValueMapper properties are null, the legend item's text will be taken from the MapShapeSource.shapeDataField property and the legend item's icon will have the default color.

Legend for bubbles

Set MapLegend.source to MapElement.bubble to show legend for bubbles.

If MapShapeSource.bubbleColorMappers is not null, then MapColorMapper.color and MapColorMapper.text will be used for the legend item's icon and the legend item's text respectively.

If MapShapeSource.bubbleColorMappers is null, the color returned in the MapShapeSource.bubbleColorValueMapper will be applied to the legend item's icon and the legend item's text will be taken from the MapShapeSource.shapeDataField.

If both the MapShapeSource.bubbleColorMappers and the MapShapeSource.bubbleColorValueMapper properties are null, the legend item's text will be taken from the MapShapeSource.shapeDataField property and the legend item's icon will have the default color.

late List<DataModel> _data;
late MapShapeSource _mapSource;

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

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

   _mapSource = MapShapeSource.asset(
     "assets/world_map.json",
     shapeDataField: "name",
     dataCount: _data.length,
     primaryValueMapper: (int index) {
       return _data[index].country;
     },
     shapeColorValueMapper: (int index) {
       return _data[index].storage;
     },
     shapeColorMappers: [
       MapColorMapper(value: "Low", color: Colors.red),
       MapColorMapper(value: "High", color: Colors.green)
     ],
   );
 }

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(
       title: Text('Bar legend'),
     ),
     body: Center(
       child: SfMaps(
         layers: [
           MapShapeLayer(
             source: _mapSource,
             legend: MapLegend.bar(MapElement.shape),
           )
         ],
       ),
     ),
   );
 }

class DataModel {
  const DataModel(this.country, this.count, this.storage);

  final String country;
  final double count;
  final String storage;
}

See also:

  • MapLegend(), for legend type with different styles like circle, diamond, rectangle and triangle.

Implementation

const MapLegend.bar(
  this.source, {
  this.shouldAlwaysShowScrollbar = false,
  this.title,
  this.overflowMode = MapLegendOverflowMode.scroll,
  this.padding = const EdgeInsets.all(10.0),
  this.position = MapLegendPosition.top,
  this.offset,
  this.spacing = 2.0,
  this.segmentSize,
  this.textStyle,
  this.direction,
  this.labelsPlacement,
  this.edgeLabelsPlacement = MapLegendEdgeLabelsPlacement.inside,
  this.labelOverflow = MapLabelOverflow.visible,
  this.segmentPaintingStyle = MapLegendPaintingStyle.solid,
  this.showPointerOnHover = false,
  this.pointerBuilder,
  this.pointerColor,
  this.pointerSize = const Size(16, 12),
})  : _type = _LegendType.bar,
      enableToggleInteraction = false,
      toggledItemColor = null,
      toggledItemStrokeColor = null,
      toggledItemStrokeWidth = 0.0,
      toggledItemOpacity = 0.0,
      iconType = MapIconType.circle,
      iconSize = const Size(8.0, 8.0),
      assert(spacing >= 0);