launchdarkly / flutter-client-sdk

LaunchDarkly Client-side SDK for Flutter mobile applications
Other
15 stars 17 forks source link

Migration Issue Flutter 4.6.0 with rebuilding/updating existing context with new attributes #161

Closed mkhtradm01 closed 1 month ago

mkhtradm01 commented 1 month ago

Is this a support request? No, even though a support request is opened but it would be better to open it here for more technical insight and interaction.

Describe the bug When updating context using client.identify(updatedContext).

Sometimes the updatedContext is invalid, even though all attributes are provided and the context kind and key remain the same like in the initial context, just to update an attribute of existing context.

To reproduce

Future<void> setLDContext({String? country})async{
      late LDContext context;
     final context = LDContextBuilder()
     .kind('user', 'user-key-123abc')
     .build();

     // second time execution when the same user provide the country at some point in the app
    if(country != null){
    context = LDContextBuilder()
    .kind('user', 'user-key-123abc')
    .setString('country', country)
    .build();
    // mostly, the first time execution the built context is valid, but when the country is available, and execute this entire script for the 
    // second time, the context turns to be invalid
    if(!context.valid){
      log("context is not valid: context");
      return;
     }

     // update the context
     await client.identify(context);
}
// first time execution
await setLDContext();

// second time execution when user input the country
final country = await getCountryFromUser(countryTextEditingInput);
await setLDContext(country: country);

Expected behavior the context remains valid in the second execution

Logs If applicable, add any log output related to your problem.

SDK version 4.6.0

Language version, developer tools flutter doctor -v [✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale en-AE) • Flutter version 3.22.1 on channel stable at /Users/adamumuktar/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision a14f74ff3a (9 weeks ago), 2024-05-22 11:08:21 -0500 • Engine revision 55eae6864b • Dart version 3.4.1 • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/adamumuktar/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/adamumuktar/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] VS Code (version 1.91.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.90.0

[✓] Connected device (4 available) • iPhone 15 Pro 17.5 (mobile) • XX-XX-XX-XX-XXXXXF41 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 127.0.6533.73

[✓] Network resources • All expected network resources are available.

• No issues found!

OS/platform macOs Sanoma 14.5 (23F79)

Additional context Add any other context about the problem here.

mkhtradm01 commented 1 month ago

Sorry there's a mix up, this fixed ✅ The cause is resetting context kind of anonymous type which should be set once in out app, at the initialization step.