stopTrip method

Future<bool> stopTrip()

Manually stops the current active trip.

Ends trip recording and finalizes trip data. This method is useful for manual trip control when automatic detection is not sufficient.

Returns:

  • bool: true if trip stopped successfully, false otherwise

Usage:

try {
  final stopped = await communicator.stopTrip();
  if (stopped) {
    print('Trip stopped successfully');
    // Update UI to show trip is ended
    // Optionally fetch trip summary
  } else {
    print('Failed to stop trip');
  }
} catch (e) {
  print('Error stopping trip: $e');
}

Throws:

  • Future.error("Unable to stop trip"): When trip stop fails

Important Notes:

  • Only works if there's an active trip
  • Trip data will be processed and stored
  • Triggers automatic data synchronization if enabled

Use Cases:

  • Manual trip termination
  • Override automatic detection
  • Emergency trip stop

Implementation

Future<bool> stopTrip() async {
  try {
    bool tripStoped = await kruzr_comm.stopTrip();
    return tripStoped;
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in stopTrip");
      print(stackTrace);
      print(e);
    }
    return Future.error("Unable to stop trip");
  }
}