Comments (13)
@KaYBlitZ -- Hey, any thoughts on this? Our app is sort of in limbo without figuring this out .. Cheers!
from flutter_typeahead.
from flutter_typeahead.
Tried that -- but since the text hasn't changed it doesn't fire getSuggestions :( We are now thinking of adding a keyboard controller and hacking the text input to force a refire -- but seems hacky .. code like:
void _fiddleTheKeyboard() {
if (_oldPattern?.isEmpty ?? true) {
// set the kb to "something" and then clear it
_recipientsSearchController.text = ' '; // couple spaces
_recipientsSearchController.clear();
} else {
// clear the kb and set it to the old pattern
_recipientsSearchController.clear();
_recipientsSearchController.text = _oldPattern;
}
_oldPattern = null; // clear out old search pattern so we force a new query
}
Was hoping for a cleaner method ..
from flutter_typeahead.
from flutter_typeahead.
Yes, that option has always been on -- but it doesn't fire because the old pattern and new are the same .. and I think that is correct behavior because a build() can happen often in Flutter and if the pattern hasn't changed you (in general) don't want to re do getSuggestions .. unless you want to FORCE a refresh() ..
BTW -- the keyboard controller hack works .. but it's a hack .. :)
from flutter_typeahead.
Glad the hack works. But I just tried out the focus method and it works for me? Tried it in the example app. I click the button an it focuses on the text field and it automatically gets the suggestions for me. Like so:
class _FormExampleState extends State<FormExample> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _typeAheadController = TextEditingController();
final FocusNode _focusNode = FocusNode();
String _selectedCity;
@override
void dispose() {
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Form(
key: this._formKey,
child: Padding(
padding: EdgeInsets.all(32.0),
child: Column(
children: <Widget>[
Text('What is your favorite city?'),
TypeAheadFormField(
getImmediateSuggestions: true,
textFieldConfiguration: TextFieldConfiguration(
focusNode: _focusNode,
decoration: InputDecoration(labelText: 'City'),
controller: this._typeAheadController,
),
suggestionsCallback: (pattern) {
return CitiesService.getSuggestions(pattern);
},
itemBuilder: (context, suggestion) {
return ListTile(
title: Text(suggestion),
);
},
transitionBuilder: (context, suggestionsBox, controller) {
return suggestionsBox;
},
onSuggestionSelected: (suggestion) {
this._typeAheadController.text = suggestion;
},
validator: (value) {
if (value.isEmpty) {
return 'Please select a city';
}
},
onSaved: (value) => this._selectedCity = value,
),
SizedBox(
height: 10.0,
),
RaisedButton(
child: Text('Press me!'),
onPressed: () {
FocusScope.of(context).requestFocus(_focusNode);
},
)
],
),
),
);
}
}
Are you manually checking the old pattern vs the new pattern in your code and somehow cancelling getSuggestions if it's the same? This is already automatic in TypeAhead, specifically this code:
this._controllerListener = () {
// If we came here because of a change in selected text, not because of
// actual change in text
if (widget.controller.text == this._lastTextValue) return;
this._lastTextValue = widget.controller.text;
from flutter_typeahead.
from flutter_typeahead.
BTW -- I think there is a very similar request in the PageWise widget too if I am reading that correctly ..
from flutter_typeahead.
is there away to just find only the item or text that is typed in the box. exmaple I use it for codes, if someone type 100, i dont need 1001 or 1002 coming up.
from flutter_typeahead.
Have any other solution @sjmcdowall ?
from flutter_typeahead.
FWIW, I have this need as well.
from flutter_typeahead.
I got this to work using the built in Autocomplete widget:
TextEditingController? autoCompleteEditingController;
String? selected;
return Autocomplete<SmartyModel>(
fieldViewBuilder:
(context, textEditingController, focusNode, onFieldSubmitted) {
autoCompleteEditingController = textEditingController;
return TextFormField(
controller: textEditingController,
focusNode: focusNode,
);
},
optionsBuilder: (TextEditingValue textEditingValue) async {
if (textEditingValue.text == '') {
return const Iterable.empty();
} else {
return await provider.search(
textEditingValue.text,
selected,
);
}
},
displayStringForOption: (option) => option.toString(),
onSelected: (option) {
if (selected != null) {
selected = null;
autoCompleteEditingController!.text = option.toString();
} else {
selected = option.toSelectedString();
autoCompleteEditingController!.text = option.toSearchString();
}
},
);
from flutter_typeahead.
In 2023, I also have this need, but I haven't found a solution.
from flutter_typeahead.
Related Issues (20)
- [Bug] TextInputAction.next throw RenderAbstractViewport.of() HOT 1
- suggestions not showing
- [Bug] WASM compilation HOT 2
- [Bug] Need to set style.height to remove error text using flutter web HOT 2
- [Bug] I updated from 4.8.0 to 5.2.0. The code is compiling but the list of suggestions is not being displayed. HOT 5
- when adding more typeahead field into one page iOS app crashing [Bug] HOT 1
- Facing Error when try to build the app. [Bug] HOT 1
- [Question] How to change the width of the suggestionBox, without changing the width of the TextField HOT 4
- how to use suggestion controller want to display data list when user just focus on text box
- [Feature] Keyboard focus remains in text field while changing selection HOT 5
- [Feature] library should also export src/common/base/types.dart HOT 1
- How can i give the hint text and style HOT 3
- [Bug] Adding the TypeAhead widget inside a datatable breaks the flow when using keyboard navigation HOT 2
- [Bug] Keyboard up arrow skips multiple items in list on desktop HOT 1
- Cannot apply border to InkWell in material defaults HOT 1
- Mouse cursor doesn't change to pointer-hand when `ListTile` is returned in `itemBuilder`
- Add to other list, Typeahead suggestion box auto focus HOT 1
- [Bug] - Clear Suggestions Cache
- Navigating back to a typeaheadfield with a swipe gesture makes the field lose focus and become unresponsive HOT 1
- [Bug] Drop frame in 5.x.x version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_typeahead.