Mobile Development 11 min read

Implementing Magnifier Mode and Reverse Selection in Flutter TextField

The article details how to add a native‑style magnifier loupe and support reverse text selection to Flutter’s TextField by using CompositedTransformTarget/Follower overlays with BackdropFilter rendering, extending TextSelectionOverlay and gesture builders, tracking drag state, and swapping selection offsets when handles cross.

Xianyu Technology
Xianyu Technology
Xianyu Technology
Implementing Magnifier Mode and Reverse Selection in Flutter TextField

The article continues a series on building a rich‑text editor (Mural) on top of Flutter's TextField . It focuses on two interaction features that are missing in Flutter compared with native Android EditText and iOS UITextField : a magnifier (loupe) mode and reverse selection of a text range.

Magnifier mode – The author analyses the native behavior, identifies two scenarios (cursor positioning and selection dragging), and extracts three common characteristics: content‑centered display, floating position above the cursor/handle, and lifecycle tied to drag start/end. Three technical questions are answered:

How to attach the magnifier above the cursor or a selection handle? The solution uses Flutter's CompositedTransformFollower and CompositedTransformTarget with the existing startHandleLayerLink and endHandleLayerLink to keep the magnifier aligned.

How to render the screen area inside the magnifier? By placing a BackdropFilter in an Overlay and applying a translated‑and‑scaled matrix ( deltaOffsetFromFocusPoint ) so that the region around the cursor becomes the magnified view.

How to handle platform‑specific differences? The same overlay logic is integrated into TextSelectionOverlay to show/hide the magnifier and the toolbar during drag, while a special case for iOS long‑press is added by extending TextSelectionGestureDetectorBuilder .

Reverse selection – The author notes that iOS allows the right handle to cross the left one (reverse selection) and some Android OEMs support it, but Flutter's TextField blocks it because the handles collapse into a cursor when they meet. The proposed implementation keeps the native rule for most cases but adds a flag to indicate a handle‑drag operation. When the handles meet while the flag is set, the cursor conversion is suppressed, and after drag end the selection offsets are swapped to preserve the reverse order.

Implementation steps include:

Marking the drag state.

Displaying expanded handles during collapse.

Swapping baseOffset and extentOffset in TextSelectionOverlay after reverse drag.

The article concludes with a summary of the series, performance improvements for long‑text editing, and future work on richer rich‑text components, more platform‑aligned interactions, and further rendering optimizations.

FlutterMobile UICross-platformMagnifierselectionTextField
Xianyu Technology
Written by

Xianyu Technology

Official account of the Xianyu technology team

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.