typedef

 /// typedef

/// Syntax 1 : typedef return_type function_name(parameters);
/// Syntax 2 : typedef variable_name = return_type function_name;

// 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);
//
// x = Second;
// x(5);
// }

void main() {
PerformOperation performOperation;
performOperation = sumOfNumber;

print(performOperation(n1: 2, n2: 5,),);

performOperation = subOfNumber;

print(performOperation(n1: 2, n2: 5,),);
}
/// typedef function_name(var args)
typedef PerformOperation({required int n1, required int n2});

double sumOfNumber({required int n1, required int n2}) {
int sum = n1 + n2;
return sum.toDouble();
}

double subOfNumber({required int n1, required int n2}) {
int sub = n1 - n2;
return sub.toDouble();
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter