Skip to content

Instantly share code, notes, and snippets.

@nikli2009
Created July 7, 2019 13:15
Show Gist options
  • Save nikli2009/f5106c83feef317778d76f3ed6bc8834 to your computer and use it in GitHub Desktop.
Save nikli2009/f5106c83feef317778d76f3ed6bc8834 to your computer and use it in GitHub Desktop.
Dart Function as Parameter
void main() {
print(' '.padLeft(10,'-') + 'Function as Parameter' + ' '.padRight(10,'-'));
Person newUser = Person(talk: trashTalk);
newUser.talk(); // Try dunk it!
newUser.talk = friendlyTalk;
newUser.talk(); // You can do it.
// useful when refactor one giant component into couple of reusable components.
// pass Functions as EventListener to child Widget.
}
class Person {
Function talk;
Person({this.talk});
}
void trashTalk() {
print('Try dunk it!');
}
void friendlyTalk() {
print('You can do it.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment