getLocation method

  1. @override
Stream<Either<String, LocationModel>> getLocation({
  1. ConfigLocationManager? config,
})
override

Implementation

@override
Stream<Either<String, LocationModel>> getLocation({
  ConfigLocationManager? config,
}) {
  try {
    final locationStream = eventChannel.receiveBroadcastStream(
      [
        config?.toJson(),
      ],
    ).map<Right<String, LocationModel>>(
      (dynamic element) {
        final result = LocationModel.fromMap(
          element.cast<String, dynamic>(),
        );
        return Right(result);
      },
    );
    return locationStream;
  } catch (e) {
    if (e is PlatformException) {
      return Stream.value(
        const Left<String, LocationModel>("Platform Exception"),
      );
    }
    return Stream.value(
      const Left<String, LocationModel>("Unknown Exception"),
    );
  }
}