Allows tags to be entered inside textfield

Overview

textfield_tags

This is a widget that allows your users to create tags by entering the tag's name inside of textfield and make the tags appear in the textfield. After entering the tag, the user can press the spacebar or enter button to save the tag and move on to enter another tag.

Environment

sdk: ">=2.12.0 <3.0.0"

flutter: ">=1.17.0"

Installation

  dependencies:
      textfield_tags: ^1.4.2

$ flutter pub get

Getting Started

To start 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,

  1. import 'package:textfield_tags/textfield_tags.dart'; inside your dart file
  2. Call the widget TextFieldTags().
  3. The widget takes in 5 arguments: TagsStyler, TextFieldStyler, onTag, onDelete, and initialTags. Note that TagsStyler, TextFieldStyler, onTag, onDelete should not be null. You can investigate the properties of TagsStyler and TextFieldStyler for more customizations if you choose to do so.

When you want to use it, call the TextFieldTags() as bellow examples show

   TextFieldTags(
     textSeparators: <String> [
       //text tag seperators
       //Default = " ", ","
     ],
      tags: <String>[
         // List of tags
         // Provide a list of initial tags to initialize it
      ],
      textFieldStyler: TextFieldStyler(
          //These are properties you can tweek for customization

          // bool textFieldFilled = false,
          // Icon icon,
          // String helperText = 'Enter tags',
          // TextStyle helperStyle,
          // String hintText = 'Got tags?',
          // TextStyle hintStyle,
          // EdgeInsets contentPadding,
          // Color textFieldFilledColor,
          // bool isDense = true,
          // bool textFieldEnabled = true,
          // OutlineInputBorder textFieldBorder = const OutlineInputBorder(),
          // OutlineInputBorder textFieldFocusedBorder,
          // OutlineInputBorder textFieldDisabledBorder,
          // OutlineInputBorder textFieldEnabledBorder
          ),
      tagsStyler: TagsStyler(
          //These are properties you can tweek for customization
          
          // showHashtag = false,
          // EdgeInsets tagPadding = const EdgeInsets.all(4.0),
          // EdgeInsets tagMargin = const EdgeInsets.symmetric(horizontal: 4.0),
          // BoxDecoration tagDecoration = const BoxDecoration(color: Color.fromARGB(255, 74, 137, 92)),
          // TextStyle tagTextStyle,
          // Icon tagCancelIcon = const Icon(Icons.cancel, size: 18.0, color: Colors.green)
          ),
      onTag: (tag) {
        //This give you the tag that was entered
        //print(tag)
      },

      onDelete: (tag){
        //This gives you the tag that was deleted
        //print(tag)
      },
      validator: (tag){
        if(tag.length>15){
          return "hey that's too long";
        }
        return null;
      }
      //tagsDistanceFromBorderEnd: 0.725,
      //scrollableTagsMargin: EdgeInsets.only(left: 9),
      //scrollableTagsPadding: EdgeInsets.only(left: 9),
    )

Example giffs

Examples pics

  TextFieldTags(
      tagsStyler: TagsStyler(
        tagTextStyle: TextStyle(fontWeight: FontWeight.normal),
        tagDecoration: BoxDecoration(color: Colors.blue[300], borderRadius: BorderRadius.circular(0.0), ),
        tagCancelIcon: Icon(Icons.cancel, size: 18.0, color: Colors.blue[900]),
        tagPadding: const EdgeInsets.all(6.0)
      ),
      textFieldStyler: TextFieldStyler(),
      onTag: (tag) {},
      onDelete: (tag) {},
      validator: (tag){
        if(tag.length>15){
          return "hey that's too long";
        }
        return null;
      } 
   )

  //The Colors for this are used from https://flutter-color-picker.herokuapp.com/
  TextFieldTags(
      tagsStyler: TagsStyler(
        tagTextStyle: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), 
        tagDecoration: BoxDecoration(color: const Color.fromARGB(255,171,81,81), borderRadius: BorderRadius.circular(8.0), ),
        tagCancelIcon: Icon(Icons.cancel, size: 16.0, color: Color.fromARGB(255,235,214,214)),
        tagPadding: const EdgeInsets.all(10.0),
      ),
      textFieldStyler: TextFieldStyler(),
      onTag: (tag) {},
      onDelete: (tag) {},
      validator: (tag){
        if(tag.length>15){
          return "hey that's too long";
        }
        return null;
      }
   )

TextFieldTags(
  initialTags: ["college"],
  tagsStyler: TagsStyler(
    showHashtag: true,
    tagMargin: const EdgeInsets.only(right: 4.0),
    tagCancelIcon: Icon(Icons.cancel, size: 15.0, color: Colors.black),
    tagCancelIconPadding: EdgeInsets.only(left: 4.0, top: 2.0),
    tagPadding:
        EdgeInsets.only(top: 2.0, bottom: 4.0, left: 8.0, right: 4.0),
    tagDecoration: BoxDecoration(
      color: Colors.white,
      border: Border.all(
        color: Colors.grey.shade300,
      ),
      borderRadius: const BorderRadius.all(
        Radius.circular(20.0),
      ),
    ),
    tagTextStyle:
        TextStyle(fontWeight: FontWeight.normal, color: Colors.black),
  ),
  textFieldStyler: TextFieldStyler(
    hintText: "Tags",
    isDense: false,
    textFieldFocusedBorder: UnderlineInputBorder(
      borderSide: BorderSide(color: Colors.black, width: 3.0),
    ),
    textFieldBorder: UnderlineInputBorder(
      borderSide: BorderSide(color: Colors.black, width: 3.0),
    ),
  ),
  onDelete: (tag) {
    print('onDelete: $tag');
  },
  onTag: (tag) {
    print('onTag: $tag');
  },
  validator: (String tag) {
    print('validator: $tag');
    if (tag.length > 10) {
      return "hey that is too much";
    }
    return null;
  },
)

Comments
  • textSeparators issue

    textSeparators issue

    LateInitializationError: Field '_textSeparators@1298091221' has already been initialized.

    I tried in many ways but still I could not solve it can you please help me regarding it.

    bug 
    opened by BalaVenkatasainath 21
  • Error thrown RangeError (index): Invalid value: Only valid value is 0: -1

    Error thrown RangeError (index): Invalid value: Only valid value is 0: -1

    https://github.com/eyoeldefare/textfield_tags/blob/bc1385f06e80e89b1ad67c8de63c606f6f726d0d/lib/src/main.dart#L183

    This should be "-1" not "-2"

    opened by Gunnar-Stunnar 7
  • feat: adds a feature to provide a list of already added tags

    feat: adds a feature to provide a list of already added tags

    Merging this PR will close #6 and will add a feature where the user can set an initial list of tags, which might have been added previously.

    This is personally tested by me. And apart from implementing this feature, I've also updated the README.md accordingly and have modified the code a little bit (have made the if statements shorter). Also, I didn't notice while committing that Android studio has formatted the code, LMK if you want that like before. LMK, if any further change is required from my end. :slightly_smiling_face:

    opened by iamdipanshusingh 7
  • TextInput is not recorded

    TextInput is not recorded

    Issue: I can type words in the input form, yet after pressing space or enter, the words dissapear and no tag is renderd. Also, tags are not showing up at print in console.

    Expected:

    • tags to show up after space
    • onTag to show a print in console when a tags is added

    Debug console:

    W/IInputConnectionWrapper( 5213): getSelectedText on inactive InputConnection
    W/IInputConnectionWrapper( 5213): getTextAfterCursor on inactive InputConnection
    W/IInputConnectionWrapper( 5213): beginBatchEdit on inactive InputConnection
    W/IInputConnectionWrapper( 5213): endBatchEdit on inactive InputConnection
    

    My code:

    class _PostFormState extends State<PostForm> {
    
      TextEditingController title = TextEditingController();
      List<String> tags;
    
      final _formKey = GlobalKey<FormState>();
    
      @override
      Widget build(BuildContext context) {
        return Form(
                    key: _formKey,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        TextFormField(
                              controller: title,
                              decoration: InputDecoration(hintText: 'Title'),
                              maxLength: 140,
                              validator: (value) {
                                if (value.isEmpty) {
                                  return 'Please enter a title';
                                } else {
                                  return null;
                                }
                              }),
                        SizedBox(height: 16,),
                        TextFieldTags(
                          onTag: (tag) {
                            tags.add(tag);
                            print(tags);
                          },
                          // onDelete: (tag) {
                          //   tags.remove(tag);
                          // },
                        ),
                        RaisedButton.icon(
                            onPressed: () {
                               // Validate returns true if the form is valid, otherwise false.
                                if (_formKey.currentState.validate()) {
                                  // Provide userfeedback while processing
                                  Scaffold
                                      .of(context)
                                      .showSnackBar(SnackBar(content: Text('Processing Data')));
    
                                  // Post to firebase
                                  Future result = widget.db.post(widget.audio, title, tags);
    
                                    result.then((user) => Navigator.of(context)
                                        .pushReplacementNamed(homeRoute, arguments: 2)).catchError((e) => throw 'error in posting' + e);
                                  }
                                },                         
                            label: Text('Post'),
                            icon: Icon(Icons.post_add),
                          ),
                      ],
                    ),
                  );
      }
    }
    

    My environment:

    [√] Flutter (Channel beta, 1.22.0-12.1.pre, on Microsoft Windows [Version 10.0.18363.1139])
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    [√] Android Studio (version 4.0)
    [√] VS Code (version 1.50.1)
    [√] Connected device (1 available)
    

    I ran in an emulator in debug mode

    opened by Mateis 7
  • Max Tags property

    Max Tags property

    Hi, I can't find a property for max tags. Is there a way to expose a new tags limit? Or a better way to get the Tags List length so we can limit adding extra tags?

    opened by diogosequeira94 5
  • null safety error

    null safety error

    need to replace "!" to "?" character, It doesn't work because there is no question mark because there is a definition that can be null.

    lib>src>controller.dart line 87 #60 #58

    opened by tekangun 4
  • Textfield Tags do not scroll when full on Flutter Web

    Textfield Tags do not scroll when full on Flutter Web

    If a Textfield Tag box is in Flutter Web, and is completely filled up with tags, it will not automatically scroll over to add more tags. Instead, it prevents you from typing with no ability to move over. How can this issue be resolved because currently, once it is full, the textfield becomes unusable. Hence, the demonstration in the images on Pub.dev with it sliding over does not occur.

    waiting for response Enod 
    opened by jmsquillaro 4
  • clear / reset fields

    clear / reset fields

    I have this TextFieldTags used inside a form. After the form is submitted, it is supposed to reset or clear the tags after successful submit. I dont see how to achieve this, or is there any way to do this?

    opened by Trend74X 4
  • One tag I enter will be entered twice as hashtag

    One tag I enter will be entered twice as hashtag

    Hello, I have reproduced a bug related to #17 which has already been closed!

    I'm using the latest version and the codes are below.

    Flexible(
      child: TextFieldTags(
        initialTags: this._task.tags, // It happens when I set this option.
        onTag: (String tag) {
          this._tags.add(tag);
        },
        onDelete: (String tag) {
          this._tags.remove(tag);
        },
      ),
    ),
    

    And these photos are what happened.

    スクリーンショット 2021-07-31 22 17 26 スクリーンショット 2021-07-31 22 17 35 bug enhancement good first issue 
    opened by myConsciousness 4
  • Implementing backspace deletion

    Implementing backspace deletion

    This time, I implemented backspace deletion. It's the desired feature that tags gets deleted when you press backspace button. but flutter doesn`t have the function to detect the soft backspace button. So I did the trick like the space add function. Execute when the param value of onChanged function enters once space. Since this part can conflict with the space add-in, the form's starting value is always two spaces. When the TextField focuses, it is always fixed with two spaces to avoid errors in the user's space position via focusNode. The problem here occurs when the user forcibly moves the cursor of the textfield. However, I thought that people would seldom deliberately change the position of the cursor. Below is a demo video.

    test

    I'm sorry for my poor English. Please let me know if there is any problem with the code.

    opened by chb1828 4
  • warning after flutter 3.0

    warning after flutter 3.0

    /C:/Users/Bala/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/textfield_tags-2.0.0+1/lib/src/controller.dart:86:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.

    • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/Users/Bala/flutter/packages/flutter/lib/src/widgets/binding.dart'). package:flutter/…/widgets/binding.dart:1 WidgetsBinding.instance!.addPostFrameCallback((_) {

    after switched to flutter 3.0 and textfield_tags 2.0.0+1 getting this warning.

    opened by SainathChallagundla 3
  • Add custom data type support

    Add custom data type support

    Getting 'Instance of 'MasterData' when I use AutComplete<MasterData>. see code below Screenshot 2022-08-19 at 11 49 23 AM

     optionsBuilder: (TextEditingValue textEditingValue) {
                                    if (textEditingValue.text == '') {
                                      return const Iterable<MasterData>.empty();
                                    }
                                    return addNewProjectsProvider.serviceList.where((MasterData option) {
                                      return option.typeName!.contains(textEditingValue.text.toLowerCase());
                                    });
                                  },
    

    After selecting any item, it shows name properly. Screenshot 2022-08-19 at 11 51 40 AM

    So, is there any way to change 'Instance of 'MasterData' to actual type(MasterData.typeName) ?

    opened by ashishpipaliya 1
  • Prevent paste long text (include free spaces)

    Prevent paste long text (include free spaces)

    You can paste a long text with many free spaces without any problem! and Input doesn't detect any worlds as tags! How to prevent that? Of course, it happens for some texts like this one:

    if(resolution.categories!.any((e) => e.toLowerCase() == tag)) {

    Enod 
    opened by parsadoc 1
  • How to use multiple lines in a textfield instead of one scrolling line?

    How to use multiple lines in a textfield instead of one scrolling line?

    I want to make the text break and add the tag to a new line instead of adding them to a horizontally scrolling line when the end of the textfield is reached. How can I do that?

    opened by Wizzel1 1
  • Breaking changes comming up after V2.0.0+ release (BE AWARE BEFORE UPDATING)

    Breaking changes comming up after V2.0.0+ release (BE AWARE BEFORE UPDATING)

    Please note that the next release will be v2.0.0 and it will be breaking change. So if you update your package to v2+, it will break your code. The reason i am updating this package is to make it more robust and customizable and also to make it upto date with new features in flutter.

    Some of the things that will be implemented are:

    1. Custom autocomplete support by user as per issue #46 request
    2. Build your own custom widget instead of using our implementation
    3. More functionality using custom controller
    Enod 
    opened by eyoeldefare 2
Allows communication between your bot and the Web App built in Flutter displayed inside Telegram.

tele_web_app It enables communication between your bot and the Flutter-embedded Web App displayed inside Telegram by making use of interoperability be

Yeikel Uriarte Arteaga 16 Dec 8, 2022
A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)

flutter_html A Flutter widget for rendering HTML and CSS as Flutter widgets. Screenshot 1 Screenshot 2 Screenshot 3 Table of Contents: Installing Curr

Matthew Whitaker 1.5k Jan 5, 2023
Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.

HtmlWidget monorepo This repo contains the source code for everything HtmlWidget-related. Name Link flutter_widget_from_html_core flutter_widget_from_

Đào Hoàng Sơn 445 Jan 6, 2023
Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.

nfc_in_flutter NFC in Flutter is a plugin for reading and writing NFC tags in Flutter. It works on both Android and iOS with a simple stream interface

Andi Semler 113 Sep 28, 2022
A simple tag editor for inputing tags in Flutter.

Super Tag Editor A simple tag editor for inputting tags with suggestion box Supported suggestion box Screen Shot 1 Screen Shot 2 ) Usage Add the packa

dab 4 Dec 6, 2022
Working proof of the Go (golang) server running inside Flutter

flap Working proof of the Go server running inside Flutter Video in action Prerequisites Flutter >2.0 Go >1.16 Build Go server cd go macOS: make maco

Err 28 Dec 17, 2022
A flutter plugin to draw the coordinates on the widget and as well as to find the given point is inside a list of coordinates or not.

Draw On A flutter plugin to draw the coordinates on widget and as well as to find the given point is inside a list of coordinates or not. For Draw on

Sivaramsiva10 4 Apr 5, 2022
A Flutter package that provides a dropdown form field using a dropdown button inside a form field.

Dropdown form field A dropdown form field using a dropdown button inside a form field. Demo Features Can be used as regular form field. Simple to impl

Carlos Eugenio Torres 72 Jan 1, 2023
Iridium-reader-widget - Plug and play reader widget allowing to easily integrate an Iridium viewer inside any app

Plug and play reader widget allowing to easily integrate an Iridium viewer insid

Mantano 15 Dec 31, 2022
A Learning Management System Solutions Developed from Scratch inside Orange Digital Center Labs By ODC-Flutter WorkForce.

A Learning Management System Solutions Developed from Scratch inside Orange Digital Center Labs By ODC-Flutter WorkForce.

Orange Digital Center Egypt - Coding School 5 May 9, 2022
Makes it possible to safely execute and retry a Future inside a StatelessWidget

futuristic Makes it possible to safely execute and retry a Future inside a StatelessWidget. See the Mainstream package for a similar API for working w

Martin Rybak 28 Sep 15, 2022
A dart library to check if given point(s) are present inside polygon or not.

poly A library for checking if given point(s) is present inside Polygon or not. Contents Installation Examples Note: Instead of casting, use toListNum

Sacchi 9 Feb 25, 2022
A TextField flutter package with tagging functionality.

Flutter Tagging A flutter package with tagging or multi-select functionality. Useful for adding Tag or Label Selection Forms. List<Language> _selected

Sarbagya Dhaubanjar 149 Sep 6, 2022
A focusable and blurable TextField widget

Flutter Focus Widget 一个可以让FocusNode失去焦点的Widget A focusable and blurable widget of based on the FocusNode. 新增的参数: bool showFocusArea 使用一个半透明的红色方框显示焦点区域

yeoman 9 Jul 17, 2022
Text and TextField highlighted with rounded corners

rounded_background_text Highlight text with rounded corners Features ✅ Highlight

Bruno D'Luka 39 Nov 6, 2022
Flutter-pinbox - UI for enter a PIN on flutter/dart, one digit per textField box.

flutter-pinbox This is a library for enter a PIN on flutter/dart. You can enter one digit per textField box. The detail The library locate at path lib

null 2 Feb 26, 2022
A Flutter widget to show an icon collection to pick. This widget extend TextField and has a similar behavior as TextFormField

icon_picker A Flutter widget to show an icon collection to pick. This widget extend TextField and has a similar behavior as TextFormField Usage In the

m3uzz Soluções em TI 11 Sep 27, 2022
Sample Flutter Drawing App which allows the user to draw onto the canvas along with color picker and brush thickness slider.

DrawApp Sample Flutter Drawing App which allows the user to draw onto the canvas along with color picker and brush thickness slider. All code free to

Jake Gough 226 Nov 3, 2022
Flutter Multi-platform allows developers to unleash their app to run on the wide variety of different platforms with little or no change.

Flutter Multi-platform sample Flutter Multi-platform allows developers to unleash their app to run on the wide variety of different platforms with lit

MindInventory 22 Dec 31, 2022