getLocations method

  1. @override
Future<List<Location>?> getLocations([
  1. String? locationId
])
override

The function getLocations retrieves a list of locations from a method channel and converts the JSON response into a list of Location objects. @param {String} locationId - The locationId parameter is an optional parameter of type String. It is used to specify a specific location ID for retrieving locations. If no locationId is provided, all locations will be retrieved. @returns The method is returning a Future object that resolves to a List of Location objects.

Implementation

@override
Future<List<Location>?> getLocations([String? locationId]) async {
  final returnVal =
      await methodChannel.invokeMethod<String>('getLocations', locationId);
  List<Location>? locations;
  if (returnVal != null) {
    locations = (jsonDecode(returnVal) as List)
        .map((i) => Location.jsonToObj(i))
        .toList();
  }
  return locations;
}