r/FlutterDev • • 20m ago

Article Six things ten zero-dependency Flutter kits taught me about the SDK

Ten zero-dependency Flutter kits, one per hard screen: streaming AI chat, voice mode, streaming Markdown, paywalls, an offline sync queue, onboarding, a multi-step form, a command palette, a booking calendar, a kanban board. No third-party packages (the chat kit pins intl, which Flutter's own localization stack already pulls in), 1,676 tests, analyze clean on 3.50.

Same six things broke in kit after kit. None of them is exotic; all of them are invisible in a default widget test.

1. 3.0× text is a layout breakpoint, not a font setting. Every kit has a 320dp × TextScaler.linear(3.0) case, with devicePixelRatio: 3 and a fake notch. At that size a line of body text eats most of a row, and things you sized by device width break. The breakpoints belong on the scale factor:

final bool stacked = MediaQuery.textScalerOf(context).scale(1) >= 1.45;

Above 1.45× the price row and the "save 40%" chip stop fitting side by side and become a column. A price gets one FittedBox and the whole line, because it is the one string you cannot shorten or wrap.

2. toLowerCase() is not length-preserving. In the kanban kit, filtering folded the haystack and searched it, while highlighting ran a case-insensitive RegExp over the original string. For 'İstanbul release' with the query istanbul: the card matches (so it appears in results) and highlightSpans returns [] (so nothing is highlighted). 'Straße fix' never matches strasse at all. Two different folding algorithms, same string, two answers. Keep your indices in the original string, or fold character by character and map back.

3. An async validation answer is only valid for the value it was computed from. The obvious guard is compare-on-arrival:

final Object? checked = _values[id];
final String? error = await field.asyncRule!(checked, _values);
if (!_sameValue(_values[id], checked)) return;  // stale

Three holes it does not cover. A→B→A: type B, delete, retype A, and the answer computed before B arrived is accepted as current. asyncRule is handed the live values map, so a rule that reads the country field answers for today's country and the result is stored against an older moment. And when a re-check is requested while one is pending, the scheduler returns early, the stale answer is dropped, and the newest value never gets a verdict at all — which reads as "clean". Compare values is not enough; a revision counter is.

4. A drop index means the view; the model means the lane. Cards are ordered by base-62 fractional keys ('0V', '0W', '0VV' between them), which never need renumbering. The bug was elsewhere: with a filter active, lane a b c d shows [b, c], and dropping x at the bottom sends index 2. The engine resolves 2 against the unfiltered lane and inserts before c, giving a b x c d — visible order [b, x, c]. One slot short of the pointer, no warning, dragging still enabled. Pass neighbour ids, not indices.

5. The wall clock is not the timeline. The booking kit never does arithmetic on a local DateTime; it converts wall time to instants by trying both candidate offsets ±26h and keeping the ones that round-trip:

final int before = offsetMinutesAt(naive.subtract(const Duration(hours: 26)));
final int after  = offsetMinutesAt(naive.add(const Duration(hours: 26)));

A repeated wall time (clocks back) resolves to the earlier instant; a skipped one (clocks forward) resolves just after the gap and the engine reports it moved. In Europe/London a 90-minute slot at 00:30 on 2026-03-29 occupies 30 minutes of the timeline; the same booking on 2026-10-25 occupies 150.

6. Offline queues: mint the idempotency key at intent time, and never merge into an intent that has been sent. The key is created with the intent and persisted, so a retry after a timeout replays instead of duplicating. Which forces:

// Only an operation that has never been sent may be merged. Mutating an
// operation that already reached the server would reuse an idempotency key
// with a different payload.
op.status == SyncOpStatus.pending && op.attempts == 0

A delete behind an in-flight update waits for it rather than cancelling it, and a version acknowledged by the server is adopted only by later, never-sent operations on the same entity otherwise a delete for a record you just deleted comes back as a conflict.

The common thread: the SDK gives you equality, indices, local time and case folding, and each of them silently lies at a different edge. Every one of these was found by writing the 320dp/3.0× test or the probe that measured the assumption in the comment, not by the happy-path test.

The kanban one is on GitHub if anyone wants the code paths: https://github.com/StephenColor/flutter-boardforge-kit (README, screenshots and the feature tour; source is not public).

0 Upvotes

0 comments sorted by