ionicfirebaseapp/getwidget

GFDropdown requires `dynamic` for `onChanged` parameter

lukehutch opened this issue · 3 comments

Describe the bug

The following code compiles but causes a red screen exception at runtime:

GFDropdown(
  hint: const Text('Choose an item'),
  items: dropdownItems,
  onChanged: (newValue) {
    setState(() {
      dropdownValue = newValue;
    });
  },
),
The following _TypeError was thrown building GFDropdown<String>(dirty, state: _GFDropdownState#948b2):
type '(String?) => void' is not a subtype of type '((dynamic) => void)?'

You have to add dynamic to prevent this exception:

GFDropdown(
  hint: const Text('Choose an item'),
  items: dropdownItems,
  onChanged: (dynamic newValue) {
    setState(() {
      dropdownValue = newValue;
    });
  },
),

To Reproduce

Put the above code in a widget tree

Expected behavior

dynamic should not be needed here (and it's not for other GF widget types that I have tried). It's a bit shocking that this produces a runtime error.

Desktop (please complete the following information):

  • OS: [e.g. iOS] Linux
  • Browser [e.g. chrome, safari] Chrome
  • Version [e.g. 22] latest

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] Android emulator, Pixel 6, Android 33

Created a dart lang issue, since this may be a compiler/runtime issue. dart-lang/sdk#51461

Thanks, this is a dup, closing