Flutter SDK Getting Started
Initializing the SDK
We recommend initializing the SDK once and pass around the client instance around in your app. Using the builder pattern we can initialize the DevCycle SDK by providing the DevCycleUser and DevCycle mobile SDK key:
import 'package:devcycle_flutter_client_sdk/devcycle_flutter_client_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static final user = DevCycleUserBuilder().isAnonymous(true).build();
static final options = DevCycleOptionsBuilder().logLevel(LogLevel.error).build();
final _devcycleClient = DevCycleClientBuilder()
.sdkKey('<DEVCYCLE_MOBILE_SDK_KEY>')
.user(user)
.options(options)
.build();
@override
void initState() {
super.initState();
}
...
}
The user object may specify a userId
for a given User. If the userId
is not specified, the User is considered to be anonymous.
DevCycleClient Builder
The DevCycleClient can be built using the following methods:
Method | Parameter | Description |
---|---|---|
sdkKey | String | DevCycle SDK Key |
user | DevCycleUser | DevCycleUser object |
options | DevCycleOptions | DevCycleOptions object |
DevCycleUser Builder
The DevCycleUser can be built using the following methods:
Method | Parameter | Description |
---|---|---|
userId | String | Unique user ID |
isAnonymous | Bool | Boolean to indicate if the user is anonymous |
String | User's email | |
name | String | User's name |
language | String | User's language |
country | String | User's country |
customData | [String: Any] | Key/value map of properties to be used for targeting |
privateCustomData | [String: Any] | Key/value map of properties to be used for targeting. Private properties will not be included in event logging. |
DevCycleOptions Builder
The SDK exposes various initialization options which can be used by passing a DevCycleOptions
object to the options
method of DevCycleClient.builder()
:
Method | Parameter | Default | Description |
---|---|---|---|
flushEventsIntervalMs | Int | 10000 | Controls the interval between flushing events to the DevCycle servers in milliseconds, defaults to 10 seconds. |
disableCustomEventLogging | Boolean | false | Disables logging of custom events generated by calling .track() method to DevCycle. |
disableAutomaticEventLogging | Boolean | false | Disables logging of SDK generated events (e.g. variableEvaluated, variableDefaulted) to DevCycle. |
logLevel | LogLevel | error | Set log level of the default logger. Defaults to error |
enableEdgeDB | Boolean | false | Enables the usage of EdgeDB for DevCycle that syncs User Data to DevCycle. |
configCacheTTL | Int | 604800000 | The maximum allowed age of a cached config in milliseconds, defaults to 7 days |
disableConfigCache | Bool | false | Disable the use of cached configs |
disableRealtimeUpdates | Bool | false | Disable Realtime Updates |
apiProxyURL | String | null | Allows the SDK to communicate with a proxy of DevCycle Client SDK API. |
eventsApiProxyURL | String | null | Allows the SDK to communicate with a proxy of DevCycle Events API. |
Notifying when DevCycle features are available
In the initialize call there is an optional onInitialized
parameter you can use to determine when your features have been loaded:
final _devcycleClient = DevCycleClientBuilder()
.sdkKey('<DEVCYCLE_MOBILE_SDK_KEY>')
.user(DevCycleUserBuilder().build())
.build()
.onInitialized((error) {
print(error)
});