Tinyrack

Inline Suggestions

Offer suggestions for the token being typed inside a text field the caller owns.

Offer suggestions for the token being typed inside a text field the caller owns.

Contract

AxisContract
OwnershipThe caller keeps its own field, controller, and focus node, and passes them as child. This component never builds or reads the field, so a multiline editor keeps every property it already had.
KeyboardA multiline editor consumes the arrow and enter keys itself, so the host calls controller.handleKeyEvent first inside its own handler. Keyboard and controller navigation keep the highlighted row in view. Anything the list does not consume comes back as KeyEventResult.ignored, which leaves Enter-to-send intact. A held modifier is never consumed, so Shift+Enter and Control+Enter stay with the field.
SessionsessionKey identifies the token being completed. Changing it resets the highlight and clears an earlier dismissal, so Escape hides the current token while a freshly typed one reopens. Results that arrive late for the same session keep the highlighted value rather than its index.
StatusEmptiness is derived from a ready list with no items, so a caller cannot describe a contradictory state. A loading list that still holds results keeps them on screen with a spinner below, which is what stops the list flickering on every keystroke.
MatchingThe caller filters, orders, and scores; this component only renders. matchedIndices names the characters of label to emphasise, so a consumer highlights a match without naming a color.

Reach for inline suggestions when only part of what someone is typing should be completed, such as a mention or a command in a longer message. Use TRAutocomplete when the whole field is the query, and TRCombobox when the committed value must come from a list.

Install

Add the package, then import its public library.

flutter pub add tinyrack_ui
import 'package:tinyrack_ui/tinyrack_ui.dart';

Playground

Usage

import 'package:material_ui/material_ui.dart';
import 'package:tinyrack_ui/tinyrack_ui.dart';

TRInlineSuggestions<String>(
  open: trigger != null,
  sessionKey: trigger?.start,
  controller: suggestions,
  items: matches,
  onSelected: (item) => complete(item.value),
  child: Focus(
    onKeyEvent: (node, event) => suggestions.handleKeyEvent(event),
    child: TRTextField(controller: text, maxLines: 8, minLines: 1),
  ),
)

API

TRInlineSuggestions properties

PropType / defaultPurpose
childWidgetThe field the caller owns, used verbatim as the trigger and as the position and width anchor.
itemsList<TRInlineSuggestionItem<T>>Rows to offer, already filtered and ordered by the caller.
openboolWhether a token is being completed. Fully controlled, because the condition depends on caret state this component cannot observe.
sessionKeyObject? · nullIdentity of the token being completed; changing it resets the highlight and clears a dismissal.
onSelectedValueChanged<TRInlineSuggestionItem<T>>Reports the committed row. The caller performs the text edit with its own offsets.
statusTRInlineSuggestionsStatus · readyWhether the list is settled, still loading, or failed.
placementTRLayerPlacement · topStartWhere the list sits relative to the field; it flips when space runs out.
layerSizeTRLayerSize · match anchor / content height ≤ measureXlSizes the complete suggestion layer. The row-count limit may make the scrolling list shorter than a larger fixed or minimum layer height.
maxVisibleItemsint · 8Rows shown before the list scrolls, counted rather than measured so the height follows the reader text size.
autoHighlightbool · trueArms the first row so Enter commits without pressing an arrow key first.
acceptOnEnter · acceptOnTabbool · trueWhether Enter and Tab commit the highlighted row. Both are separate so a host can leave Enter to sending.
emptyLabel · loadingLabel · errorLabelStringCopy for the three non-collapsing notice rows, supplied by the caller because the package carries no localization delegate.

TRInlineSuggestionItem properties

PropType / defaultPurpose
value · labelT · StringThe payload handed back on selection and the primary row text.
description · hint · tagString? · nullA muted second line, a trailing affordance such as expected arguments, and a short category chip.
matchedIndicesList<int> · const []Characters of label to emphasise. The caller owns the matcher; the design system owns the emphasis.
enabledbool · trueA disabled row stays visible, renders muted, and is skipped by keyboard navigation and commit.

TRInlineSuggestionsController members

PropType / defaultPurpose
handleKeyEventKeyEventResult Function(KeyEvent)Call this first inside the host field Focus(onKeyEvent:); ignored means the host still owns the key.
isOpen · highlightIndex · highlightedItembool · int · TRInlineSuggestionItem<T>?Reads the live list state; highlightIndex is -1 when nothing is armed.
highlightNext · highlightPrevious · highlightFirst · highlightLastvoid Function()Moves the highlight, wrapping at each end and skipping disabled rows.
commitHighlighted · dismissbool Function() · void Function()Commits the highlighted row, reporting whether anything was committed, or hides the list until the next session.