attachToHostSdk method

  1. @override
Future<bool> attachToHostSdk({
  1. required bool enableIntegrationTesting,
})
override

Starts the Embrace SDK.

Implementation

@override
Future<bool> attachToHostSdk({required bool enableIntegrationTesting}) async {
  if (isStarted) {
    if (kDebugMode) {
      print('Embrace SDK has already started!');
    }
    return false;
  }

  _isStarted = true;

  debugPrint('Embrace Flutter SDK Version: $packageVersion');

  methodChannel.setMethodCallHandler(handleMethodCall);

  // Check android version
  if (kDebugMode && _platform.isAndroid) {
    final nativeAndroidVersionStr = await _getNativeSdkVersion();
    if (nativeAndroidVersionStr != null) {
      final nativeVersion = SdkVersion(nativeAndroidVersionStr);
      if (nativeVersion.isLowerThan(minimumAndroidVersion)) {
        if (kDebugMode) {
          print('WARNING: You are using Embrace Android SDK '
              '$nativeAndroidVersionStr which is lower than the minimum '
              '$minimumAndroidVersion. '
              'See https://embrace.io/docs/flutter/integration/add-embrace-sdk/#android-setup '
              'for more information.');
        }
        logWarning(
          'Embrace Android SDK version ($nativeAndroidVersionStr) is lower '
          'than required minimum $minimumAndroidVersion.',
          null,
        );
      }
    }
  }

  final success = await methodChannel.invokeMethod<bool?>(
        _attachSdkMethodName,
        {
          _enableIntegrationTestingArgName: enableIntegrationTesting,
          _embraceFlutterSdkVersionArgName: packageVersion,
          _dartRuntimeVersionArgName: _platform.version.replaceAll('"', ''),
        },
      ) ??
      false;
  if (!success) {
    if (kDebugMode) {
      print(
        'The Embrace SDK was not started in Android/iOS native code '
        'and it will be initialized by the Flutter SDK. We '
        'recommend adding native initialization to report more accurate '
        'start up times (see '
        'https://embrace.io/docs/flutter/integration/session-reporting/#add-the-android-sdk-start-call '
        'for Android and '
        'https://embrace.io/docs/flutter/integration/session-reporting/#add-the-ios-sdk-start-call '
        'for iOS).',
      );
    }
  } else {
    if (kDebugMode) {
      print('Embrace Flutter SDK attached to host SDK successfully.');
    }
  }
  return success;
}