MapShapeSource.asset constructor

const MapShapeSource.asset(
  1. String name, {
  2. String? shapeDataField,
  3. int dataCount = 0,
  4. IndexedStringValueMapper? primaryValueMapper,
  5. List<MapColorMapper>? shapeColorMappers,
  6. List<MapColorMapper>? bubbleColorMappers,
  7. IndexedStringValueMapper? dataLabelMapper,
  8. IndexedDoubleValueMapper? bubbleSizeMapper,
  9. IndexedColorValueMapper? shapeColorValueMapper,
  10. IndexedColorValueMapper? bubbleColorValueMapper,
})

Creates a layer using the .json file from an asset bundle.

late MapShapeSource _mapSource;

@override
void initState() {
  _mapSource = MapShapeSource.asset(
    'assets/Ireland.json',
    shapeDataField: 'name',
  );

 super.initState();
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Asset sample'),
    ),
    body: Container(
      color: Colors.blue[100],
      child: SfMaps(
        layers: [
          MapShapeLayer(
            source: _mapSource,
            showDataLabels: true,
            color: Colors.orange[100],
          ),
       ],
      ),
    ),
  );
}

Implementation

const MapShapeSource.asset(
  String name, {
  this.shapeDataField,
  this.dataCount = 0,
  this.primaryValueMapper,
  this.shapeColorMappers,
  this.bubbleColorMappers,
  this.dataLabelMapper,
  this.bubbleSizeMapper,
  this.shapeColorValueMapper,
  this.bubbleColorValueMapper,
})  : _path = name,
      _type = GeoJSONSourceType.asset,
      assert((primaryValueMapper != null && dataCount > 0) ||
          primaryValueMapper == null),
      assert((shapeColorMappers != null &&
              primaryValueMapper != null &&
              shapeColorValueMapper != null) ||
          shapeColorMappers == null),
      assert((bubbleColorMappers != null &&
              primaryValueMapper != null &&
              bubbleColorValueMapper != null) ||
          bubbleColorMappers == null);