Skip to content

feat: Expose flag values with their JSON type - #100

Merged
Zaimwa9 merged 3 commits into
mainfrom
feat/typed-flag-values
Oct 21, 2026
Merged

Zaimwa9 merged 3 commits into
mainfrom
feat/typed-flag-values

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Adds Flag.value, which holds the flag's value with its JSON type: a String, num, bool or null. Until now the SDK only exposed values as strings: stateValue turns 42 into "42" and true into "true".

The change is additive. stateValue and getFeatureFlagValue are unchanged.

  • Flag.fromJson reads value from the raw feature_state_value.
  • toJson writes value with its type, so flags restored from storage keep it. Flags cached by older versions hold a string, so they still load, with value equal to that string.
  • A flag created without a value (e.g. Flag.seed) falls back to stateValue. copyWith(stateValue: …) without a value replaces both.
  • *.g.dart is unchanged: value is excluded from codegen (includeFromJson/includeToJson: false) and handled in Flag.fromJson/toJson.

Tests cover int, double, bool, string and null values, a toJson round trip, a restore from storage, cache data from older versions, and copyWith.

This makes the SDK behavioural spec pass in #99, which reads flag.value.

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner October 21, 2026 14:51
@Zaimwa9
Zaimwa9 requested review from kyle-ssg and removed request for a team October 21, 2026 14:51
@Zaimwa9

Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

1 similar comment
@Zaimwa9

Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@themis-blindfold

Copy link
Copy Markdown

⚖️ Themis review: ✅ Ship it

The typed value is captured before the existing string conversion and is preserved through serialisation and cache restoration without changing stateValue. The package, test, and analysis checks completed successfully; no defects found.

Area Score
🎯 Correctness 5/5
🧪 Test coverage 5/5
📐 Code quality 5/5
🚀 Product impact 3/5
📝 Walkthrough
  • Flag model - retains the raw JSON value alongside the established string representation, then restores that raw value when serialising.
  • Persistence tests - cover primitive value types, JSON round trips, encrypted storage restoration, legacy string caches, and copyWith.
🧪 How to verify
  1. Run flutter test test/core/models/flag_test.dart.
  2. Run flutter test.
  3. Fetch flags containing string, integer, decimal, boolean, and null values, then confirm Flag.value retains each original type while stateValue remains a string.
  4. Enable caching, restart the client, and confirm each typed value is retained after restoring the cached flags.
    Automate: Keep the typed-value and storage round-trip cases in test/core/models/flag_test.dart.

Product take: Solid compatibility improvement: consumers can use remote-config numbers and booleans without reparsing strings.
It is a modest SDK-surface addition with useful day-to-day impact.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

Typed values arrive intact; string parsing can take the afternoon off. · reviewed at 6d616e2

@Zaimwa9

Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@Zaimwa9
Zaimwa9 requested review from khvn26 and removed request for kyle-ssg October 21, 2026 15:15
Comment thread lib/src/core/model/flag.dart Outdated
@themis-blindfold

Copy link
Copy Markdown

⚖️ Themis review: ✅ Ship it

TL;DR: Flag.value now retains scalar JSON types through API parsing and cache serialization while the existing string-based stateValue API remains intact. Completed Flutter Test, Dart Analyze, and Dart Publish Package Test checks passed; local Flutter/Dart executables were unavailable for an additional run.

Area Score
🎯 Correctness 5/5
🧪 Test coverage 5/5
📐 Code quality 5/5
🚀 Product impact 3/5
📝 Walkthrough
  • Flag model - adds a typed value alongside the backwards-compatible string stateValue.
  • Serialization and storage - preserves the raw scalar value when parsing and writing cached flags.
  • Regression coverage - covers numeric, boolean, string, null, round-trip, legacy-cache, and copyWith cases.
🧪 How to verify
  1. Run flutter test test/core/models/flag_test.dart.
  2. Parse flags with integer, double, boolean, string, and null values; verify value retains each type and stateValue remains a string representation.
  3. Save those flags through StorageProvider, reload them, and verify the typed values persist.
  4. Load a cache entry written by a previous SDK version and verify its string value remains available through both accessors.

Automate: Keep the typed-value parse and storage round-trip cases in test/core/models/flag_test.dart.

Product take: Solid SDK compatibility improvement for consumers that need native remote-config values, while preserving existing callers.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

Typed values, untyped drama avoided · reviewed at 6d616e2

Co-authored-by: Kim Gustyr <kim.gustyr@flagsmith.com>
@themis-blindfold

Copy link
Copy Markdown

⚖️ Themis review: ✅ Ship it

TL;DR: Flag.value preserves the decoded JSON type through parsing and cache serialization while leaving the existing string-valued API intact. The completed package, analysis, and Flutter test checks passed.

Area Score
🎯 Correctness 5/5
🧪 Test coverage 5/5
📐 Code quality 5/5
🚀 Product impact 3/5
📝 Walkthrough
  • Flag model - captures the raw feature-state value separately while retaining stateValue's string compatibility.
  • Cache serialization - writes the raw value back so restored flags retain numeric and boolean types.
  • Regression coverage - exercises primitive values, JSON round trips, storage restore, old caches, and copyWith.
🧪 How to verify
  1. Run flutter test test/core/models/flag_test.dart.
  2. Save and restore flags whose values are an integer, double, boolean, string, and null; confirm value retains each type.
  3. Load a cache entry written by the previous release and confirm its value remains a string.
  4. Run flutter analyze.
    Automate: The added model tests cover parsing, serialization, storage restore, and legacy-cache compatibility.

Product take: A solid compatibility improvement for remote-config consumers: callers can now use typed values without parsing strings themselves.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

Typed flags, untyped drama · reviewed at 5e161f9

@talissoncosta talissoncosta left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Zaimwa9
Zaimwa9 requested a review from khvn26 October 21, 2026 16:11
@Zaimwa9
Zaimwa9 merged commit f7798e5 into main Oct 21, 2026
3 checks passed
@Zaimwa9
Zaimwa9 deleted the feat/typed-flag-values branch October 21, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants