Created
May 25, 2019 20:10
-
-
Save rahul-lohra/6f3561221564a346d060d58aabe8b659 to your computer and use it in GitHub Desktop.
Dart callback
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
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