一個 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.