Skip to content

Instantly share code, notes, and snippets.

@rahul-lohra
Created May 25, 2019 20:10
Show Gist options
  • Save rahul-lohra/6f3561221564a346d060d58aabe8b659 to your computer and use it in GitHub Desktop.
Save rahul-lohra/6f3561221564a346d060d58aabe8b659 to your computer and use it in GitHub Desktop.
Dart callback
main(List<String> args) {
Button btn = new Button();
btn.setCallback((a){
print(a);
});
for(int i=0;i<4;++i){
btn.tap();
}
}
class Button {
int _count = 0;
Function(int) f;
void tap(){
++_count;
if(f!=null && (_count%2) == 0){
f(_count);
}
}
int getCount(){
return _count;
}
void setCallback(Function(int) f){
this.f = f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment