Dart: Typedef Keyword

Dart: Typedef Keyword

ยท

1 min read

The typedef keyword in Dart is a way to define a type alias for a function type. A type alias is a name that represents a specific type, and a function type is a type that represents a function. The typedef keyword allows you to create a type alias for a function type and use it to define variables, parameters, and return types.

In dart language we can see one keyword which " Typedef ", in use of this keyword we can create User defined function .

We can call multiple different type of function with use of the type def function.

There are two types of syntax in User defined function.

Syntax:

//Syntax 1
// Pass the parameter in function
typedef return_type function_name(parameters);

//Syntax 24
//Store the value in variable
typedef variable_name = retuen_type function_name;
typedef exampleOfTypedef(int number);

firstExample (int number)
{
  print("First Value is ${number + 10}");
}

secondExample (int number)
{
  print("Second Value ID is ${number + 10}");
}

void main()
{
  exampleOfTypedef num = firstExample;
  exampleOfTypedef num2 = secondExample;
  num(10);
  num2(20);
}

ย