-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to add the user input value even if the value is not found. #121
Comments
Come Up with this solution FormBuilderChipsInput<String>(
decoration: InputDecoration(
labelText: 'Skills',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.w),
borderSide: BorderSide.none,
),
),
name: 'skills',
maxChips: 5,
findSuggestions: (String query) {
if (query.isNotEmpty) {
var lowercaseQuery = query.toLowerCase();
List<String> res = skills.where((skill) {
return skill
.toLowerCase()
.contains(query.toLowerCase());
}).toList(growable: false)
..sort(
(a, b) =>
a.toLowerCase().indexOf(lowercaseQuery).compareTo(
b.toLowerCase().indexOf(lowercaseQuery),
),
);
if (res.isNotEmpty) return res;
return ['Add $query'];
} else {
return const [];
}
},
chipBuilder: (context, state, skill) {
return InputChip(
key: ObjectKey(skill),
label: Text(skill),
/* avatar: CircleAvatar(
backgroundImage: NetworkImage(skill.imageUrl),
), */
onDeleted: () => state.deleteChip(skill),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
},
suggestionBuilder: (context, state, skill) {
final bool isAddSkillPresent = skill.startsWith('Add');
final formattedSkill = skill.replaceAll('Add', '');
return Container(
alignment: Alignment.centerLeft,
child: InkWell(
onTap: () => state.selectSuggestion(formattedSkill),
child: Chip(
key: ObjectKey(skill),
// onDeleted: () => state.selectSuggestion(skill),
label: Text(
skill,
style: TextStyle(
fontWeight: isAddSkillPresent
? FontWeight.bold
: FontWeight.normal,
),
),
// avatar: const CircleAvatar(),
),
),
);
},
allowChipEditing: true,
suggestionsBoxMaxHeight: 300.h,
),
|
A bit simpler solution:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like the implementation done in
flutter_tagging_plus: ^4.0.1
The text was updated successfully, but these errors were encountered: