overflowMode property

MapLegendOverflowMode overflowMode

Wraps or scrolls the legend items when it overflows.

In wrap mode, overflowed items will be wrapped in a new row and will be positioned from the start.

If the legend position is left or right, scroll direction is vertical. If the legend position is top or bottom, scroll direction is horizontal.

Defaults to MapLegendOverflowMode.wrap for default legend and MapLegendOverflowMode.scroll for bar legend.

late List<DataModel> _data;
late MapShapeSource _mapSource;

 void initState() {

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

   _mapSource = MapShapeSource.asset(
     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)

 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(
       title: Text('Default legend'),
     body: Center(
       child: SfMaps(
         layers: [
             source: _mapSource,
             legend: MapLegend(
               overflowMode: MapLegendOverflowMode.scroll,

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

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

See also:

  • position, to set the position of the legend.
  • direction, to set the direction of the legend.


final MapLegendOverflowMode overflowMode;