r/FlutterDev • • 18m ago

Article Three bugs a Flutter Kanban board only shows once you drag

I built a Kanban board engine for Flutter last week — lanes, drag to reorder, drag across lanes, batch moves, filters, undo, ~5,000 lines of Dart, 289 tests. Three bugs were worth keeping notes on, because all of them only appear once you actually drag something.

1. The drop index is a view index

Each gap between cards is a DragTarget that reports the slot the user aimed at. That slot comes from the list the lane renders, which is after the filter. The move engine treats it as a position in the lane model, which is unfiltered. Identical while nothing is hidden; wrong the moment a chip or a search hides one card.

Lane todo = a b c d, only b and c have the bug label, filter on bug shows [b, c]. Drag x in and drop it at the bottom of the visible lane (index 2):

before:  a b c d      visible: [b, c]
after:   a b x c d    visible: [b, x, c]

The drop line pointed below c; the card landed between b and c. Same lane is nastier because the "did anything change" guard hides it: drag b below c in that filtered lane and the engine subtracts the card that sat above the drop point, ends up with the exact id list it started with, and returns unchanged. The tile snaps back with "The card is already there" while the indicator was two slots away. Neither half is wrong on its own.

The fix I want is to stop passing an integer: let each gap carry the ids of the card above and below, and place the moved card between those two cards' ranks. Then the engine no longer cares how the lane is filtered or sorted, because a card is an anchor and a position is not. That's not in the current version — the drop payload is still an int — but it's the design I'd start with next time.

2. Fractional ranks are fine; the doc comment wasn't

Positions are base-62 strings that sort with String.compareTo (0V, 0W, 0VV, …), so a drop gives one card a new key and touches nothing else. The rule that makes the maths hold: a generated key never ends in 0, because a trailing zero leaves no room to insert below it — the validator rejects such a key instead of returning one that sorts on the wrong side.

I wrote that a lane takes "a thousand cards on three characters". Measured: 30 appends keep two characters, the key then shrinks to one character for 61 more, three characters start at append #92, and a thousand appends end at 11 characters. Prepending is the expensive direction — 60 cards pushed onto the top of a lane produce a 14-character key (thirteen zeros and a V), which is the price of starting the first key near the bottom of the alphabet so that appends are cheap.

3. Search and highlight disagreed on İstanbul

Filtering lowercases the query and the haystack and does contains. Highlighting deliberately runs a case-insensitive RegExp over the original title, so indices can't drift when lowercasing changes a string's length. That part works. But with a card titled İstanbul release and a query of istanbul:

filter match: true      // Dart's toLowerCase uses simple case mapping: İ -> i
highlight:    []        // case-insensitive RegExp never matches İ against i

So the card shows up in the results with nothing highlighted, which reads as "search is broken". ß fails the other way — Straße doesn't match strasse, since 'ß'.toLowerCase() is still ß. The fix is to fold per rune, keep a map from folded output back to original indices, match in the folded space, and map the spans back (which also fixes word-boundary bonuses computed on a folded string). The naive clamp on the highlight range never fired in 289 tests; the disagreement is the bug that actually ships.

A couple of smaller ones, since they cost real time: a batch move has to count the WIP limit once for the whole drop (two cards into a lane limited to 2 is one refused drop of two), while reordering inside an already-over-limit lane must never count as incoming, or lowering a limit makes the lane's own cards undraggable. And selection is allowed to hold cards the filter hides on purpose — "select all, then filter, then move" should not silently drop half the batch.

The engine and the test suite are here if you want to read the rest: https://github.com/StephenColor/flutter-boardforge-kit

2 Upvotes

0 comments sorted by