flutter_drivekit_trip_analysis 0.0.3
flutter_drivekit_trip_analysis: ^0.0.3 copied to clipboard
Flutter plugin for DriveQuant's DriveKit trip analysis SDK
DriveKit Trip Analysis plugin #
Flutter interface for the DriveKit Trip Analysis
To learn more about DriveKit, please visit our DriveKit documentation
Installation #
To use this plugin, run this command in your project
flutter pub add drivekit_trip_analysis
Now, you can import 'package:flutter_drivekit_trip_analysis/flutter_drivekit_trip_analysis.dart' and use DriveKitTripAnalysis in your Dart code.
Usage #
You need to install the flutter_drivekit_core plugin and follow the instructions to specify the API key and the user identifier.
Then, you can start using the Drivekit Trip Analysis plugin. For example, you can activate the auto start mode with the following code:
final tripAnalysis = DriveKitTripAnalysis()
tripAnalysis.activateAutoStart(true);
Please refer to the DriveKit Trip Analysis documentation for more information about the features we provide.
Manual initialization #
If you have disabled the DriveKit auto-initialization:
- On Android project, call
initializemethod ofDriveKitTripAnalysisclass inside yourMainApplicationclass.
// MainApplication.kt
// …
override fun onCreate() {
super.onCreate()
DriveKit.initialize()
val tripNotification: TripNotification = ...
DriveKitTripAnalysis.initialize(tripNotification)
// Initialize every other DriveKit modules you use:
// DriveKitDriverData.initialize()
// etc.
}
- On iOS project, call
initializemethod inside yourAppDelegate.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DriveKit.shared.initialize()
DriveKitTripAnalysis.shared.initialize(appLaunchOptions: launchOptions)
(…)
}
API #
| Method | Return Type | iOS | Android |
|---|---|---|---|
| activateAutoStart() | Future<void> |
✅ | ✅ |
| startTrip() | Future<void> |
✅ | ✅ |
| stopTrip() | Future<void> |
✅ | ✅ |
| cancelTrip() | Future<void> |
✅ | ✅ |
| isTripRunning() | Future<bool> |
✅ | ✅ |
| activateCrashDetection() | Future<void> |
✅ | ✅ |
| setMonitorPotentialTripStart() | Future<void> |
✅ | ✅ |
| getMonitorPotentialTripStart() | Future<bool> |
✅ | ✅ |
| setVehicle() | Future<bool> |
✅ | ✅ |
activateAutoStart #
Future<void> activateAutoStart(bool activate);
The automatic mode detects vehicle movements and triggers the trip analysis without driver intervention while the application is in background. The analysis is stopped automatically at the end of the trip.
This feature is recommended to avoid driver distraction and phone handling while driving. The automatic mode has been optimized to limit the battery drain.
By default, auto start is disabled. To enable automatic trip detection mode, call the following method:
driveKitTripAnalysis.activateAutoStart(true);
To disable automatic trip detection call the same method with parameter enable set to false
driveKitTripAnalysis.activateAutoStart(false);
⚠️
If a trip is running when automatic trip detection is disabled, the trip will not be cancelled. If you want to cancel the trip, you should also call
cancelTripmethod.
startTrip #
Future<void> startTrip();
You can start a trip by calling the following method:
driveKitTripAnalysis.startTrip
ℹ️
If a trip's already started, calling this method will have no effect.
stopTrip #
Future<void> stopTrip();
You can stop a trip by calling the following method. The trip will be stopped instantly:
driveKitTripAnalysis.stopTrip
ℹ️
If a vehicle stops longer than the timeout configured, the trip will be stopped automatically.
ℹ️
If there is no running trip, calling this method will have no effect.
cancelTrip #
Future<void> cancelTrip();
If you want to cancel a trip, you can call this method:
driveKitTripAnalysis.cancelTrip
isTripRunning #
Future<bool> isTripRunning();
This method returns false if the SDK is in INACTIVE state, and no trip is currently running.
final isTripRunning = await driveKitTripAnalysis.isTripRunning();
activateCrashDetection #
activateCrashDetection(enable: boolean): Promise<void>
Crash detection features, included into the DriveKit Trip Analysis component, is able to collect and analyse smartphone sensors data to automatically detect when a car accident occurs.
Learn more about the feature on iOS / on Android
An input parameter is available in DriveKitTripAnalysis to enable or disable the feature:
Future<void> activateCrashDetection(bool activate);
To disable crash detection, call the method with parameter to false
driveKitTripAnalysis.activateCrashDetection(false);
setMonitorPotentialTripStart #
Future<void> setMonitorPotentialTripStart(bool activate);
DriveKit's automatic start mode detects a trip and launches its recording immediately. This operating mode may not be appropriate for all use cases.
Your application may require other information or business logic before enabling the trip recording. For example, it may be appropriate to check that:
- A connected device is near to the smartphone.
- The trip recording is acceptable in a given time slot.
In this case, you may want to subscribe to the events that are indicative of the trip start but not necessarily launch the GPS sensor and the trip analysis.
This is why DriveKit allows you to subscribe to trigger events that indicate that a trip has probably started.
Learn more about the feature on iOS / on Android
By default, the configuration is disabled. Call the following method with parameter to true to enable it.
DrivekitTripAnalysis.setMonitorPotentialTripStart(true);
To disable the feature, call the method with parameter to false
DrivekitTripAnalysis.setMonitorPotentialTripStart(false);
getMonitorPotentialTripStart #
Future<bool> getMonitorPotentialTripStart();
Check if the feature is activated or not with the following command:
final monitorPotentialTripStart = await DrivekitTripAnalysis.getMonitorPotentialTripStart();
setVehicle #
Future<void> setVehicle(Vehicle vehicle);
To obtain a more precise analysis on driving behaviour, it's recommended to configure the vehicle used by the driver. You can do this by calling the following method:
DrivekitTripAnalysis.instance.setVehicle(
const Vehicle(
carTypeIndex: 2,
carEngineIndex: 2,
carPower: 200,
carMass: 1500,
carGearboxIndex: 3,
carConsumption: 6.5,
carAutoGearboxNumber: 1,
engineDisplacement: 1500,
carPassengers: 2,
length: 4.7,
width: 1.9,
height: 1.5,
engineCylinderNb: 6,
driveWheels: 1,
),
);
A detailed description of vehicle parameter is available here.
ℹ️
If no vehicle is configured a default vehicle will be configured with following parameters:
carTypeIndex = 1
carEngineIndex = 1
carPower = 150
carMass = 1400
carGearboxIndex = 2
carConsumption = 4.5
engineDisplacement = 1200
frontTireSize = "205/55/16"
rearTireSize = "205/55/16"
length = 4.5
width = 1.8
height = 1.45
engineCylinderNb = 4
driveWheels = 0