initOpacity method

Future<void> initOpacity({
  1. String? apiKey,
})

Initialize the Opacity SDK The API key should be provided by the consuming app or retrieved from secure storage

Implementation

Future<void> initOpacity({String? apiKey}) async {
  try {
    // Use provided key or retrieve from secure storage
    final key = apiKey ?? await _storage.read(key: 'opacity_api_key');
    if (key == null || key.isEmpty) {
      print('Warning: Opacity API key not configured');
      return;
    }
    _opacityApiKey = key;

    await _flutterOpacityCorePlugin.init(
      key,
      false, // debug mode
      OpacityEnvironment.production,
      true // enable logging
    );
  } catch (e) {
    print('Error initializing Opacity SDK: $e');
    rethrow;
  }
}