Skip to content

Instantly share code, notes, and snippets.

@savioserra
Last active August 28, 2019 13:54
Show Gist options
  • Save savioserra/0def9d998169d0399371812e6e9bf2db to your computer and use it in GitHub Desktop.
Save savioserra/0def9d998169d0399371812e6e9bf2db to your computer and use it in GitHub Desktop.
// 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