init method
- String? mobileKey,
- String? userKey, {
- LaunchDarklyConfig? config,
- LaunchDarklyUser? user,
- Map<
String, dynamic> ? custom, - Map<
String, dynamic> ? privateCustom,
Initializes and blocks for up to 5 seconds
until the client has been initialized. If the client does not initialize within
5 seconds, it is returned anyway and can be used, but may not
have fetched the most recent feature flag values.
mobileKey
is the mobile key from your Environments page in LaunchDarkly.
Additional configuration can be set via the optional config
.
userKey
is the user id considered by LaunchDarkly for feature flag targeting and rollouts.
The userKey should also uniquely identify each user. You can use a primary key, an e-mail address,
or a hash, as long as the same user always has the same key. We recommend using a hash if possible.
You can also distinguish logged-in users from anonymous users in the SDK by leaving the userKey parameter null.
You can pass built-in user attributes as LaunchDarklyUser in user
.
You can pass custom attributes and private custom attributes in custom
and privateCustom
maps accordingly.
Please note private attributes take precedence over non-private ones.
Implementation
Future<bool?> init(
String? mobileKey,
String? userKey, {
LaunchDarklyConfig? config,
LaunchDarklyUser? user,
Map<String, dynamic>? custom,
Map<String, dynamic>? privateCustom,
}) async {
if (userKey == null) {
return await _channel.invokeMethod('init', <String, dynamic>{
'mobileKey': mobileKey,
'config': config?.toMap(),
'user': user?.toMap(),
'custom': {
if (custom != null) ...custom,
if (privateCustom != null) ...privateCustom,
},
'privateAttributes': privateCustom?.keys.toList(),
});
} else {
return await _channel.invokeMethod('init', <String, dynamic>{
'mobileKey': mobileKey,
'userKey': userKey,
'user': user?.toMap(),
'config': config?.toMap(),
'custom': {
if (custom != null) ...custom,
if (privateCustom != null) ...privateCustom,
},
'privateAttributes': [
if (user != null) ...user.privateAttributes,
if (privateCustom != null) ...privateCustom.keys,
],
});
}
}