Flutter SDK 4.0 Migration Guide

Amplitude Flutter SDK 4.0 features default event tracking, simplified interfaces, and wraps the latest Amplitude iOS and Android Kotlin SDKs.


  • amplitude_flutter:v3: Flutter SDK 3.0
  • amplitude_flutter:v4: Flutter SDK 4.0


Open pubspec.yaml and update the dependency:

2- amplitude_flutter: ^3
3+ amplitude_flutter: ^4.0.0-beta.1


Flutter SDK 4.0 offers an API to instrument events. To migrate to Flutter SDK 4.0, you need to update a few calls. The following sections detail which calls have changed.


Like all other calls, instance() is removed. Flutter SDK 4.0 uses the Configuration object to set the configuration. See Configuration for more information.

-import 'package:amplitude_flutter/amplitude.dart'; //
-import 'package:amplitude_flutter/identify.dart';
+import 'package:amplitude_flutter/amplitude.dart'; //
+import 'package:amplitude_flutter/configuration.dart';
6// Create the instance and initialize SDK
-final Amplitude amplitude = Amplitude.getInstance(instanceName: "project"); //
+final Amplitude amplitude = Amplitude(Configuration( //
+ apiKey: "YOUR-API-KEY",
+ serverUrl: "https://your.endpoint.com",
+ serverZone: ServerZone.eu,
+ defaultTracking: DefaultTrackingOptions(
+ sessions: true
+ )
+ ));
+await amplitude.isBuilt;


Flutter SDK 4.0 includes the following configuration changes:

  • It's more consistent across runtimes.
  • It no longer supports certain configurations.
  • It uses an instance variable for configuration, versus setters in SDK version 3.0.
  • Configuration is immutable after you pass it to Amplitude.
Flutter SDK 3.0 Flutter SDK 4.0
enableCoppaControl() or disableCoppaControl() config.enableCoppaControl
setMinTimeBetweenSessionsMillis() config.minTimeBetweenSessionsMillis
setEventUploadThreshol(d) config.flushQueueSize
setEventUploadPeriodMillis() config.flushIntervalMillis
setServerZone() config.serverZone
setServerUrl() config.serverUrl
setUseDynamicConfig() NOT SUPPORTED
setOptOut() config.optOut
setOffline() NOT SUPPORTED
trackingSessionEvents() config.defaultTracking.sessions
useAppSetIdForDeviceId() config.useAppSetIdForDeviceId

Track events

Flutter SDK 4.0 uses a unified track API to replace the following logEvent API variations:

  • withEventProperties
  • withApiProperties
  • withUserProperties
  • withGroup
  • withGroupProperties


The logEvent() API maps to track().

-amplitude.logEvent('BUTTON_CLICKED'); //
+amplitude.track(event: BaseEvent(eventType:'BUTTON_CLICKED')); //

logEvent() with event properties

-amplitude.logEvent('BUTTON_CLICKED', {"Hover Time": "100ms"}); //
+amplitude.track(event: BaseEvent(eventType:'BUTTON_CLICKED', eventProperties: {"Hover Time": "100ms"})); //

logEvent() with outOfSession

logEvent() receives an optional boolean argument outOfSession. The new track() API doesn't support it. You can still track an event as out-of-session by setting event.sessionId = -1.

-amplitude.logEvent("BUTTON_CLICKED", outOfSession: true); //
+amplitude.track(event: BaseEvent(eventType:'BUTTON_CLICKED', sessionId: -1)); //


The uploadEvents() API maps to flush().

-amplitude.uploadEvents(); //
+amplitude.flush(); //

Set user properties

The APIs for setting user properties are the same, except for the removal of instance(). Here are code snippets to migrate APIs for user properties.


setUserId() remains unchanged but doesn't receive startNewSession.


setDeviceId() remains unchanged.


regenerateDeviceId() isn't supported in the Flutter SDK 4.0.


The clearUserProperties API has been removed, but you can now use the unified identify API to remove user properties.

-amplitude.clearUserProperties(); //
+final Identify identify = Identify() //
+ ..clearAll();


The setUserProperties API has been removed, but you can now use the unified identify API to add user properties.

-- Map<String, dynamic> userProps = { //
-- 'gender': 'female',
-- 'age': '20'
-- };
-- amplitude.setUserProperties(userProperties);
++ final Identify identify = Identify() //
++ ..set('gender','female')
++ ..set('age',20);
++ amplitude.identify(identify);


You can now make an identify call on amplitude without calling instance().

1final Identify identify = Identify()
2 ..set('gender','female')
3 ..set('age',20);
-Amplitude.getInstance().identify(identify); //
+amplitude.identify(identify); //

Set group properties


You can now make an identify call on amplitude without calling instance().

1// set group with a single group name
-Amplitude.getInstance().setGroup("orgId", "15"); //
+amplitude.setGroup("orgId", "15");//
4// set group with multiple group names
-Amplitude.getInstance().setGroup("sport", ["tennis", "soccer"]); //
+amplitude.setGroup("sport", ["tennis", "soccer"]); //


You can now make an identify call on amplitude without calling instance().

1final Identify identify = Identify()
2 ..set("gender", "female")
3 ..set("age", 20);
-Amplitude.getInstance().groupIdentify("groupType", "groupValue", identify); //
+amplitude.groupIdentify("groupType", "groupValue", identify); //

Tracking revenue

logRevenue() and logRevenueAmount() are replaced by revenue().

-String productId = "product001"; //
-int quantity = 2;
-double price = 20;
-double amount = 35;
-amplitude.logRevenue(productId, quantity, price);
+final Revenue revenue = Revenue() //
+ ..price = 3.99
+ ..quantity = 3
+ ..productId = "com.company.productId";
Was this page helpful?

Thanks for your feedback!

June 18th, 2024

Need help? Contact Support

Visit Amplitude.com

Have a look at the Amplitude Blog

Learn more at Amplitude Academy

© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.