Last active
August 28, 2019 13:54
-
-
Save savioserra/0def9d998169d0399371812e6e9bf2db to your computer and use it in GitHub Desktop.
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
// generic callbacks in dart sdk would be very helpfull | |
// otherwise we should typedef those for every project | |
// (or maybe i should create a package with this :thinking:) | |
typedef void IntCallback(int foo); | |
class AnAwesomeWidget { | |
// user can take some action. eg. when switching pages in a PageView | |
final IntCallback somethingHappened; | |
int someState = 0; | |
AnAwesomeWidget({this.somethingHappened}) { | |
// just some async stuff | |
Future.doWhile(() async { | |
await Future.delayed(Duration(seconds: 1), () => somethingHappened(someState)); | |
someState++; | |
return someState < 5; | |
}); | |
} | |
// ...build | |
} | |
void main() { | |
var widget = AnAwesomeWidget(somethingHappened: print); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment