getRegions method
The function getRegions
retrieves a list of regions from a method channel and converts the JSON
response into a list of Region
objects.
@param {String} regionId
- The regionId
parameter is an optional parameter of type String
.
It is used to specify a specific region ID for which you want to retrieve the regions. If
regionId
is not provided, the method will retrieve all regions.
@returns The method is returning a Future object that resolves to a List of Region objects.
Implementation
@override
Future<List<Region>?> getRegions([String? regionId]) async {
final returnVal =
await methodChannel.invokeMethod<String>('getRegions', regionId);
List<Region>? regions = [];
if (returnVal != null) {
regions = (jsonDecode(returnVal) as List)
.map((i) => Region.jsonToObj(i))
.toList();
}
return regions;
}