<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Syed Mohd Adnan</title>
    <description>The latest articles on DEV Community by Syed Mohd Adnan (@imadnan).</description>
    <link>https://dev.to/imadnan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F928295%2Fcf0ba5a7-f150-4268-8dd0-4e544f34ed6c.png</url>
      <title>DEV Community: Syed Mohd Adnan</title>
      <link>https://dev.to/imadnan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imadnan"/>
    <language>en</language>
    <item>
      <title>Flutter InputChips Inside TextFormField</title>
      <dc:creator>Syed Mohd Adnan</dc:creator>
      <pubDate>Sun, 18 Sep 2022 18:05:19 +0000</pubDate>
      <link>https://dev.to/imadnan/flutter-inputchips-inside-textformfield-fo2</link>
      <guid>https://dev.to/imadnan/flutter-inputchips-inside-textformfield-fo2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hi,&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;I'm writing this tutorial to share and to keep it as reference.&lt;br&gt;
The process of making InputChip and building them inside the  TextFormField, by the way this is first time ever that I have written anything so please forgive me for errors in English.&lt;/p&gt;

&lt;p&gt;As per this task I didn't find any suitable Dependency in &lt;br&gt;
&lt;a href="https://pub.dev/" rel="noopener noreferrer"&gt;https://pub.dev/&lt;/a&gt; so I searched a lot and there is not much written about this even on Stack Overflow that's why I did this myself that is also without any dependency.&lt;/p&gt;

&lt;p&gt;InputChip is Class provided in flutter Framework to build Chips on Input, to learn more: &lt;br&gt;
&lt;a href="https://api.flutter.dev/flutter/material/InputChip-class.html/" rel="noopener noreferrer"&gt;https://api.flutter.dev/flutter/material/InputChip-class.html/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Now, to Implement this? Follow along:&lt;/p&gt;

&lt;h3&gt;
  
  
  - Creating InputChip:
&lt;/h3&gt;

&lt;p&gt;Constructor of InputChips least required &lt;strong&gt;label&lt;/strong&gt; property as &lt;strong&gt;Widget&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

InputChip(
    label: Text('InputChips'),
  )


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7euihh9jj2hnyt2bzviq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7euihh9jj2hnyt2bzviq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By Default these chips are disabled. To enable, you need to pass &lt;strong&gt;onPressed&lt;/strong&gt; callback (and not setting &lt;strong&gt;isEnabled&lt;/strong&gt; to &lt;em&gt;false&lt;/em&gt;). Setting &lt;strong&gt;isEnabled&lt;/strong&gt; to true without passing &lt;strong&gt;onPressed&lt;/strong&gt; callback will cause Flutter disabling the widget.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

InputChip(
    selected: _selected,
    label: Text('ActivatedChip'),
    onPressed: () {
      print('Chip is pressed');

      setState(() {
        _selected = !_selected;
      });
    }
  )


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6gi7scukn8oxag3xxo5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6gi7scukn8oxag3xxo5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  - Avatar in InputChip:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Avatar&lt;/strong&gt; Property is used to display before label. It can be an &lt;strong&gt;image&lt;/strong&gt;, an &lt;strong&gt;Icon&lt;/strong&gt;, a &lt;strong&gt;CircleAvatar&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

InputChip(
    selected: _selected,
    label: Text('Star'),
    avatar: const Icon(Icons.star),
    onPressed: () {
      print('Chip is pressed');

      setState(() {
        _selected = !_selected;
      });
    }
  )


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjaj4y9cr5d7i7u34ho2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjaj4y9cr5d7i7u34ho2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  - Customizing label in InputChip:
&lt;/h3&gt;

&lt;p&gt;Labet text can be customized using &lt;strong&gt;labelStyle&lt;/strong&gt; and &lt;strong&gt;labelPadding&lt;/strong&gt; property.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

 InputChip(
    selected: _selected,
    label: Text('italics'),
    labelStyle: TextStyle(color: Colors.black, fontStyle: FontStyle.italic),
    labelPadding: EdgeInsets.all(3.0),
    onPressed: () {
      print('Chip is pressed');

      setState(() {
        _selected = !_selected;
      });
    }
  }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2s0hwl7nqq30jpaxri57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2s0hwl7nqq30jpaxri57.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  - Other Properties in InputChip:
&lt;/h3&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;backgroundColor&lt;/li&gt;
&lt;li&gt;selectedColor&lt;/li&gt;
&lt;li&gt;tooltip (shows text on longPress on chip)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  - Handling Deletion in InputChip:
&lt;/h3&gt;

&lt;p&gt;For deletion inputchip can be provided with a delete icon to delete with &lt;strong&gt;onDeleted&lt;/strong&gt; property passed inside &lt;strong&gt;onPressed&lt;/strong&gt; callback.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  InputChip(
    selected: _selected,
    label: Text('Delete'),
    onPressed: () {
      print('Chip is pressed');

      setState(() {
        _selected = !_selected;
      });
    },
    onDeleted: () {
      print('Chip is deleted');
    },
  )


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qcgv5iz8ney4r7jwrk4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qcgv5iz8ney4r7jwrk4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you Be Like Enough of InputChip Knowledge How to Pass data to make them render inside TextField, don't fret I'll describe and post full code:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  - Custom Text in InputChip:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Declare TextEditingController.&lt;/li&gt;
&lt;li&gt;For inputting data, you need to provide either a &lt;strong&gt;TextField&lt;/strong&gt; or &lt;strong&gt;TextFormField&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In TextFormField &lt;strong&gt;controller&lt;/strong&gt; property call &lt;strong&gt;TextEditingController&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now using Callback get the Input value as &lt;strong&gt;TextEditingController.text&lt;/strong&gt; inside the chip &lt;strong&gt;Label&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjefzse6ixb4ezib30cef.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjefzse6ixb4ezib30cef.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  - Getting Chip Inside TextFormField:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Make a &lt;strong&gt;List&lt;/strong&gt; to hold the value of chip on TextEditingController Callback.&lt;/li&gt;
&lt;li&gt;Then map List value to a variable.&lt;/li&gt;
&lt;li&gt;Inside &lt;strong&gt;decoration&lt;/strong&gt; property in &lt;strong&gt;TextFormField&lt;/strong&gt; create another chip.&lt;/li&gt;
&lt;li&gt;Used the map variable inside the new &lt;strong&gt;chip&lt;/strong&gt; as &lt;strong&gt;label&lt;/strong&gt; on the callback of previous chip.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Voila 🪄&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1ljbea5rq29j0pxzdf2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1ljbea5rq29j0pxzdf2.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fohy1siebpgqzjwn8o6mw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fohy1siebpgqzjwn8o6mw.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub repository&lt;br&gt;
The code is open source, so if you want to get it you can do it here:&lt;br&gt;
&lt;a href="https://github.com/im-adnan/TextInputChips_Example" rel="noopener noreferrer"&gt;https://github.com/im-adnan/TextInputChips_Example&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Thanks for reading this article, I hope that now you could understand better how to Implement InputChips inside TextFields. If this was helpful for you, I’ll really appreciate your feedback and also your claps! 👏&lt;/p&gt;

&lt;p&gt;You can find me on Twitter: @1m_adnan 😊&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>textformfield</category>
      <category>inputchip</category>
    </item>
  </channel>
</rss>
