Article Image

Typedef in Dart.

19th September 2018

Hello everybody, in this post, we'll see what typedef is and how use it in Dart.

We suppose we need to concat two string with a special characters. Notice the problem is very simple in order to explain what typedef is.

So, this is a typedef:

Typedefs are alias for functions which are object. So, Typedefs are object with an alias =).

So far, so good. Now, we need to implement a function which has same signature, i mean: (String, String) => (String) in our case. I mean given two params String then output will be another String . i.e:

We need to use our typedef Join and ours functions in a joinWith new function:

Finally, we use our typedef:

You can test this code running on console:

dart main.dart

Enjoy!

More Than Code LLC

Address: 8 The Green STE B, Dover, DE 19901

Contact: mtc.morethancode@gmail.com

© Copyright 2022 All right reserved to More Than Code LLC