ionicfirebaseapp / getwidget

Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.
https://www.getwidget.dev
MIT License
4.55k stars 606 forks source link

GFDropdown requires `dynamic` for `onChanged` parameter #314

Closed lukehutch closed 1 year ago

lukehutch commented 1 year ago

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):

Smartphone (please complete the following information):

lukehutch commented 1 year ago

Created a dart lang issue, since this may be a compiler/runtime issue. https://github.com/dart-lang/sdk/issues/51461

atul-vashisht commented 1 year ago

@lukehutch Please check https://github.com/ionicfirebaseapp/getwidget/issues/304

lukehutch commented 1 year ago

Thanks, this is a dup, closing