flutter-form-builder-ecosystem / flutter-form-builder-ecosystem/form_builder_extra_fields
[FormBuilderTypeAhead]: How to Select a value to be preselected
- Dominant language
- Dart
- Stars
- 29
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Package/Plugin version
Current
### Platforms
- [X] Android
- [X] iOS
- [X] Linux
- [X] MacOS
- [X] Web
- [X] Windows
### Flutter doctor
Flutter doctor
```bash
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.0 22A380 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.82.2)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
```
### Minimal code example
Code sample
```dart
final initialValue = selected != null
? data.firstWhere(
(element) => element.iaCaseType == selected,
)
: null;
print('IA type initial value ${initialValue?.iaTypeName}');
return FormBuilderTypeAhead(
initialValue: initialValue,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'IA Type',
hintText: 'IA Type',
),
name: 'ia_type',
itemBuilder: (context, item) {
return ListTile(title: Text(item.iaTypeName!));
},
selectionToTextTransformer: (suggestion) =>
suggestion.iaTypeName!,
controller: TextEditingController(text: ''),
validator: FormBuilderValidators.compose(
[FormBuilderValidators.required()]),
suggestionsCallback: (query) {
final pattern = RegExp('[^a-zA-Z0-9\s]');
if (query.isNotEmpty) {
var lowercaseQuery = query.toLowerCase();
return data.where((IaTypes item) {
return item.iaTypeName!
.toLowerCase()
.replaceAll(pattern, '')
.contains(lowercaseQuery);
}).toList(growable: false)
..sort((a, b) => a.iaTypeName!
.toLowerCase()
.indexOf(lowercaseQuery)
.compareTo(b.iaTypeName!
.toLowerCase()
.indexOf(lowercaseQuery)));
} else {
return data;
}
},
);
```
### Current Behavior
No preselected value is showing. Even though I have selected ***initialValue*** and passed it to intialvalue field in the `FormBuilderTypeAhead`
### Expected Behavior
when initialvalue to be passed to filed it should show it as preseleted item
### Steps To Reproduce
Using Obx of Getx
### Aditional information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.