initializeSDK static method

Future<void> initializeSDK(
  1. Kruzr360InitConfig kruzr360InitConfig
)

Initializes the Kruzr 360 SDK with the provided configuration.

This method must be called before using any other functionality of the Kruzr 360 SDK. It establishes the connection with the underlying native SDK and configures various SDK behaviors and settings.

Parameters:

  • kruzr360InitConfig: Configuration object containing all required initialization settings:
    • licenseKey: Valid license key provided by Kruzr for authentication
    • appName: Name of your application for identification
    • notificationChannelId: Id for the notification channel (Android)
    • shouldTripAutoEnd: Whether trips should automatically end (default: true)
    • shouldTripAutoStart: Whether trips should automatically start (default: true)
    • allowEventSyncRealTime: Whether to sync events in real-time (default: true)

Usage:

try {
  final config = Kruzr360InitConfig(
    licenseKey: 'your-license-key-here',
    appName: 'My Driving App',
    notificationChannelName: 'Trip Notifications',
    shouldTripAutoEnd: true,
    shouldTripAutoStart: true,
    allowEventSyncRealTime: false,
  );
  await Kruzr360Communicator.initializeSDK(config);
  print('SDK initialized successfully');
} catch (e) {
  print('Failed to initialize SDK: $e');
}

Throws:

  • Future.error("Unable to initialize SDK"): When the SDK fails to initialize due to platform-specific issues, invalid license key, or other initialization errors.

Platform Exceptions Handled:

  • PlatformException: Catches platform-specific errors from native Android/iOS code
  • Exception: Catches any other general exceptions during initialization

Important Notes:

  • This is a static method and should be called before creating any instance of Kruzr360Communicator
  • The method will log detailed error information in debug mode for troubleshooting purposes
  • Initialization should typically be done in your main.dart file or during app startup
  • Configuration settings affect SDK behavior throughout the app lifecycle

Example Implementation:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  try {
    final config = Kruzr360InitConfig(
      licenseKey: 'your-license-key',
      appName: 'My App',
      notificationChannelId: 'co.mycompany.myapp.notification.CHANNEL_ID_TELEMATICS',
    );
    await Kruzr360Communicator.initializeSDK(config);
    runApp(MyApp());
  } catch (e) {
    // Handle initialization failure
    print('SDK initialization failed: $e');
    // Show error dialog or fallback UI
  }
}
runApp(MyApp());

} catch (e) { // Handle initialization failure print('SDK initialization failed: $e'); // Show error dialog or fallback UI } }

Implementation

static Future<void> initializeSDK(
  Kruzr360InitConfig kruzr360InitConfig,
) async {
  try {
    await kruzr_comm.initializeSDK(kruzr360InitConfig);
  } on PlatformException catch (e) {
    if (kDebugMode) {
      print(e);
      print("PlatformException in initializeSDK");
    }
    return Future.error("Unable to initialize SDK");
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e);
      print("Exception in initializeSDK");
    }
    return Future.error("Unable to initialize SDK");
  }
}