| 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();
|
|
|