Okay, I have done more research and feel like I am close to doing this.
I have a MapModel class as follows:
class MapModel {
//data type
String? name; //can be null
Color? color;
//constructor
MapModel(this.name, this.color);
//method that assigns values to respective datatype variables
MapModel.fromJson(Map<String,dynamic> json){
name = json["NAME"];
color = json["COLOR"];
}
}
Then I have a late initialized variable _mapData as follows:
@override
void initState() {
super.initState();
//_mapData = readJson() as List<MapModel>; //await will wait for Future to get complete
_asyncMethod();
_shapeSource = MapShapeSource.asset('assets/uvu_map_updated.json',
shapeDataField: 'NAME',
dataCount: _mapData.length,
primaryValueMapper: (int index) => _mapData[index].name!, //! means you know value will never be null
dataLabelMapper: (int index) => _mapData[index].name!,
shapeColorValueMapper: (int index) => _mapData[index].color
);
_zoomPanBehavior = MapZoomPanBehavior();
}
_asyncMethod() async{
_mapData = await readJson();
}
But I am getting an error LATEINITIALIZATIONERROR that my _mapData has not been initialized.