fetchTripInsightsById function

Future<TripInsights?> fetchTripInsightsById(
  1. String appTripId
)

Implementation

Future<TripInsights?> fetchTripInsightsById(String appTripId) async {
  try {
    String result = await platform.invokeMethod(
      'getTripInsightsById',
      {"appTripId": appTripId},
    );

    if (kDebugMode) {
      print("Received Trip Insights: $result");
    }

    final decoded = jsonDecode(result);

    return TripInsights.fromJson(decoded);
  } on PlatformException catch (e, stacktrace) {
    if (kDebugMode) {
      print("Error in fetchTripInsightsById");
      print(e);
      print(stacktrace);
    }
    rethrow;
  } catch (e, stacktrace) {
    if (kDebugMode) {
      print("Error in fetchTripInsightsById");
      print(e);
      print(stacktrace);
    }
    throw PlatformException(code: "PLUGIN_ERROR", message: e.toString());
  }
}