feat_sdk library
A thin Dart/Flutter client for the feat feature-flag platform.
feat evaluates flags server side for client keys and returns resolved values only. This SDK is a thin client over those remote-evaluation endpoints: it polls for values and, optionally, holds a Server-Sent Events stream for near-instant updates. It performs no local evaluation and needs no bucketing engine.
The core library is pure Dart (no Flutter dependency) so it runs equally in
Flutter apps and pure-Dart backends. Flutter-only glue (lifecycle observer,
shared_preferences-backed storage) lives outside the core - see the
example.
Classes
- EvalContext
-
The evaluation context sent to the server on every poll and stream
connection. It mirrors the multi-context model used by the other feat
SDKs: an optional top-level targetingKey (shorthand for the user key)
plus zero or more per-kind objects, each of which must carry its own
key. - EvalContextBuilder
- Fluent builder for an EvalContext.
- EvalReason
- Well-known evaluation reasons. The set is open (the server may introduce new reasons), so treat EvaluatedFlag.reason as an opaque string and use these constants only for convenient comparisons.
- EvalStream
- Manages a single logical SSE subscription with automatic reconnection and exponential backoff. It is transport-agnostic via SseConnector.
- EvaluatedFlag
- A single flag as resolved by the server for the current context.
- FeatClient
- A thin client over the feat remote-evaluation endpoints.
- FeatClientConfig
- Configuration for a FeatClient.
- FeatStorage
- Pluggable key/value persistence used by the SDK for two things: the stable anonymous key and the last-evaluated flag snapshot (so the next start can serve cached values before the network responds).
- FlagChange
- Emitted on FeatClient.changes whenever a flag's resolved value flips, after either a context change, a poll, or a streamed update.
- InMemoryStorage
- The default, non-persistent FeatStorage. Values live only for the lifetime of the process. Suitable for pure-Dart backends and tests.
- SseConnection
- An open SSE connection: a stream of parsed events plus a teardown hook.
- SseEvent
- A parsed Server-Sent Event.
Enums
- FeatAppLifecycleState
-
App lifecycle states, mirroring Flutter's
AppLifecycleStateso a FlutterWidgetsBindingObservercan forward states 1:1 without importing Flutter into the core package. See the example for the glue. - StreamingMode
- Streaming policy for the client.
Constants
- defaultFeatBaseUrl → const String
- The default feat data-plane endpoint.
- featSdkVersion → const String
-
The published version of this SDK. Sent to the server in the
X-Feat-Sdkheader asdart/<version>so usage can be attributed.
Functions
-
buildAnonymousContext(
FeatStorage storage) → Future< EvalContext> -
Build a stable anonymous EvalContext. A UUID is minted on first use and
persisted through
storageso the same install lands in the same targeting bucket across restarts. Whenstorageis an InMemoryStorage (the default), the key is stable only for the process lifetime. -
httpSseConnector(
Client client) → SseConnector -
Default SseConnector built on
package:http. Unlike a browser EventSource, request headers can be set here, so the SDK version travels inX-Feat-Sdk; the client key and context still travel in the query string per the stream wire contract. -
parseSse(
Stream< String> lines) → Stream<SseEvent> - Transform a stream of already-split text lines into SseEvents.
-
randomUuidV4(
) → String - Generate an RFC 4122 version 4 UUID string.
Typedefs
-
SseConnector
= Future<
SseConnection> Function(Uri uri, Map<String, String> headers) -
Opens an SSE connection to
uriwith the given requestheadersand resolves once connected. Injectable so tests can supply a fake transport.
Exceptions / Errors
- FeatHttpException
- Thrown for unexpected, non-recoverable HTTP responses from the evaluate endpoint. The documented soft statuses (404 no-datafile, 403, 429) are treated as "no change" and never surface as this exception.
- SseConnectException
- Thrown by the default HTTP connector when the stream endpoint answers with a non-200 status.