一个 Flutter 包,允许用户直接在文本字段中输入和管理标签。它提供了一个直观的界面,用于动态添加、编辑和删除标签,通过视觉反馈增强表单交互体验。适用于需要关键词或类别输入的应用程序,例如笔记、社交媒体或任务管理工具中的标签系统。该包支持 Android、iOS、Web、macOS、Windows 和 Linux 多个平台,确保在不同设备上行为一致。
适合场景
标记用户输入
带有动态关键词的表单字段
社交媒体帖子标签
任务或项目分类
搜索筛选器带标签建议
主要特点
内联标签创建
可自定义的标签样式
跨平台支持
与现有表单的轻松集成
实时标签管理
适合对象
开发交互式表单的开发者
需要关键词标记的应用
多平台应用程序
具有动态内容输入的 UI
使用建议
需要谨慎处理标签限制
可能需要自定义验证逻辑
大量标签下的性能
有限的内置自动完成功能
样式自定义可能需要额外的代码
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
textfield_tags
Textfield_tags is a widget that allows developers to create tags inside a textfield. The widget comes with 2 default controllers that allow you to store tags as regular strings or objects. Alternatively, you can create your own controller by extending the base controller class to have custom tag controllers.
Environment
sdk: ">=2.12.0 <4.0.0"
flutter: ">=1.17.0"
Installation
dependencies:textfield_tags:^3.0.1
$ flutter pub get
Getting Started
To get started using this widget, you will need to first import the package inside your project following the installation guide found on Flutter.dev.
Usage
To use this widget,
import 'package:textfield_tags/textfield_tags.dart'; inside your dart file
Follow one of the examples bellow and call the widget TextFieldTags(...).
Read the api documentation on these properties for more details or see the examples provided in the example folder.
Examples With Different Controllers
By default, the widget comes with 2 built-in controllers: one that allows you to manage string type tags and another one that allows you to use any type of tags including objects, ints, strings, etc. We will show examples of the two controllers in actions bellow.
Using String type tags (StringTagControlle)
If you only want to use string based tags, then the StringTagController is ideal for you. The example bellow shows how you can utilize the StringTagController<String>() controller to manage string tags.
If you want to store dynamic type of datas with each tags, then using DyanmicTagController will be ideal for you. This will offer you more flexibiliity and customization and will allow you to design the tags based on their own stored data.
More Advanced Functionality Via A Custom Controller
If you feel like you want more functionality than what is offered by the 2 default controllers, then you can easily extend TextfieldTagsController class to your own custom class and inherit all its functionalities and add your own stuffs as bellow example shows.
The bellow example shows you how you can use a numbers
tag picker that selects numbers between 2 and 10 with the exception of number 8.