Flutter Tags Search View Example: Build a Chip-Based Search
A tags search view lets users type keywords, see them as chips, and filter a list instantly. It's common in note apps, e-commerce filters, and admin dashboards. In Flutter you can build one without third-party packages using TextField, Wrap, InputChip, and a filtered ListView.
This article walks through a complete, working example: a tag input field that adds chips on submit, removes them with a tap, and filters a list of items in real time. We'll cover debounce, keyboard actions, empty states, and the performance ranges you should expect on mid-range Android devices.
Why Build a Tags Search View Instead of a Plain TextField
A plain TextField works for a single query string, but tags give users structure. Each tag is visible, removable, and can be combined: "flutter" AND "android" narrows results more precisely than a single fuzzy string. This matters when your dataset has 500–5,000 items and users need to slice it repeatedly.
Tags also improve clarity on mobile. Users see exactly which filters are active, so they don't wonder why a list looks short. In internal tools, tag chips reduce support questions because the active filter state is always on screen.
From an implementation view, tags are just a `Set<String>` in state. That keeps the model simple and testable: add, remove, and filter are pure functions. You can swap the data source later without touching the UI logic.
- Tags make multi-filter queries visible and removable
- A Set<String> keeps state simple and testable
- Chips work well with touch targets of 48dp or more
- Empty tag list means “show everything” by default
The Core Widgets: TextField, Wrap, InputChip, and ListView
The input area is a TextField with `textInputAction: TextInputAction.done` and an `onSubmitted` callback. When the user presses done, trim the text, ignore empties and duplicates, and add it to a `Set<String>` held in a StatefulWidget. Then clear the controller so the field is ready for the next tag.
Display tags with a Wrap widget containing InputChip children. Wrap handles line breaks automatically, so five or six tags fit on two lines on a 360dp-wide phone without overflow. Each InputChip gets an `onDeleted` callback that removes the tag from the set and calls setState.
The results list is a ListView.builder whose itemCount comes from the filtered list. Avoid rebuilding the entire list on every keystroke by filtering only when tags change, not while typing. If you also want free-text search, debounce that input by 250–300ms.
For long lists, a plain ListView.builder is fine up to a few thousand items. If you need mixed headers and grids, compare ListView, GridView and CustomScrollView before committing to a structure.
- Use onSubmitted to add tags from the keyboard
- Wrap + InputChip gives free wrapping and delete icons
- Filter on tag changes, not on every keystroke
- Debounce free-text input by 250–300ms
Step-by-Step: Building the Tags Search View
Start with a StatefulWidget. In state, declare `final Set<String> _tags = {};`, a `TextEditingController`, and your source list, for example 200 sample items with `title` and `category` fields. In `dispose`, call `_controller.dispose()` to avoid leaks.
In `build`, use a Column with a TextField, a Wrap of chips, and an Expanded ListView. The TextField's `onSubmitted` calls `_addTag`. The InputChip's `onDeleted` calls `_removeTag`. The ListView's items come from a getter `_filtered` that returns all items when `_tags` is empty, otherwise items whose fields contain every tag (case-insensitive).
Filtering 500 items with 3 tags typically takes under 3ms on a mid-range Android phone, so you can filter synchronously in build without jank. If your dataset is 10,000+ items, precompute lowercase fields and consider filtering in an isolate.
Add an empty state: when `_filtered` is empty, show a short message and a button to clear tags. Also show a small count like “12 results” above the list so users understand the effect of each tag.
- Dispose the TextEditingController in dispose()
- Normalize case once when loading data
- Show result counts and an empty state
- Clear tags with a single button when needed
| Approach | Typical dataset | Filter time (mid-range) | Complexity |
|---|---|---|---|
| Single TextField, no debounce | Under 500 items | 1–3ms per keystroke | Low |
| Single TextField with 250ms debounce | 500–5,000 items | 1–4ms after pause | Low |
| Tag chips + synchronous filter | 500–5,000 items | 1–4ms per tag change | Medium |
| Tag chips + isolate filter | 10,000+ items | 5–15ms off main thread | High |
| Database query with indexes | 50,000+ items | Depends on query and disk | High |
State Management and Edge Cases That Bite
Keep tag state local to the screen unless other screens need it. Lifting it too early adds complexity. If you do share it, a simple ChangeNotifier or ValueNotifier<Set<String>> is enough; avoid rebuilding the whole app on each tag change.
Handle duplicates: ignore a tag that already exists, or move it to the front as the most recent. Trim whitespace and decide on case sensitivity up front—most apps treat “Flutter” and “flutter” as the same tag. Reject tags longer than 24–32 characters to keep chips readable.
Rotation and keyboard changes can rebuild the widget. If you store tags in a StatefulWidget, state survives rebuilds, but not process death. For persistence, save tags to a local store or pass them through a state restoration mechanism. The same discipline applies to handling configuration changes without losing state on the Android side.
Finally, test with the keyboard open on a small screen. The input field should stay visible; wrap the Column in a SafeArea and let the ListView shrink.
- Ignore duplicates or move them to the front
- Normalize case and trim whitespace
- Limit tag length to 24–32 characters
- Test with the keyboard open on a 360dp screen
Performance Ranges and When to Optimize
For typical tag search screens, the bottleneck is list building, not filtering. On a mid-range Android device, filtering 1,000 items with 3 tags usually takes 1–4ms; building 1,000 list rows is the slower part. Keep row widgets small and avoid heavy work in `itemBuilder`.
If you notice dropped frames while typing, debounce the input and avoid calling setState on every character. A 250ms debounce reduces rebuilds by roughly 4–8x during fast typing and keeps the UI at 60fps on most devices.
When your dataset grows beyond 10,000 items, move filtering off the main isolate or use a database query with indexed columns. The UI pattern stays the same; only the data layer changes.
- Filtering 1,000 items: typically 1–4ms
- Debounce reduces rebuilds during typing
- Keep itemBuilder cheap and const where possible
- Move to isolates or DB queries beyond 10,000 items
Key points
- A Set<String> plus Wrap and InputChip is enough to build a solid tags search view.
- Filter on tag changes and debounce free-text input by 250–300ms.
- Synchronous filtering stays under 4ms for up to about 1,000 items on mid-range devices.
- Test keyboard visibility, duplicates, and case handling before shipping.
Flutter Screen Widget and Cost Estimator
Estimate the number of widgets in a screen and a rough development-hour figure from your component counts. Adjust the fields to see how each UI area affects the total effort.
Editor and Flutter contributor
Writes practical Flutter tutorials focused on widgets, layout and animation. Enjoys breaking large UI problems into small, testable pieces and explaining them clearly to beginners.