Created
October 3, 2020 12:06
-
-
Save CoderJava/f00c1f3d28e7a2bee7081a7dd9f6ffac to your computer and use it in GitHub Desktop.
Input chip with TextField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| class InputChipExample extends StatefulWidget { | |
| @override | |
| _InputChipExampleState createState() => _InputChipExampleState(); | |
| } | |
| class _InputChipExampleState extends State<InputChipExample> { | |
| final controllerInput = TextEditingController(); | |
| final listChips = <String>[]; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('Input Chip'), | |
| ), | |
| body: Padding( | |
| padding: const EdgeInsets.all(16.0), | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: [ | |
| TextField( | |
| controller: controllerInput, | |
| onSubmitted: (value) { | |
| setState(() { | |
| controllerInput.text = ''; | |
| listChips.add(value); | |
| }); | |
| }, | |
| decoration: InputDecoration( | |
| hintText: 'Input a email', | |
| isDense: true, | |
| ), | |
| keyboardType: TextInputType.emailAddress, | |
| ), | |
| Wrap( | |
| children: listChips.map((e) { | |
| return InputChip( | |
| avatar: CircleAvatar(child: Icon(Icons.account_circle),), | |
| label: Text(e), | |
| onDeleted: () => setState(() => listChips.remove(e)), | |
| ); | |
| }).toList(), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment