Home

Awesome

flutter_tags

pub package Awesome Flutter Donate

Create beautiful tags quickly and easily.

Installing

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_tags: "^0.4.9+1"

DEMO

<div align="center"> <table> <tr> <td style="text-align:center"> <img width = "250px" src="https://github.com/Dn-a/flutter_tags/raw/master/repo-file/img/example0.4.0_1.gif" /> </td> <td style="text-align:center"> <img width = "250px" src="https://github.com/Dn-a/flutter_tags/raw/master/repo-file/img/example0.4.0_2.gif" /> </td> </tr> </table> </div>

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(str);
          });
        },
      ),
      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

PropNameDescriptiondefault value
columnsPossibility to set number of columns when necessarynull
itemCountTag number to displayrequired
symmetryAbility to view and scroll tags horizontallyfalse
horizontalScrollOffset drawer width0.4
heightHorizontalScrollheight for HorizontalScroll to set to display tags correctly60
spacingHorizontal space between the tags6
runSpacingVertical space between the tags14
alignmentHorizontal WrapAlignmentWrapAlignment.center
runAlignmentVertical WrapAlignmentWrapAlignment.center
directionDirection of the ItemTagsAxis.horizontal
verticalDirectionIterate Item from the lower to the upper direction or vice versaVerticalDirection.down
textDirectionText direction of the ItemTagsTextDirection.ltr
itemBuildertag generator
textFieldadd textFieldTagsTextFiled()

ItemTags() parameters

Donate

It takes time to carry on this project. If you found it useful or learned something from the source code please consider the idea of donating 5, 20, 50 € or whatever you can to support the project.

Issues

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