tag_field 1.0.9
tag_field: ^1.0.9 copied to clipboard
A customizable Flutter widget for adding and managing tags.
tag_field #
💡 Flutter Tag Field Widget #
tag_field is a premium, feature-rich, and highly customizable Flutter package for building interactive tag/chip input fields. It provides smooth animations, custom layouts, input validation, auto-separators, and full form integration out of the box.
Whether you are building a social networking app with @mentions, a blogging platform with categorization tags, or a contact selection widget, tag_field has you covered.
✨ Features #
|
🎯
Interactive TagsAdd, edit, and delete tags with smooth animations and intuitive keyboard gestures. |
📝
Form ValidationStandard |
📐
Multiple LayoutsWrap, single-line inline scrolling, and stacked column layouts to fit any responsive design. |
|
🎨
Full CustomizationCustomize colors, gradients, borders, shadows, icons, and text styles to match your design system. |
✅
Smart ValidationEnforce tag limit boundaries, validate tag formats, and prevent duplicate tag entries. |
🛠️
Custom BuildersProvide a |
|
📌
Flexible Suggestion PositioningSupports positioning tags |
||
🎬 Demo #
Check out how the animations and layouts adapt elegantly in real-time! ✨
🚀 Quick Start #
Installation #
Add tag_field to your project's pubspec.yaml file:
dependencies:
tag_field: ^1.0.7
Import it in your Dart file:
import 'package:tag_field/tag_field.dart';
💻 Code Examples #
1. Basic TagField Usage #
A simple tagging interface with custom separators and duplicate detection:
TagField(
initialTags: const ['Flutter', 'Dart'],
hintText: 'Add programming languages...',
maxTags: 8,
allowDuplicates: false,
separators: const [' ', ',', '\n'],
onTagsChanged: (tags) {
print('Current tags: $tags');
},
)
2. Form Validation (TagFormField) #
Integrate tag inputs inside your forms seamlessly. Supports validators, resetting, and custom error decorations:
Form(
key: _formKey,
child: Column(
children: [
TagFormField(
initialValue: const ['Flutter'],
hintText: 'Add at least 2 tags...',
validator: (tags) {
if (tags == null || tags.length < 2) {
return 'Please add at least 2 tags to continue';
}
return null;
},
onSaved: (tags) {
_myModel.tags = tags ?? [];
},
),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
}
},
child: const Text('Submit'),
),
],
),
)
3. Suggestions Overlay (Auto-Complete) #
Provide a list of suggestions that automatically filter as the user types:
TagField(
suggestions: const ['apple', 'banana', 'apricot', 'cherry'],
hintText: 'Type to search fruits...',
onTagsChanged: (tags) {
print('Selected tags: $tags');
},
)
4. Input Formatting & Character Limits #
Apply custom input formatting constraints (e.g. alphanumeric only) and limit the length of individual tags:
TagField(
maxTagLength: 10,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9]')), // Alphanumeric only
],
hintText: 'Max 10 chars, letters/numbers only...',
)
⚙️ Configuration Properties #
The TagField and TagFormField widgets accept the following configuration parameters:
| Property | Type | Default | Description |
|---|---|---|---|
initialTags/initialValue |
List<String> |
const [] |
Initial tags list to seed the input field. |
maxTags |
int? |
null |
Maximum allowed tags limit boundary. |
allowDuplicates |
bool |
false |
When false, shows snack bar error when duplicate tags are entered. |
hintText |
String |
'Add tags...' |
Placeholder text inside text field when empty. |
layout |
TagInputLayout |
TagInputLayout.wrap |
Layout strategy (wrap, inline, column, insideBelow, outsideAbove, outsideBelow). |
separators |
List<String> |
const [' ', ',', '\n'] |
Characters that trigger tag addition when typed. |
submitOnEnter |
bool |
true |
Convert input to tag when pressing Enter. |
clearInputOnSubmit |
bool |
true |
Instantly clear the text field upon tag addition. |
trimTags |
bool |
true |
Trim whitespace characters before tag creation. |
caseSensitive |
bool |
false |
Enforce case-sensitive comparison on tag deduplication. |
enableAnimations |
bool |
true |
Toggle animation transitions. |
tagBuilder |
Widget Function(...) |
null |
Custom builder to supply custom UI layout widgets for tags. |
tagBackgroundColor |
Color |
Color(0xFFE3F2FD) |
Background color of individual tags. |
tagTextColor |
Color |
Color(0xFF1976D2) |
Font color of individual tag texts. |
tagBorderColor |
Color |
Color(0xFF90CAF9) |
Border outline color of individual tags. |
containerBorderColor |
Color |
Color(0xFFE0E0E0) |
Outer border color of the input container. |
suggestions |
List<String>? |
null |
Predefined list of suggestions for the auto-complete overlay dropdown. |
suggestionBuilder |
Widget Function(...) |
null |
Custom builder to render suggestion overlay items. |
suggestionMaxHeight |
double |
200.0 |
Maximum height of the suggestion overlay panel. |
suggestionBackgroundColor |
Color? |
null |
Background color of the suggestions dropdown container. |
inputFormatters |
List<TextInputFormatter>? |
null |
Input formatting rules for character constraints. |
maxTagLength |
int? |
null |
Character length boundary for any single tag. |
👥 Meet The Creators #
🤝 Let's Build Something Amazing Together!
Passionate Flutter developers creating the future, one widget at a time
💬 Got questions? Ideas? Just want to say hi? We'd love to hear from you!