Voidcallback x Function what’s the difference?

Asked

Viewed 488 times

0

In the documentation it states that

part of dart.ui;
/// Signature of callbacks that have no arguments and return no data.
typedef VoidCallback = void Function();

From what I understand VoidCallback is a 'nickname' for void Function() and used only where the graphical part (UI) of the flutter is used, is that the same or has more difference?

2 answers

3


1) From what I understand Voidcallback is a 'nickname' for void Function()

Correct. Because it is open-source, you have checked that it is the same as a function that has no return, and does not receive parameters. This can also be seen in documentation.

2) used only where the graphical part (UI) of the flutter is used

I imagine you deducted that from the line part of dart.ui. According to the documentation of that import:

Built-in types and core Primitives for a Flutter application.

Main built-in and primitive types for a flutter application.

[...] such as classes for Driving the input, Graphics text, layout, and Rendering subsystems.

[...] such as classes to drive data input, graphics, layout and render subsystems

(From the link above, free translation)

Therefore, we can realize that this import does not only deal with the part graphic, but of any other example among those cited.

It is important to note that it is not because this typedef was defined in this import that it needs to be used solely and exclusively with the same goals. It is nothing more than a apelido, a convenience to show what kind of function is expected. When someone reads VoidCallback is immediate to what.

3) Is that right or has any other difference?

That’s all there is to it.

1

There is no difference, it is only a simple way to use the type, is the library using a language resource to facilitate the use, the typedef does not add functionality, it just generates the same nickname. It probably does this because it uses too much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.