Code Monkey home page Code Monkey logo

textfield_tags's Introduction

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.0

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

textfield_tags's People

Contributors

chb1828 avatar eyoeldefare avatar iamdipanshusingh avatar ikp-773 avatar martibis avatar myconsciousness avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.