Skip to content

Can't instantiate FormBuilderTypeAhead with custom controller #144

Closed
@taigfs

Description

@taigfs

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());
  },
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions