A simple tag editor.
To use this package, add material_tag_editor as a dependency in your pubspec.yaml file.
dependencies:
material_tag_editor:
git:
url: https://github.com/LostInDarkMath/material_tag_editor.gitImport it
import 'package:material_tag_editor/tag_editor.dart';Use the widget
TagEditor(
length: values.length,
delimiters: [',', ' '],
hasAddButton: true,
inputDecoration: const InputDecoration(
border: InputBorder.none,
hintText: 'Hint Text...',
),
onTagChanged: (newValue) {
setState(() {
values.add(newValue);
});
},
tagBuilder: (context, index) => _Chip(
index: index,
label: values[index],
onDeleted: onDelete,
),
)It is possible to build the tag from your own widget, but it is recommended that Material Chip is used
class _Chip extends StatelessWidget {
const _Chip({
required this.label,
required this.onDeleted,
required this.index,
});
final String label;
final ValueChanged<int> onDeleted;
final int index;
@override
Widget build(BuildContext context) {
return Chip(
labelPadding: const EdgeInsets.only(left: 8.0),
label: Text(label),
deleteIcon: Icon(
Icons.close,
size: 18,
),
onDeleted: () {
onDeleted(index);
},
);
}
}If you have any suggestion for including a feature or if something doesn't work, feel free to open a Github issue for us to have a discussion on it.
