Added methods to search and add for new labels on a list

This commit is contained in:
kolaente 2019-03-21 08:16:24 +01:00
parent 24ffef1aef
commit 4d6390331b
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B

View File

@ -28,8 +28,9 @@ class _TaskEditPageState extends State<TaskEditPage> {
String _text, _description, _repeatAfterType;
Duration _repeatAfter;
List<Label> _labels;
List<Label>
_suggestedLabels; // we use this to find the label object after a user taps on the suggestion, because the typeahead only uses strings, not full objects.
var _reminderInputs = new List<Widget>();
var _labelWidgets = new List<LabelComponent>();
@override
Widget build(BuildContext ctx) {
@ -240,7 +241,8 @@ class _TaskEditPageState extends State<TaskEditPage> {
TypeAheadFormField(
textFieldConfiguration: TextFieldConfiguration(
//controller: _typeAheadController,
decoration: InputDecoration(labelText: 'City')),
decoration:
InputDecoration(labelText: 'Add a new label')),
suggestionsCallback: (pattern) {
return _searchLabel(pattern);
},
@ -253,8 +255,7 @@ class _TaskEditPageState extends State<TaskEditPage> {
return suggestionsBox;
},
onSuggestionSelected: (suggestion) {
// Here we need to save it
print(suggestion);
_addLabel(suggestion);
},
),
Builder(
@ -324,7 +325,20 @@ class _TaskEditPageState extends State<TaskEditPage> {
return VikunjaGlobal.of(context)
.labelService
.getAll(query: query)
.then((labels) => labels.map((label) => label.title).toList());
.then((labels) {
_suggestedLabels = labels;
return labels.map((label) => label.title).toList();
});
}
_addLabel(String labelTitle) {
// FIXME: This is not an optimal solution...
_suggestedLabels.forEach((label) {
if (label.title == labelTitle) {
_labels.add(label);
}
});
// TODO: really add the label to the list
}
// FIXME: Move the following two functions to an extra class or type.