flutter_typeahead
flutter_typeahead copied to clipboard
KeyboardType problem
When KeyboardType is TextInputType.number or phone and autofocus is true, on the start screen with text field, when typing any symbols it not appear on text field but when I tap again on text field and start typing symbols, they are appears on textfield TextField implementation:
class ZlakerTextFieldWithDropDown<T> extends StatefulWidget {
final TextEditingController controller;
final FutureOr<Iterable<T>> Function(String) onQueryTyped;
final List<T> itemList;
final String hintText;
final int? minCharsForSuggestions;
final Function(T) onItemSelected;
final FocusNode? focusNode;
final String Function(T) titleBuilder;
final bool? autoFocus;
final bool? isActive;
final TextInputAction? textInputAction;
final TextInputType? inputType;
final String? errorText;
final int? length;
final List<TextInputFormatter>? formatters;
const ZlakerTextFieldWithDropDown({
Key? key,
required this.controller,
required this.onQueryTyped,
required this.itemList,
required this.hintText,
required this.onItemSelected,
required this.titleBuilder,
this.autoFocus,
this.textInputAction,
this.focusNode,
this.inputType,
this.isActive,
this.errorText,
this.length,
this.formatters,
this.minCharsForSuggestions,
}) : super(key: key);
@override
State<ZlakerTextFieldWithDropDown<T>> createState() => _ZlakerTextFieldWithDropDownState<T>();
}
class _ZlakerTextFieldWithDropDownState<T> extends State<ZlakerTextFieldWithDropDown<T>> {
late bool isActive;
late SuggestionsBoxController _suggestionsBoxController;
List<TextInputFormatter>? newFormatters;
@override
void initState() {
isActive = false;
_suggestionsBoxController = SuggestionsBoxController();
super.initState();
}
@override
void dispose() {
super.dispose();
}
void changeIsActiveState([bool? newActiveState]) {
setState(() {
isActive = newActiveState ?? !isActive;
});
if (isActive) {
// _suggestionsBoxController.toggle();
} else {
_suggestionsBoxController.open();
}
}
@override
Widget build(BuildContext context) {
setFormatters();
return TypeAheadField<T>(
suggestionsBoxController: _suggestionsBoxController,
loadingBuilder: (context) => const LoadingIndicator(),
hideSuggestionsOnKeyboardHide: true,
suggestionsCallback: (suggestion) async {
Iterable<T>? result;
if (widget.controller.text.length >= (widget.minCharsForSuggestions ?? 2)) {
result = await widget.onQueryTyped(suggestion);
changeIsActiveState(result.isEmpty);
}
return result ?? [];
},
itemBuilder: (context, item) => ListTile(
title: Text(
widget.titleBuilder(item),
style: Theme.of(context).textTheme.bodyText1,
),
),
noItemsFoundBuilder: (context) => Container(
height: 150,
padding: const EdgeInsets.all(16),
child: Text(
'Ничего не найдено.',
style: Theme.of(context).textTheme.subtitle1,
),
),
onSuggestionSelected: (suggestion) {
changeIsActiveState(true);
widget.onItemSelected(suggestion);
},
minCharsForSuggestions: widget.minCharsForSuggestions ?? 2,
textFieldConfiguration: TextFieldConfiguration(
enabled: widget.isActive ?? true,
maxLength: widget.length,
focusNode: widget.focusNode,
keyboardType: widget.inputType ?? TextInputType.text,
onChanged: (text) => widget.onQueryTyped(text),
controller: widget.controller,
textInputAction: widget.textInputAction,
autofocus: widget.autoFocus ?? false,
inputFormatters: newFormatters,
enableSuggestions: false,
autocorrect: false,
decoration: ZlakerTextField.decoration(
context,
widget.hintText,
TextFieldActionButton(
svgIconPath: isActive ? 'assets/icons/arrow_down.svg' : 'assets/icons/arrow_up.svg',
onPressed: changeIsActiveState,
),
widget.errorText,
),
),
);
}
void setFormatters() {
if (widget.formatters != null) {
newFormatters = widget.formatters;
} else if (widget.inputType == TextInputType.number) {
newFormatters = [FilteringTextInputFormatter.digitsOnly];
}
}
}
and current text field
ZlakerTextFieldWithDropDown<Organisation>(
hintText: 'ИНН',
controller: _presenter.innController,
focusNode: _presenter.innFocusNode,
errorText: model.innErrorText,
length: 12,
textInputAction: TextInputAction.next,
inputType: TextInputType.phone,
onItemSelected: _presenter.onOrganisationSelected,
itemList: model.organisations,
onQueryTyped: _presenter.getOrganisationList,
titleBuilder: (item) => '${item.inn}, ${item.directorFullName}',
),
but when
keyboardType: TextInputType.text
symbols on typing appears on textfield