xxxxxxxxxx
/*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.
*/
/*The typedef keyword simply gives another name to a function type so that it can be easily
reused. */
///-----------------------------------------------------------
typedef LoggerFunction = void Function(String msg);
void printIntegers(LoggerFunction logger) {
logger("Done int.");
}
void printDoubles(LoggerFunction logger) {
logger("Done double.");
}
xxxxxxxxxx
typedef ManyOperation(int firstNo, int secondNo); // function signature to match
Subtract(int firstNo, int second){
print("Subtract result is ${firstNo-second}");
}
Calculator(int a, int b, ManyOperation oper){ // matches function signature
oper(a,b);
}
main(){
Calculator(5, 5, Subtract); // 'Subtract result is 0'
}
xxxxxxxxxx
//Return type not part of typedef
typedef function_name(parameters)