Commit 4805e78
authored
feat: Debounce lifecycle, network, and setMode signals in flutter SDK (#292)
## Summary
Wires `StateDebounceManager` (from `launchdarkly_common_client`) into
the Flutter `ConnectionManager`. Lifecycle and network events feed the
debouncer rather than driving `_handleState()` directly; the debouncer's
stream emits a reconciled snapshot after the configurable window closes
(default 1s), at which point `_handleState()` runs once.
Implements CSFDV2 CONNMODE section 3.5 for the Flutter SDK.
### Notable behaviour
- `ConnectionManagerConfig` gains `debounceWindow` and
`initialApplicationState`.
- Foreground -> background flush remains synchronous (CONNMODE 3.3.1).
- Network availability propagation to the destination remains
synchronous; only the mode-resolution decision is debounced.
- `setMode(mode)` sets the override synchronously so subsequent
automatic transitions are suppressed immediately; applying the resolved
mode is debounced (CONNMODE 2.0.3 / 3.5.5).
- `FlutterStateDetector` exposes `initialApplicationState`, read
synchronously at construction time from
`SchedulerBinding.instance.lifecycleState`, so the SDK seeds the correct
lifecycle assumption when launched in background.
- `LDClient` wires the seed and substitutes `foreground` when the user
opts out of lifecycle handling
(`applicationEvents.backgrounding=false`).
## Blocked on
Depends on #291 (StateDebounceManager in common_client). After #291
merges and `launchdarkly_common_client` is released, the pin in
`packages/flutter_client_sdk/pubspec.yaml` will be bumped to that
version and this PR can be marked ready for review.
Split out of #281 to enable incremental merge / release per the
dependency-order workflow in RELEASING.md.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes when streaming/polling/offline modes apply during rapid
lifecycle and network churn; mis-seeded `initialApplicationState` could
mis-resolve mode on background launch, though behavior is heavily
tested.
>
> **Overview**
> Wires **`StateDebounceManager`** from `launchdarkly_common_client`
into Flutter **`ConnectionManager`** so lifecycle, network, and
**`setMode`** signals coalesce before **`_handleState()`** runs (default
**1s** `debounceWindow`; **`Duration.zero`** keeps prior synchronous
behavior for tests).
>
> **`ConnectionManagerConfig`** adds **`debounceWindow`** and
**`initialApplicationState`**. Foreground→background **flush** and
destination **network availability** updates stay synchronous; explicit
**`offline`** still bypasses debouncing. **`setMode`** records the
override immediately but debounces applying the resolved mode.
>
> **`FlutterStateDetector`** exposes **`initialApplicationState`** from
**`SchedulerBinding.instance.lifecycleState`**. **`LDClient`** reuses
one detector instance, seeds lifecycle when backgrounding is enabled,
and stops folding **`config.offline`** into the automatic
background/network disable flags (offline is applied via
**`_connectionManager.offline`** after construction). Bumps
**`launchdarkly_common_client`** to **1.13.0** and extends
**`connection_manager_test`** with **`fake_async`** debounce and
background-launch regression coverage.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b51ade7. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent df9415a commit 4805e78
5 files changed
Lines changed: 427 additions & 38 deletions
File tree
- packages/flutter_client_sdk
- lib/src
- test/persistence
Lines changed: 77 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
104 | 121 | | |
105 | 122 | | |
106 | 123 | | |
107 | 124 | | |
108 | 125 | | |
109 | 126 | | |
| 127 | + | |
| 128 | + | |
110 | 129 | | |
111 | 130 | | |
112 | 131 | | |
| |||
127 | 146 | | |
128 | 147 | | |
129 | 148 | | |
| 149 | + | |
| 150 | + | |
130 | 151 | | |
131 | 152 | | |
132 | 153 | | |
| |||
140 | 161 | | |
141 | 162 | | |
142 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
143 | 169 | | |
144 | 170 | | |
145 | 171 | | |
| |||
157 | 183 | | |
158 | 184 | | |
159 | 185 | | |
160 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
161 | 191 | | |
162 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
163 | 204 | | |
164 | 205 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 206 | + | |
171 | 207 | | |
172 | 208 | | |
173 | 209 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 210 | + | |
182 | 211 | | |
183 | 212 | | |
184 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
185 | 240 | | |
186 | 241 | | |
187 | 242 | | |
| |||
228 | 283 | | |
229 | 284 | | |
230 | 285 | | |
| 286 | + | |
| 287 | + | |
231 | 288 | | |
232 | 289 | | |
233 | 290 | | |
234 | | - | |
235 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
236 | 295 | | |
237 | 296 | | |
238 | | - | |
| 297 | + | |
239 | 298 | | |
240 | 299 | | |
241 | 300 | | |
| |||
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
28 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
29 | 41 | | |
30 | 42 | | |
31 | 43 | | |
| |||
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
44 | 68 | | |
45 | 69 | | |
46 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
| 89 | + | |
89 | 90 | | |
90 | | - | |
| 91 | + | |
91 | 92 | | |
92 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
93 | 97 | | |
94 | | - | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
0 commit comments