init method Null safety

Future<void> init(
  1. {String? userId,
  2. VideoLaunchBehavior? videoLaunchBehavior}
)

Initializes Firework SDK.

userId is used to uniquely identify device or user.

Implementation

Future<void> init({
  String? userId,
  VideoLaunchBehavior? videoLaunchBehavior,
}) async {
  final videoLaunchBehaviorUpdated =
      _videoLaunchBehavior != videoLaunchBehavior;
  if (videoLaunchBehaviorUpdated) {
    FWEventBus.getInstance().fire(
      FWEvent(
        eventName: FWEventName.videoLaunchBehaviorUpdated,
      ),
    );
  }

  final nativeMethodName = FireworkSDKNativeMethodName.init.name;
  Map<String, dynamic> arg = {};
  if (userId != null) {
    arg["userId"] = userId;
  }

  if (videoLaunchBehavior != null) {
    arg["videoLaunchBehavior"] = videoLaunchBehavior.name;
  }

  await FWMethodChannelUtil.getFirewokSDKChannel()
      .invokeMethod(nativeMethodName, arg);

  final shoppingInitNativeMethodName = ShoppingNativeMethodName.init.name;
  await FWMethodChannelUtil.getShoppingChannel().invokeMethod(
    shoppingInitNativeMethodName,
  );

  final liveStreamInitNativeMethodName = LiveStreamNativeMethodName.init.name;
  await FWMethodChannelUtil.getLiveStreamMethodChannel()
      .invokeMethod(liveStreamInitNativeMethodName);

  FWGlobalState.getInstance().completeSdkInitCalledFuture();
}