搜索插件、代码仓与 APP 分类

插件详情v1.1.0

flutter_tags_x

创建可选择和可输入的标签(TextField)从未如此简单。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2010
喜欢数
30
Pub 分数
140

安装插件

flutter pub add flutter_tags_x

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_tags_x 是一个 Flutter 包,可简化可选择和基于输入的标签创建,同时支持预定义标签和用户输入的标签。它提供直观的界面,内置对文本字段、选择状态和动态标签管理的支持。适用于表单、筛选器或标签系统,通过跨多个平台的干净、可自定义的芯片组件增强用户体验。

适合场景

  • 带有标签建议的表单输入
  • 用户生成内容标记
  • 具有可选芯片的过滤接口
  • 基于标签的搜索功能
  • 表单中的动态标签管理
  • 可选择项的交互式列表

主要特点

  • 支持预定义标签和输入标签
  • 用于添加新标签的内置文本字段
  • 可选择且可移除的标签芯片
  • 可自定义的样式和主题
  • 跨平台兼容性
  • 与现有表单逻辑的轻松集成

适合对象

  • 开发交互式表单的开发者
  • 需要基于标签过滤的应用
  • 包含用户生成内容的项目
  • 希望拥有简洁标签界面的设计师
  • 面向多个平台的团队

使用建议

  • 需要仔细处理标签重复问题
  • 可能需要为输入约束自定义验证
  • 样式自定义需要理解 Flutter 小部件
  • 使用大型标签列表时,性能可能需要优化
  • 有限的内置验证,仅限基本输入检查

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_tags_x

Create beautiful tags quickly and easily.

Forked from Dn-a/flutter_tags (Not supported)

Installing

Add this to your package's pubspec.yaml file: Null-safety version MORE INFO

dependencies:
  flutter_tags_x: ... # last version

DEMO

Simple usage


import 'package:flutter_tags/flutter_tags.dart';
.
.
.
List _items;
double _fontSize = 14;

@override
void initState(){
    super.initState();
    // if you store data on a local database (sqflite), then you could do something like this
    Model().getItems().then((items){
            _items = items;
        });
}

@override
Widget build(BuildContext context) {
    return Tags(
      key:_tagStateKey,
      textField: TagsTextField(
        textStyle: TextStyle(fontSize: _fontSize),
        constraintSuggestion: true, suggestions: [],
        //width: double.infinity, padding: EdgeInsets.symmetric(horizontal: 10),
        onSubmitted: (String str) {
          // Add item to the data source.
          setState(() {             
             // required             
            _items.add(Item(
                title: str,
                active: true,
                index: 1,                
              ));
          });
        },
      ),
      itemCount: _items.length, // required
      itemBuilder: (int index){          
            final item = _items[index];
    
            return ItemTags(
                  // Each ItemTags must contain a Key. Keys allow Flutter to
                  // uniquely identify widgets.
                  key: Key(index.toString()),
                  index: index, // required
                  title: item.title,
                  active: item.active,
                  customData: item.customData,
                  textStyle: TextStyle( fontSize: _fontSize, ),
                  combine: ItemTagsCombine.withTextBefore,
                  image: ItemTagsImage(
                    image: AssetImage("img.jpg") // OR NetworkImage("https://...image.png")
                  ), // OR null,
                  icon: ItemTagsIcon(
                    icon: Icons.add,
                  ), // OR null,
                  removeButton: ItemTagsRemoveButton(
                    onRemoved: (){
                        // Remove the item from the data source.
                        setState(() {
                            // required
                            _items.removeAt(index);
                        });
                        //required
                        return true;
                    },
                  ), // OR null,
                  onPressed: (item) => print(item),
                  onLongPressed: (item) => print(item),
            );
    
      },
    );    
}

final GlobalKey<TagsState> _tagStateKey = GlobalKey<TagsState>();
// Allows you to get a list of all the ItemTags
_getAllItem(){
    List<Item> lst = _tagStateKey.currentState?.getAllItem;
    if(lst!=null)
        lst.where((a) => a.active==true).forEach( ( a) => print(a.title));        
}

Wrapped widget example

You are free to wrap ItemTags () inside another widget

Tags(  
      itemCount: items.length, 
      itemBuilder: (int index){ 
          return Tooltip(
          message: item.title,
          child:ItemTags(
            title:item.title,
          )
          );
      },
    );    
Tags() parameters
PropName Description default value
columns Possibility to set number of columns when necessary null
itemCount Tag number to display required
symmetry Ability to view and scroll tags horizontally false
horizontalScroll Offset drawer width 0.4
heightHorizontalScroll height for HorizontalScroll to set to display tags correctly 60
spacing Horizontal space between the tags 6
runSpacing Vertical space between the tags 14
alignment Horizontal WrapAlignment WrapAlignment.center
runAlignment Vertical WrapAlignment WrapAlignment.center
direction Direction of the ItemTags Axis.horizontal
verticalDirection Iterate Item from the lower to the upper direction or vice versa VerticalDirection.down
textDirection Text direction of the ItemTags TextDirection.ltr
itemBuilder tag generator
textField add textField TagsTextFiled()
ItemTags() parameters
  • index - required
  • title - required
  • textScaleFactor - custom textScaleFactor
  • active - bool value (default true)
  • pressEnabled - active onPress tag ( default true)
  • customData - Possibility to add any custom value in customData field, you can retrieve this later. A good example: store an id from Firestore document.
  • textStyle - textStyle()
  • alignment - MainAxisAlignment ( default MainAxisAlignment.center)
  • combine - * ability to combine text, icons, images in different ways ( default ItemTagsCombine.imageOrIconOrText)*
  • icon - ItemTagsIcon()
  • image - ItemTagsImage()
  • removeButton - ItemTagsRemoveButton()
  • borderRadius - BorderRadius
  • border - custom border-side
  • padding - default EdgeInsets.symmetric(horizontal: 7, vertical: 5)
  • elevation - default 5
  • singleItem - default false
  • textOverflow - default TextOverflow.fade
  • textColor - default Colors.black
  • textActiveColor - default Colors.white
  • color - default Colors.white
  • activeColor - default Colors.blueGrey
  • highlightColor -
  • splashColor -
  • colorShowDuplicate - default Colors.red
  • onPressed - callback
  • onLongPressed - callback
  • onRemoved - callback

Issues

If you encounter problems, open an issue. Pull request are also welcome.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。