I'm working with SfMaps and when I try to load geojson data from the local assets folder using the MapShapeSource.asset() property and everything works fine. But I'm having problems when I want to load geojson data as a result from api
calling
(GET / POST) using the http package flutter.
I believe this can be solved using MapShapeSource.network(), but am still confused about how to use it.
any kind of help is very much appreciated
// Function to load data json from API
Future<void> loadGeojsonData() async {
setState(() => loading = true);
try {
final response = await http.post(
Uri.parse("some url"),
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: body);
if (response.statusCode >= 400) {
throw Exception('statusCode=${response.statusCode}');
}
setState(() {
loading = false;
data = jsonDecode(response.body);
});
} catch (e) {
setState(() => loading = false);
debugPrint("Error load data: $e");
return;
}
}
// Loadjson data from API in Map Shape Source.network() but not sure how to do it
dataSource = MapShapeSource.network(
'url',
shapeDataField: 'name',
);