getTripList function

Future<List<SingleTripResponse>> getTripList(
  1. int offset,
  2. int limit
)

Implementation

Future<List<SingleTripResponse>> getTripList(int offset, int limit) async {
  try {
    String result = await platform.invokeMethod('getTripList', {
      "offset": offset,
      "limit": limit,
    });
    if (kDebugMode) {
      print("Received Trip List: $result");
    }
    var decodedList = jsonDecode(result);
    if (kDebugMode) {
      print("decoded Trip List: $decodedList");
    }
    List<SingleTripResponse> list = List<SingleTripResponse>.from(
      decodedList.map((model) {
        SingleTripResponse singleTripResponse = SingleTripResponse.fromJson(
          model,
        );

        return singleTripResponse;
      }),
    );

    if (kDebugMode) {
      print("-> Trip List: $list");
    }

    return list;
  } on PlatformException catch (e, stacktrace) {
    if (kDebugMode) {
      print(e);
      print(stacktrace);
    }
    rethrow;
  } catch (e, stacktrace) {
    if (kDebugMode) {
      print(e);
      print(stacktrace);
    }
    throw PlatformException(code: "PLUGIN_ERROR", message: e.toString());
  }
}