搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。