Last active
June 6, 2018 05:08
-
-
Save yjbanov/9a3f1bf6dd45b18d82a0b75ef294ca1b to your computer and use it in GitHub Desktop.
A Darty widget declaration syntax
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
// Stateless widget: | |
// | |
// - no `extends StatelessWidget` | |
// - fields are `final` by default | |
// - `@override`, `Widget` return type and `BuildContext context` parameter are implied | |
widget MyApp { | |
String title; | |
build { | |
} | |
} | |
// Stateful widget: | |
// | |
// - same as a stateless widget, but with a nested `state` block | |
// - fields outside the `state` block are `final` | |
// - fields inside the `state` block are mutable | |
// - ideally one wouldn't need to call `setState`; instead any assignment | |
// to one of the `state` fields automatically results in state change | |
widget MyApp { | |
String title; | |
state { | |
String counter; | |
} | |
build { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two important properties of this syntax are:
state
block.