Created
July 7, 2019 13:15
-
-
Save nikli2009/f5106c83feef317778d76f3ed6bc8834 to your computer and use it in GitHub Desktop.
Dart Function as Parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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