Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing options logic #297

Open
stippo-tech opened this issue Jan 25, 2024 · 0 comments
Open

Passing options logic #297

stippo-tech opened this issue Jan 25, 2024 · 0 comments

Comments

@stippo-tech
Copy link

stippo-tech commented Jan 25, 2024

In the latest SDK version (6.12.2), the class AppsflyerSdk has some initialization logic in the initSdk() method, but it also takes options as an argument. Additionally, AppsflyerSdk is a singleton. This logic leads to calls like AppsflyerSdk(null) every time after the object AppsflyerSdk is created. Also it is not obvious why calls like AppsflyerSdk([anyOtherAppsflyerOptions]) return the same instance of AppsflyerSdk. Please consider moving the logic for passing options to the initSdk() method.

To avoid this issue I need to wrap AppsflyerSdk in wrappers like this.

import 'package:appsflyer_sdk/appsflyer_sdk.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:my_application/app_consts.dart';

class AppsflyerWrapper {
  AppsflyerSdk? _appsflyerSdk;

  Future<void> init({
    double? timeToWaitForATTUserAuthorization,
    String? appInviteOneLink,
    bool? disableAdvertisingIdentifier,
    bool? disableCollectASA,
  }) async {
    final packageName =
        await PackageInfo.fromPlatform().then((info) => info.packageName);
    _appsflyerSdk ??= AppsflyerSdk(AppsFlyerOptions(
      afDevKey: AppConsts.afDevKey,
      appId: packageName,
      showDebug: false,
      timeToWaitForATTUserAuthorization: timeToWaitForATTUserAuthorization,
      appInviteOneLink: appInviteOneLink,
      disableAdvertisingIdentifier: disableAdvertisingIdentifier,
      disableCollectASA: disableCollectASA,
    ));
    await _appsflyerSdk?.initSdk();
  }

  Future<String?> getUid() async => _appsflyerSdk?.getAppsFlyerUID();

  Future<bool?> logEvent(
          String eventName, Map<dynamic, dynamic>? eventValues) async =>
      _appsflyerSdk?.logEvent(eventName, eventValues);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant