MapLegend class
Shows 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.
In a rare case, 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.
The below code snippet represents how to setting default legend to the shape.
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('Default legend'),
),
body: Center(
child: SfMaps(
layers: [
MapShapeLayer(
source: _mapSource,
legend: MapLegend(MapElement.shape),
)
],
),
),
);
}
class DataModel {
const DataModel(this.country, this.count, this.storage);
final String country;
final double count;
final String storage;
}
The below code snippet represents how to setting bar legend to the shape.
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;
}
- Inheritance
-
- Object
- DiagnosticableTree
- MapLegend
- Annotations
Constructors
- MapLegend(MapElement source, {bool shouldAlwaysShowScrollbar = false, Widget? title, MapLegendPosition position = MapLegendPosition.top, Offset? offset, MapLegendOverflowMode overflowMode = MapLegendOverflowMode.wrap, Axis? direction, EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0), double spacing = 10.0, MapIconType iconType = MapIconType.circle, Size iconSize = const Size(8.0, 8.0), TextStyle? textStyle, bool enableToggleInteraction = false, Color? toggledItemColor, Color? toggledItemStrokeColor, double toggledItemStrokeWidth = 1.0, double toggledItemOpacity = 0.5})
-
Creates a legend with different styles like circle, rectangle, triangle
and square for the bubbles or shapes.
const
- MapLegend.bar(MapElement source, {bool shouldAlwaysShowScrollbar = false, Widget? title, MapLegendOverflowMode overflowMode = MapLegendOverflowMode.scroll, EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0), MapLegendPosition position = MapLegendPosition.top, Offset? offset, double spacing = 2.0, Size? segmentSize, TextStyle? textStyle, Axis? direction, MapLegendLabelsPlacement? labelsPlacement, MapLegendEdgeLabelsPlacement edgeLabelsPlacement = MapLegendEdgeLabelsPlacement.inside, MapLabelOverflow labelOverflow = MapLabelOverflow.visible, MapLegendPaintingStyle segmentPaintingStyle = MapLegendPaintingStyle.solid, bool showPointerOnHover = false, MapLegendPointerBuilder? pointerBuilder, Color? pointerColor, Size pointerSize = const Size(16, 12)})
-
Creates a bar type legend for the bubbles or shapes.
const
Properties
- direction → Axis?
-
Arranges the legend items in either horizontal or vertical direction.
final
- edgeLabelsPlacement → MapLegendEdgeLabelsPlacement
-
Place the edge labels either inside or outside of the bar legend.
final
- enableToggleInteraction → bool
-
Enables the toggle interaction for the legend.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- iconSize → Size
-
Customizes the size of the icon.
final
- iconType → MapIconType
-
Specifies the shape of the legend icon.
final
- labelOverflow → MapLabelOverflow
-
Trims or removes the legend text when it is overflowed from the
bar legend.
Defaults to MapLabelOverflow.hide.
final
- labelsPlacement → MapLegendLabelsPlacement?
-
Place the labels either between the segments or on the segments.
final
- offset → Offset?
-
Places the legend in custom position.
final
- overflowMode → MapLegendOverflowMode
-
Wraps or scrolls the legend items when it overflows.
final
- padding → EdgeInsetsGeometry?
-
Sets the padding around the legend.
final
- pointerBuilder → MapLegendPointerBuilder?
-
Returns a widget for the given value.
final
- pointerColor → Color?
-
Customizes the color of the pointer.
final
- pointerSize → Size
-
Customizes the size of the pointer.
final
- position → MapLegendPosition
-
Positions the legend in the different directions.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- segmentPaintingStyle → MapLegendPaintingStyle
-
Applies gradient or solid color for the bar segments.
final
- segmentSize → Size?
-
Customizes the size of the bar segments.
final
- shouldAlwaysShowScrollbar → bool
-
Toggles the scrollbar visibility.
final
- showPointerOnHover → bool
-
Specifies whether the pointer should be shown while hovering
on the MapLegend segments.
final
- source → MapElement
-
Shows legend for the bubbles or shapes.
final
- spacing → double
-
Specifies the space between the each legend items.
final
- textStyle → TextStyle?
-
Customizes the legend item's text style.
final
- title → Widget?
-
Sets a title for the legend.
final
- toggledItemColor → Color?
-
Fills the toggled legend item's icon and the respective shape or bubble
by this color.
final
- toggledItemOpacity → double
-
Sets the toggled legend item's text opacity.
final
- toggledItemStrokeColor → Color?
-
Stroke color for the toggled legend item's respective shape or bubble.
final
- toggledItemStrokeWidth → double
-
Stroke width for the toggled legend item's respective shape or
bubble.
final
Methods
-
copyWith(
{Axis? direction, EdgeInsetsGeometry? padding, MapLegendPosition? position, Widget? title, Offset? offset, double? spacing, MapIconType? iconType, TextStyle? textStyle, Size? iconSize, Size? segmentSize, MapLegendOverflowMode? overflowMode, bool? enableToggleInteraction, Color? toggledItemColor, Color? toggledItemStrokeColor, double? toggledItemStrokeWidth, double? toggledItemOpacity, MapElement? source, MapLegendLabelsPlacement? labelsPlacement, MapLegendEdgeLabelsPlacement? edgeLabelsPlacement, MapLabelOverflow? labelOverflow, MapLegendPaintingStyle? segmentPaintingStyle, bool? showPointerOnHover, MapLegendPointerBuilder? pointerBuilder, Color? pointerColor, Size? pointerSize}) → MapLegend - Creates a copy of this class but with the given fields replaced with the new values.
-
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}) → 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