Flutter

Apptimize supports Flutter applications built for iOS and Android devices as a wrapper around the existing iOS and Android SDKs. You do not need to manage the installation of those SDKs, you need only add the plugin to your Flutter project.

SDK Installation

Install from pub.dev

The Apptimize flutter plugin is published on pub.dev as apptimize_flutter. The latest installation instructions for your version of flutter will always be displayed on the Installing tab.

  1. Update your dependencies in pubspec.yaml, adding apptimize_flutter.

    dependencies:
        apptimize_flutter: ^2.0.0
    
  2. Install it.

    • From the terminal: Run flutter pub get.

    OR

    • From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec.yaml.

    • From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec.yaml.

  3. Import it. In each dart files you wish to use apptimize, add the following import statement:

    import 'package:apptimize_flutter/apptimize_flutter.dart';
    
  4. Stop and restart the app. This package brings platform-specific code for iOS and Android and that code must be built into your app. Hot reload and hot restart only update the Dart code, so a full restart of the app might be required to avoid errors like MissingPluginException when using the package.

  5. After that, sign in to the Apptimize dashboard and configure your tests.

You can find our latest Flutter Plugin Documentation here.

Initializing Apptimize

To initialize Apptimize, call the Apptimize.startApptimize() method with the App Key associated with your app, which can be found in the Install tab of your Dashboard.

Synchronous and Asynchronous Loading

To ensure the best experience for your end users, we recommend waiting to display your application content until Apptimize has been fully loaded and initialized. This will prevent situations where an outsized percentage of users are placed in the baseline variant because the experiment data hasn’t been fully received and processed by the SDK.

The sample code below shows how to use Apptimize.apptimizeInitializedStream to determine when Apptimize setup and initialization is complete.

Create an onApptimizeInitialized method.

// Create a function that will be executed whenever new
// Apptimize metadata is downloaded
Future<void> onApptimizeInitialized(ApptimizeInitializedEvent e) async {
    print("Apptimize setup and initialization complete");
    await Apptimize.track("Apptimize Initialized");

    // Set a flag to indicate Apptimize data is available
    // and content can be displayed
}

And put the following in your startup code.

Apptimize.apptimizeInitializedStream.listen((event) => {
    onApptimizeInitialized(event)
});
await Apptimize.startApptimize("<appkey>");

EU Cloud Site

Set the serverRegion property of the ApptimizeOptions class to EUCS and then pass this options instance to Apptimize.setup to set your Apptimize region to EUCS if you are integrated in our EU Cloud site.

var apptimizeOptions = new ApptimizeOptions();
apptimizeOptions.serverRegion = ApptimizeServerRegion.EUCS;

// Set additional options here...

await Apptimize.startApptimize(apptimizeAppKey, apptimizeOptions);

Troubleshooting

Cocoapods errors

[!] Automatically assigning platform `ios` with version `9.0` on target `Runner` because no platform
was specified. Please specify a platform for this target in your Podfile. See
`https://guides.cocoapods.org/syntax/podfile.html#platform`.