setTripAutoEnd method

Future<void> setTripAutoEnd(
  1. bool shouldAutoEnd
)

Enables or disables automatic trip end detection.

Controls whether the SDK should automatically detect and stop recording trips when the vehicle stops moving for a sufficient duration. When enabled, the SDK will automatically end trip recording based on movement patterns.

Parameters:

  • shouldAutoEnd: true to enable automatic trip end, false to disable

Usage:

try {
  // Enable automatic trip end
  await communicator.setTripAutoEnd(true);
  print('Automatic trip end enabled');

  // Disable automatic trip end (manual end only)
  await communicator.setTripAutoEnd(false);
  print('Automatic trip end disabled - manual end required');
} catch (e) {
  print('Failed to change auto end setting: $e');
}

Throws:

  • Future.error("Unable to change trip auto end pref"): When setting update fails

Important Notes:

  • Setting persists across app sessions
  • When disabled, trips must be stopped manually using stopTrip
  • Overrides the initial configuration from Kruzr360InitConfig
  • Changes take effect immediately for active trips

Use Cases:

  • User preference settings
  • Fleet management policies
  • Long stop scenarios (gas stations, shopping)
  • Testing and debugging scenarios

Implementation

Future<void> setTripAutoEnd(bool shouldAutoEnd) async {
  try {
    await kruzr_comm.setTripAutoEnd(shouldAutoEnd);
  } on PlatformException catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in setTripAutoEnd");
      print(stackTrace);
      print(e);
    }
    return Future.error({"code": e.code, "message": e.message, "details": e.details});
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in setTripAutoEnd");
      print(stackTrace);
      print(e);
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
  return;
}