rrousselGit / functional_widget

A code generator to write widgets as function without loosing the benefits of classes.
597 stars 46 forks source link

VoidCallback parameter yields dynamic #43

Closed derolf closed 4 years ago

derolf commented 5 years ago

Example:

@widget
Widget foo(VoidCallback bar) => Container();

generates

class Foo extends StatelessWidget {
  const Foo(this.bar, {Key key}) : super(key: key);

  final dynamic bar;

  @override
  Widget build(BuildContext _context) => foo(bar);
}

resulting in error:

The argument type 'dynamic' can't be assigned to the parameter type 'VoidCallbackvoid Function()'.dart(argument_type_not_assignable)
rrousselGit commented 5 years ago

The issue is on https://github.com/dart-lang/build/issues/733. functional_widget cannot do anything about it, sadly.

derolf commented 5 years ago

I don't get what the actual problem is... because it works for other types...

However, a workaround is to declare VoidCallback in the same (original) file.

rrousselGit commented 5 years ago

The issue is, voidcallback is originally defined in Flutter. Which code generators don't have access to. So the type do not resolve

derolf commented 5 years ago

Got it! Probably you should mention that in the docs...

Can this happen to other types as well? Can’t you just handle unknown types as “opaque”?

derolf commented 5 years ago

I am not able to replicate this issue in a test. Do you know how to do that?

rrousselGit commented 5 years ago

Wait, Voidcallback? The issue should happen for things from dart:ui only, like Color.

Voidcallback should work (although the generator will instead write void Function()

derolf commented 5 years ago

I have a fix. Should work now. It builds the parameter list from the AST instead of Element.

cubuspl42 commented 5 years ago

Any progress on this one? It's a blocker for me...

rrousselGit commented 5 years ago

No. You can make a PR if you need to.

liri2006 commented 4 years ago

I'm getting same issue for basically any custom type defined outside of file with widget.

derolf commented 4 years ago

You might want to revamp https://github.com/rrousselGit/functional_widget/pull/48

liri2006 commented 4 years ago

@rrousselGit Can you take a look at PR @derolf submitted when you have a minute? This lib is awesome and it would be great to get this issue fixed.

truongsinh commented 4 years ago

with the latest version, i can no longer recreate this bug.

@widget
Widget foo(VoidCallback bar) => Container();

generates for me (excuse HookWidget but it should be the same anyway)

class Foo extends HookWidget {
  const Foo(this.bar, {Key key}) : super(key: key);

  final void Function() bar;

  @override
  Widget build(BuildContext _context) => foo(bar);
}
rrousselGit commented 4 years ago

Good catch