2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 18:55:34 +00:00

Looks like dropdown_search is the way to go!

This commit is contained in:
Oliver
2021-07-26 17:21:17 +10:00
parent ca4297ae6d
commit d07b704014
7 changed files with 97 additions and 87 deletions

View File

@ -116,82 +116,6 @@ class CheckBoxField extends FormField<bool> {
);
}
class AutocompleteFormField extends TypeAheadFormField {
final String label;
final _controller = TextEditingController();
final String url;
dynamic filters = {};
AutocompleteFormField(
this.label,
this.url,
{
this.filters,
Widget Function(dynamic)? renderer,
String? hint,
}) :
super(
textFieldConfiguration: TextFieldConfiguration(
autofocus: true,
decoration: InputDecoration(
hintText: hint,
border: OutlineInputBorder(),
),
),
suggestionsCallback: (String pattern) async {
Map<String, String> _filters = {};
if (filters != null) {
for (String key in filters) {
_filters[key] = filters[key].toString();
}
}
_filters["search"] = pattern;
_filters["offset"] = "0";
_filters["limit"] = "25";
final APIResponse response = await InvenTreeAPI().get(
url,
params: _filters
);
if (response.isValid()) {
List<dynamic> results = [];
for (var result in response.data['results'] ?? []) {
results.add(result);
}
return results;
} else {
return [];
}
},
itemBuilder: (context, suggestion) {
print("item builder: " + suggestion.toString());
return ListTile(
title: Text(suggestion['name']),
);
},
onSuggestionSelected: (suggestion) {
// TODO
},
onSaved: (value) {
// TODO
}
);
}
class StringField extends TextFormField {
StringField({String label = "", String? hint, String? initial, Function(String?)? onSaved, Function? validator, bool allowEmpty = false, bool isEnabled = true}) :