initSdk method

Future<InitResultEntity> initSdk({
  1. required ConfigEntity config,
  2. required BridgingEntity bridging,
})

初始化sdk

Implementation

Future<InitResultEntity> initSdk({required ConfigEntity config, required BridgingEntity bridging}) async {
  final completer = Completer<InitResultEntity>();
  _onNetworkChange();
  NnsdkPlatform.instance.onListenStreamData();
  bridgingEntity = bridging;
  _initEntity = config;
  _deviceInfoEntity = await NnsdkPlatform.instance.getDeviceInfo();
  _deviceId = await NnsdkPlatform.instance.getDeviceId();

  var netStatus = await Connectivity().checkConnectivity();
  NNUtil.log("网络 $netStatus");
  if (bridging == null || !_isBridgingEntityVaild()) {
    completer.complete(InitResultEntity(success: false, errorCode: -2, errorMsg: "请检查请求服务正确"));
  } else {
    if (!netStatus.contains(ConnectivityResult.none) && !netStatus.contains(ConnectivityResult.other)) {
      // 上报巨量归因数据
      await NnsdkPlatform.instance.actionStartEnableBDA();
      // 尝试初始化GDT归因
      await initGDT();
      // 获取所有商品id,到原生获取商品
      await _getSMids();
      await _login();
      await _creatUser();
      await _allGoods();
      TrackEventRule().onAppStart();
      NNUtil.log("flutter sdk初始化 ${_initEntity?.toJson()} ${_deviceInfoEntity?.toJson()} $_deviceId ");
      if (_userLoginEntity != null && _attributionEntity != null) {
        completer.complete(InitResultEntity(success: true));
      } else {
        completer.complete(InitResultEntity(success: false, errorCode: -100, errorMsg: "初始化失败,请重试"));
      }
    } else {
      completer.complete(InitResultEntity(success: false, errorCode: -1, errorMsg: "网络无连接"));
    }
  }
  return completer.future;
}