Typedef in Dart is used to create a user-defined identity (alias) for a function, and we can use that identity in place of the function in the program code. When we use typedef we can define the parameters of the function.
Syntax: typedef function_name ( parameters );
With the help of typedef, we can also assign a variable to a function.
Syntax:typedef variable_name = function_name;
After assigning the variable, if we have to invoke it then we go as:
Syntax: variable_name( parameters );
By this we will be able to use a single function in different ways:
Example 1: Using typedef in Dart.
This is Geek1 1 and 2 are lucky geek numbers !! This is Geek2 3 + 4 is equal to 7.
Note: Apart from this, typedef can also act as parameters of a function.
Example 2: Using typedef as a parameter of a function.
Welcome to GeeksForGeeks This is Geek1 21 and 23 are lucky geek numbers !!
- How to Combine Lists in Dart?
- Basics of Numbers in Dart
- Dart - Super and This keyword
- Dart - Standard Input Output
- Generators in Dart
- Dart - Classes And Objects
- Operators in Dart
- Dart - Loops
- Switch Case in Dart
- Dart - Loop Control Statements (Break and Continue)
- Dart Programming - Functions
- Instance and class methods in Dart
- Abstract Classes in Dart
- Labels in Dart
- Dart Programming - List
- Different Types of Functions in Dart
- Dart - Splitting of String
- Method Overriding in Dart
- Concept of Isolates in Dart
- Concept of Callable Classes in Dart
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : addamkoroma