Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't instantiate FormBuilderTypeAhead with custom controller #144

Closed
taigfs opened this issue Sep 27, 2019 · 1 comment
Closed

Can't instantiate FormBuilderTypeAhead with custom controller #144

taigfs opened this issue Sep 27, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@taigfs
Copy link

taigfs commented Sep 27, 2019

I'm trying to build a instance of FormBuilderTypeAhead with a custom controller, but it breaks at flutter_form_builder/src/fields/form_builder_typeahead.dart:173:32.

Apparently the package is not initializing the variable _typeAheadController if a custom controller is provided.

My code is as follows:

var _controller = TextEditingController(text: "");

return FormBuilderTypeAhead(
  attribute: "city",
  controller: _controller,
  decoration: InputDecoration(
    hintText: 'City',
    labelText: 'City',
  ),
  itemBuilder: (context, suggestion) {
    return ListTile(
      title: Text(suggestion.label),
    );
  },
  transitionBuilder: (context, suggestionsBox, controller) {
    return suggestionsBox;
  },
  selectionToTextTransformer: (MOption suggestion) {
    return suggestion.toString();
  },
  suggestionsCallback: (pattern) async {
    var s = CitiesService.getOptions(pattern);
    s.add(MOption(label: 'Create $pattern...', value: -1));
    return s;
  },
  onSuggestionSelected: (suggestion) {
    print(suggestion.toString());
  },
);
@danvick danvick added the bug Something isn't working label Nov 4, 2019
@mrsid96
Copy link

mrsid96 commented Nov 23, 2019

Is there any workaround for the same ?

Apparently there is a patch, in selectionToTextTransformer attribute
selectionToTextTransformer: (dynamic val) { //you can update the controller manually here (controller.text = val.toString()) return val.toString(); },

@danvick danvick closed this as completed in 95fc64a Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants