mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 04:45:39 +00:00 
			
		
		
		
	Working on implementation of a related field
This commit is contained in:
		| @@ -1,6 +1,8 @@ | ||||
|  | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flutter_typeahead/flutter_typeahead.dart'; | ||||
| import 'package:image_picker/image_picker.dart'; | ||||
| import 'package:inventree/api.dart'; | ||||
|  | ||||
| import 'package:inventree/l10.dart'; | ||||
|  | ||||
| @@ -115,6 +117,81 @@ 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}) : | ||||
|   | ||||
| @@ -187,6 +187,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> { | ||||
|           "keywords": {}, | ||||
|           "link": {}, | ||||
|  | ||||
|           "category": {}, | ||||
|  | ||||
|           // Checkbox fields | ||||
|           "active": {}, | ||||
|           "assembly": {}, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user