Skip to content

Commit f01ba42

Browse files
authored
docs: add an FDv2 example app for the Flutter SDK (#316)
Stacked on #314 (the Flutter FDv2 exposure). A runnable example app demonstrating FDv2 in the Flutter SDK. ## What it shows - Enabling the data system via `LDConfig(..., dataSystem: DataSystemConfig())`. - Switching connection modes at runtime with `LDClient.setConnectionMode(...)`. Registered in the melos workspace (`packages/flutter_client_sdk/example_fdv2`). Modeled on js-core's react-native `example-fdv2`. `flutter analyze` clean on the example `lib/`. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Example-only and documentation; no changes to the published SDK library code paths. > > **Overview** > Adds **`packages/flutter_client_sdk/example_fdv2`**, a runnable manual-test app for the Flutter SDK’s FDv2 data path, and registers it in **`melos.yaml`** so `melos bootstrap` links the local SDK. > > The demo UI wires **`LDConfig`** with **`dataSystem: DataSystemConfig()`** (FDv2 opt-in), **`CredentialSource.fromEnvironment()`**, and a sample user context. It surfaces live **`dataSourceStatusChanges`**, **`flagChanges`** / **`allFlags()`**, runtime **`setConnectionMode`** (automatic, streaming, polling, background, offline), and **`identify`** with result feedback. A **README** documents credentials via `--dart-define` and expected manual checks. > > Platform scaffolding (Android/iOS/web/desktop) is standard Flutter template output; the meaningful product change is the example app plus melos membership, not SDK internals. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f9be9de. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 54cc74a commit f01ba42

128 files changed

Lines changed: 4895 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

melos.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ environment:
66
packages:
77
- packages/*
88
- packages/flutter_client_sdk/example
9+
- packages/flutter_client_sdk/example_fdv2
910
- apps/*
1011

1112
scripts:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "d438f2e52741f027ab11fb4e0c45b666d0a621c5"
8+
channel: "master"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
17+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
18+
- platform: android
19+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
20+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
21+
- platform: ios
22+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
23+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
24+
- platform: linux
25+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
26+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
27+
- platform: macos
28+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
29+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
30+
- platform: web
31+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
32+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
33+
- platform: windows
34+
create_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
35+
base_revision: d438f2e52741f027ab11fb4e0c45b666d0a621c5
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# LaunchDarkly FDv2 Demo
2+
3+
A manual testing app for the FDv2 data system in the Flutter client SDK.
4+
5+
## What it demonstrates
6+
7+
- Opting into the FDv2 protocol with `dataSystem: DataSystemConfig()`.
8+
- Live flag updates over the FDv2 streaming synchronizer, including the
9+
polling initializer that runs first.
10+
- Switching connection modes (streaming, polling, offline) at runtime via
11+
`LDClient.setConnectionMode`.
12+
- Identifying new contexts and watching flag data refresh.
13+
- The data source status (valid, interrupted, offline, ...) as it changes.
14+
15+
## Running
16+
17+
From the repository root, link the workspace packages first:
18+
19+
```
20+
melos bootstrap
21+
```
22+
23+
Then run with your credentials provided through the environment:
24+
25+
```
26+
cd packages/flutter_client_sdk/example_fdv2
27+
flutter run --dart-define LAUNCHDARKLY_MOBILE_KEY=<my-mobile-key>
28+
```
29+
30+
On web, use a client-side ID instead:
31+
32+
```
33+
flutter run --dart-define LAUNCHDARKLY_CLIENT_SIDE_ID=<my-client-side-id> -d chrome
34+
```
35+
36+
Flip a flag in the LaunchDarkly dashboard and the value and "All flags"
37+
sections update in place. Switch to polling and the update arrives on the
38+
next poll; switch to offline and updates stop until you go back online.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at https://dart.dev/lints.
17+
#
18+
# Instead of disabling a lint rule for the entire project in the
19+
# section below, it can also be suppressed for a single line of code
20+
# or a specific dart file by using the `// ignore: name_of_lint` and
21+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
22+
# producing the lint.
23+
rules:
24+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
25+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
26+
27+
# Additional information about this file can be found at
28+
# https://dart.dev/guides/language/analysis-options
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
.cxx/
9+
10+
# Remember to never publicly share your keystore.
11+
# See https://flutter.dev/to/reference-keystore
12+
key.properties
13+
**/*.keystore
14+
**/*.jks
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id("com.android.application")
3+
id("kotlin-android")
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id("dev.flutter.flutter-gradle-plugin")
6+
}
7+
8+
android {
9+
namespace = "com.launchdarkly.example_fdv2"
10+
compileSdk = flutter.compileSdkVersion
11+
ndkVersion = flutter.ndkVersion
12+
13+
compileOptions {
14+
sourceCompatibility = JavaVersion.VERSION_11
15+
targetCompatibility = JavaVersion.VERSION_11
16+
}
17+
18+
kotlinOptions {
19+
jvmTarget = JavaVersion.VERSION_11.toString()
20+
}
21+
22+
defaultConfig {
23+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
24+
applicationId = "com.launchdarkly.example_fdv2"
25+
// You can update the following values to match your application needs.
26+
// For more information, see: https://flutter.dev/to/review-gradle-config.
27+
minSdk = flutter.minSdkVersion
28+
targetSdk = flutter.targetSdkVersion
29+
versionCode = flutter.versionCode
30+
versionName = flutter.versionName
31+
}
32+
33+
buildTypes {
34+
release {
35+
// TODO: Add your own signing config for the release build.
36+
// Signing with the debug keys for now, so `flutter run --release` works.
37+
signingConfig = signingConfigs.getByName("debug")
38+
}
39+
}
40+
}
41+
42+
flutter {
43+
source = "../.."
44+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The SDK needs network access; declared here so release builds (which
3+
merge only this manifest) can reach LaunchDarkly. -->
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
<application
6+
android:label="example_fdv2"
7+
android:name="${applicationName}"
8+
android:icon="@mipmap/ic_launcher">
9+
<activity
10+
android:name=".MainActivity"
11+
android:exported="true"
12+
android:launchMode="singleTop"
13+
android:taskAffinity=""
14+
android:theme="@style/LaunchTheme"
15+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
16+
android:hardwareAccelerated="true"
17+
android:windowSoftInputMode="adjustResize">
18+
<!-- Specifies an Android theme to apply to this Activity as soon as
19+
the Android process has started. This theme is visible to the user
20+
while the Flutter UI initializes. After that, this theme continues
21+
to determine the Window background behind the Flutter UI. -->
22+
<meta-data
23+
android:name="io.flutter.embedding.android.NormalTheme"
24+
android:resource="@style/NormalTheme"
25+
/>
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN"/>
28+
<category android:name="android.intent.category.LAUNCHER"/>
29+
</intent-filter>
30+
</activity>
31+
<!-- Don't delete the meta-data below.
32+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
33+
<meta-data
34+
android:name="flutterEmbedding"
35+
android:value="2" />
36+
</application>
37+
<!-- Required to query activities that can process text, see:
38+
https://developer.android.com/training/package-visibility and
39+
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
40+
41+
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
42+
<queries>
43+
<intent>
44+
<action android:name="android.intent.action.PROCESS_TEXT"/>
45+
<data android:mimeType="text/plain"/>
46+
</intent>
47+
</queries>
48+
</manifest>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.launchdarkly.example_fdv2
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
5+
class MainActivity : FlutterActivity()

0 commit comments

Comments
 (0)