Skip to main content

Command Palette

Search for a command to run...

Dart: Typedef Keyword

Published
1 min read
Dart: Typedef Keyword

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 varibale_name= return_type function_name ( parameters );

Example:

typedef Temp(int a);

First(int a){
  print('First function: ${a+1}');
}

Second(int a){
  print('Second Function: ${a+2}');
}

void main(){
  Temp x= First;
  x(5); //Output: First function: 5

  x=Second;
  x(6); //Output: Second function: 6
}

Conclusion:

Using typedef helps make your code more expressive, especially when dealing with complex function types, such as callbacks or event handlers. It enhances code readability and makes it easier to understand the intent of the code.

Dart

Part 22 of 50

I'll be here to provide explanations, examples, and assistance as you explore the depths of Dart programming language. Together, we'll unravel the intricacies of Dart, from its fundamental concepts to

Up next

Dart Debugging

Debugging is an integral part of software development, allowing developers to identify and fix issues in their code. In the world of Dart and Flutter, debugging techniques can significantly improve your productivity and help you create high-quality a...

More from this blog

Flutter Journey with Jinali

141 posts