Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: sky/sdk/lib/widgets/widget.dart

Issue 1233703003: add initState, rename animated_container (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: remove print statement Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« sky/sdk/lib/widgets/material.dart ('K') | « sky/sdk/lib/widgets/scrollable.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/widget.dart
diff --git a/sky/sdk/lib/widgets/widget.dart b/sky/sdk/lib/widgets/widget.dart
index b099a3a98df227e31c9001cb19afdf107a47fb14..4626da58e255a67887eeef512534cae7e2c828fb 100644
--- a/sky/sdk/lib/widgets/widget.dart
+++ b/sky/sdk/lib/widgets/widget.dart
@@ -521,6 +521,7 @@ abstract class StatefulComponent extends Component {
StatefulComponent({ String key }) : super(key: key);
bool _disqualifiedFromEverAppearingAgain = false;
+ bool _isStateInitialized = false;
void didMount() {
assert(!_disqualifiedFromEverAppearingAgain);
@@ -534,6 +535,11 @@ abstract class StatefulComponent extends Component {
void _sync(Widget old, dynamic slot) {
assert(!_disqualifiedFromEverAppearingAgain);
+ // TODO(ianh): _sync should only be called once when old == null
+ if (old == null && !_isStateInitialized) {
+ initState();
+ _isStateInitialized = true;
+ }
super._sync(old, slot);
}
@@ -567,6 +573,11 @@ abstract class StatefulComponent extends Component {
// extending StatefulComponent directly.
void syncFields(Component source);
+ // Stateful components can override initState if they want
+ // to do non-trivial work to initialize state. This is
+ // always called before build().
+ void initState() { }
+
void setState(Function fn()) {
assert(!_disqualifiedFromEverAppearingAgain);
fn();
« sky/sdk/lib/widgets/material.dart ('K') | « sky/sdk/lib/widgets/scrollable.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698