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

FormBuilderTypeAhead<NonStringClass> bug #319

Closed
awhitford opened this issue Jun 14, 2020 · 1 comment
Closed

FormBuilderTypeAhead<NonStringClass> bug #319

awhitford opened this issue Jun 14, 2020 · 1 comment

Comments

@awhitford
Copy link
Collaborator

I think this line is a bug:

        ? widget.selectionToTextTransformer(_initialValue ?? '')

I think it should be:

        ? widget.selectionToTextTransformer(_initialValue) ?? ''

I am getting a runtime exception:

type 'String' is not a subtype of type 'MyClass'

I'm confused because my code is very close to this example.

@awhitford
Copy link
Collaborator Author

This whole expression:

    _initialText = (widget.selectionToTextTransformer != null)
        ? widget.selectionToTextTransformer(_initialValue ?? '')
        : _initialValue?.toString() ?? '';

should really be:

    _initialText = ((widget.selectionToTextTransformer != null)
            ? widget.selectionToTextTransformer(_initialValue)
            : _initialValue?.toString()) ??
        '';

The existing code is illegal because selectionToTextTransformer has a parameter of type T, but the expression _initialValue ?? '' will transform a null value into a String instead of T.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant