Currently, the LaunchDarkly Flutter SDK stores a device-level unique identifier (the ld_device context) using SharedPreferences, but this value is not accessible through the public API. I have resorted to manually reading shared preferences to retrieve it, which is brittle and relies on internal key formats that may change.
💡 Motivation
- The device ID is essential for correlating evaluations or analytics across devices and backend systems.
- There’s currently no safe, stable alternative to manually parsing shared preferences, which risks breaking in future versions.
- Offering official access would improve developer experience and support valid use cases like debugging, analytics, or correlating logs.
❌ Actual implementation
/// Encoder method
String _encodePersistenceKey(String input) {
final bytes = utf8.encode(input);
final digest = sha256.convert(bytes);
// This will be the hex encoded digest.
return digest.toString();
}
final _preferences = await SharedPreferences.getInstance();
final _deviceIdLaunchy = _preferences.getString(
'LaunchDarkly_AutoEnvContextKey.${_encodePersistenceKey('ld_device')}',
);
debugPrint('deviceId: $_deviceIdLaunchy');
✅ Desired API
Expose a new asynchronous method on LDClient, such as:
Future<String?> getDeviceId();
That returns the same ld_device UUID stored internally. It could be available once the client has been started.
🛠️ Proposed Implementation
- Dart-side: add
getDeviceId() to LDClient in launchdarkly_flutter_client_sdk.dart, exposing the value.
- Testing: Add unit tests that confirm the device ID matches across calls and persists across restarts.
- Documentation: Include usage in
README and CHANGELOG.
I’d be happy to draft a PR implementing this feature, including all necessary code, tests, and documentation.
Please let me know if this aligns with the project’s goals, I can begin right away 🙏
Currently, the LaunchDarkly Flutter SDK stores a device-level unique identifier (the
ld_devicecontext) usingSharedPreferences, but this value is not accessible through the public API. I have resorted to manually reading shared preferences to retrieve it, which is brittle and relies on internal key formats that may change.💡 Motivation
❌ Actual implementation
✅ Desired API
Expose a new asynchronous method on
LDClient, such as:That returns the same
ld_deviceUUID stored internally. It could be available once the client has been started.🛠️ Proposed Implementation
getDeviceId()toLDClientinlaunchdarkly_flutter_client_sdk.dart, exposing the value.READMEandCHANGELOG.I’d be happy to draft a PR implementing this feature, including all necessary code, tests, and documentation.
Please let me know if this aligns with the project’s goals, I can begin right away 🙏