Dart/Flutter support for delegates

2,464

The only one that I know of that is delegate "like" is typedef. It really is a way to strongly type callbacks. A common one is WidgetBuilder

typedef Widget WidgetBuilder(BuildContext context);

or the more preferred way of writing a callback

typedef WidgetBuilder = Widget Function(BuildContext context);

But you can also build your own

Share:
2,464
Yarm
Author by

Yarm

Updated on December 04, 2022

Comments

  • Yarm
    Yarm over 1 year

    Does Dart 2.0 support the concept of a delegate? Having reviewed the documentation I assume not. So is this is an omission? Or is there an alternate approach to achieving the same? Possibly using streams?

    • Edman
      Edman almost 6 years
      What kind of delegation are you looking for?
    • Yarm
      Yarm almost 6 years
      A page calls a route which calls another route. Tthen an action pops both the second route and calls a delegate to Also pop the first route.
    • matanlurey
      matanlurey almost 6 years
      This is unrelated to Dart. You're looking for a Flutter feature?
    • Yarm
      Yarm almost 6 years
      No, looking for a language feature (dart) to use with the framework (flutter).