Giter Club home page Giter Club logo

Comments (13)

sjmcdowall avatar sjmcdowall commented on August 15, 2024

@KaYBlitZ -- Hey, any thoughts on this? Our app is sort of in limbo without figuring this out .. Cheers!

from flutter_typeahead.

KaYBlitZ avatar KaYBlitZ commented on August 15, 2024

from flutter_typeahead.

sjmcdowall avatar sjmcdowall commented on August 15, 2024

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.

KaYBlitZ avatar KaYBlitZ commented on August 15, 2024

from flutter_typeahead.

sjmcdowall avatar sjmcdowall commented on August 15, 2024

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.

KaYBlitZ avatar KaYBlitZ commented on August 15, 2024

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.

sjmcdowall avatar sjmcdowall commented on August 15, 2024

from flutter_typeahead.

sjmcdowall avatar sjmcdowall commented on August 15, 2024

BTW -- I think there is a very similar request in the PageWise widget too if I am reading that correctly ..

from flutter_typeahead.

irperera avatar irperera commented on August 15, 2024

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.

sinhpn92 avatar sinhpn92 commented on August 15, 2024

Have any other solution @sjmcdowall ?

from flutter_typeahead.

justincbeck avatar justincbeck commented on August 15, 2024

FWIW, I have this need as well.

from flutter_typeahead.

justincbeck avatar justincbeck commented on August 15, 2024

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.

greenking19 avatar greenking19 commented on August 15, 2024

In 2023, I also have this need, but I haven't found a solution.

from flutter_typeahead.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.