diff --git a/examples/widgets/big_switch.dart b/examples/widgets/big_switch.dart index 7607633cf7..c335b7705a 100644 --- a/examples/widgets/big_switch.dart +++ b/examples/widgets/big_switch.dart @@ -10,12 +10,10 @@ class BigSwitch extends StatefulComponent { final double scale; - BigSwitchState createState() => new BigSwitchState(this); + BigSwitchState createState() => new BigSwitchState(); } -class BigSwitchState extends ComponentState { - BigSwitchState(BigSwitch config) : super(config); - +class BigSwitchState extends State { bool _value = false; void _handleOnChanged(bool value) { diff --git a/examples/widgets/date_picker.dart b/examples/widgets/date_picker.dart index 75dddb4850..0fec33c9f8 100644 --- a/examples/widgets/date_picker.dart +++ b/examples/widgets/date_picker.dart @@ -8,11 +8,12 @@ import 'package:sky/material.dart'; void main() => runApp(new DatePickerDemo()); class DatePickerDemo extends StatefulComponent { - DatePickerDemoState createState() => new DatePickerDemoState(this); + DatePickerDemoState createState() => new DatePickerDemoState(); } -class DatePickerDemoState extends ComponentState { - DatePickerDemoState(DatePickerDemo config) : super(config) { +class DatePickerDemoState extends State { + void initState(BuildContext context) { + super.initState(context); DateTime now = new DateTime.now(); _dateTime = new DateTime(now.year, now.month, now.day); } diff --git a/examples/widgets/drag_and_drop.dart b/examples/widgets/drag_and_drop.dart index cd32888795..58f6f918c1 100644 --- a/examples/widgets/drag_and_drop.dart +++ b/examples/widgets/drag_and_drop.dart @@ -17,12 +17,10 @@ class DragData { } class ExampleDragTarget extends StatefulComponent { - ExampleDragTargetState createState() => new ExampleDragTargetState(this); + ExampleDragTargetState createState() => new ExampleDragTargetState(); } -class ExampleDragTargetState extends ComponentState { - ExampleDragTargetState(ExampleDragTarget config) : super(config); - +class ExampleDragTargetState extends State { String _text = 'ready'; void _handleAccept(DragData data) { @@ -71,9 +69,7 @@ class DragAndDropApp extends StatefulComponent { DragAndDropAppState createState() => new DragAndDropAppState(this); } -class DragAndDropAppState extends ComponentState { - DragAndDropAppState(DragAndDropApp config) : super(config); - +class DragAndDropAppState extends State { DragController _dragController; Offset _displacement = Offset.zero; diff --git a/examples/widgets/navigation.dart b/examples/widgets/navigation.dart index 4261eff996..d86940cd6b 100644 --- a/examples/widgets/navigation.dart +++ b/examples/widgets/navigation.dart @@ -61,12 +61,10 @@ List routes = [ ]; class NavigationExampleApp extends StatefulComponent { - NavigationExampleAppState createState() => new NavigationExampleAppState(this); + NavigationExampleAppState createState() => new NavigationExampleAppState(); } -class NavigationExampleAppState extends ComponentState { - NavigationExampleAppState(NavigationExampleApp config) : super(config); - +class NavigationExampleAppState extends State { NavigatorHistory _history = new NavigatorHistory(routes); void onBack() { diff --git a/examples/widgets/pageable_list.dart b/examples/widgets/pageable_list.dart index 10e46da544..26f3dc2af2 100644 --- a/examples/widgets/pageable_list.dart +++ b/examples/widgets/pageable_list.dart @@ -20,8 +20,9 @@ class PageableListApp extends StatefulComponent { PageableListAppState createState() => new PageableListAppState(this); } -class PageableListAppState extends ComponentState { - PageableListAppState(PageableListApp config) : super(config) { +class PageableListAppState extends State { + void initState(BuildContext context) { + super.initState(context); List cardSizes = [ [100.0, 300.0], [300.0, 100.0], [200.0, 400.0], [400.0, 400.0], [300.0, 400.0] ] diff --git a/examples/widgets/progress_indicator.dart b/examples/widgets/progress_indicator.dart index 70ff24d926..266ef10855 100644 --- a/examples/widgets/progress_indicator.dart +++ b/examples/widgets/progress_indicator.dart @@ -10,8 +10,9 @@ class ProgressIndicatorApp extends StatefulComponent { ProgressIndicatorAppState createState() => new ProgressIndicatorAppState(this); } -class ProgressIndicatorAppState extends ComponentState { - ProgressIndicatorAppState(ProgressIndicatorApp config) : super(config) { +class ProgressIndicatorAppState extends State { + void initState(BuildContext context) { + super.initState(context); valueAnimation = new ValueAnimation() ..duration = const Duration(milliseconds: 1500) ..variable = new AnimatedValue( diff --git a/examples/widgets/scale.dart b/examples/widgets/scale.dart index 108ffd8d70..3ac60aa442 100644 --- a/examples/widgets/scale.dart +++ b/examples/widgets/scale.dart @@ -10,8 +10,9 @@ class ScaleApp extends StatefulComponent { ScaleAppState createState() => new ScaleAppState(this); } -class ScaleAppState extends ComponentState { - ScaleAppState(ScaleApp config) : super(config) { +class ScaleAppState extends State { + void initState(BuildContext context) { + super.initState(context); _offset = Offset.zero; _zoom = 1.0; } diff --git a/packages/flutter/lib/src/fn3/animated_component.dart b/packages/flutter/lib/src/fn3/animated_component.dart index a1a6f45d28..7ce8bd5740 100644 --- a/packages/flutter/lib/src/fn3/animated_component.dart +++ b/packages/flutter/lib/src/fn3/animated_component.dart @@ -12,8 +12,9 @@ abstract class AnimatedComponent extends StatefulComponent { final Direction direction; } -abstract class AnimatedComponentState extends ComponentState { - AnimatedComponentState(T config) : super(config) { +abstract class AnimatedState extends State { + void initState(BuildContext context) { + super.initState(context); _performance = new AnimationPerformance(duration: config.duration); performance.addStatusListener(_handleAnimationStatusChanged); if (buildDependsOnPerformance) { diff --git a/packages/flutter/lib/src/fn3/basic.dart b/packages/flutter/lib/src/fn3/basic.dart index f775853238..8a269c16be 100644 --- a/packages/flutter/lib/src/fn3/basic.dart +++ b/packages/flutter/lib/src/fn3/basic.dart @@ -724,11 +724,12 @@ class ImageListener extends StatefulComponent { final ImageFit fit; final ImageRepeat repeat; - ImageListenerState createState() => new ImageListenerState(this); + ImageListenerState createState() => new ImageListenerState(); } -class ImageListenerState extends ComponentState { - ImageListenerState(ImageListener config) : super(config) { +class ImageListenerState extends State { + void initState(BuildContext context) { + super.initState(context); config.image.addListener(_handleImageChanged); } @@ -742,6 +743,7 @@ class ImageListenerState extends ComponentState { void dispose() { config.image.removeListener(_handleImageChanged); + super.dispose(); } void didUpdateConfig(ImageListener oldConfig) { diff --git a/packages/flutter/lib/src/fn3/button_state.dart b/packages/flutter/lib/src/fn3/button_state.dart index 5612c85209..f821be62a2 100644 --- a/packages/flutter/lib/src/fn3/button_state.dart +++ b/packages/flutter/lib/src/fn3/button_state.dart @@ -5,9 +5,7 @@ import 'package:sky/src/fn3/basic.dart'; import 'package:sky/src/fn3/framework.dart'; -abstract class ButtonState extends ComponentState { - ButtonState(T config) : super(config); - +abstract class ButtonState extends State { bool highlight = false; void _handlePointerDown(_) { diff --git a/packages/flutter/lib/src/fn3/date_picker.dart b/packages/flutter/lib/src/fn3/date_picker.dart index ad09c13c65..ba828370c8 100644 --- a/packages/flutter/lib/src/fn3/date_picker.dart +++ b/packages/flutter/lib/src/fn3/date_picker.dart @@ -39,12 +39,10 @@ class DatePicker extends StatefulComponent { final DateTime firstDate; final DateTime lastDate; - DatePickerState createState() => new DatePickerState(this); + DatePickerState createState() => new DatePickerState(); } -class DatePickerState extends ComponentState { - DatePickerState(DatePicker config) : super(config); - +class DatePickerState extends State { DatePickerMode _mode = DatePickerMode.day; void _handleModeChanged(DatePickerMode mode) { @@ -292,11 +290,12 @@ class MonthPicker extends ScrollableWidgetList { final DateTime firstDate; final DateTime lastDate; - MonthPickerState createState() => new MonthPickerState(this); + MonthPickerState createState() => new MonthPickerState(); } class MonthPickerState extends ScrollableWidgetListState { - MonthPickerState(MonthPicker config) : super(config) { + void initState(BuildContext context) { + super.initState(context); _updateCurrentDate(); } @@ -342,6 +341,7 @@ class MonthPickerState extends ScrollableWidgetListState { void dispose() { if (_timer != null) _timer.cancel(); + super.dispose(); } } @@ -363,12 +363,10 @@ class YearPicker extends ScrollableWidgetList { final DateTime firstDate; final DateTime lastDate; - YearPickerState createState() => new YearPickerState(this); + YearPickerState createState() => new YearPickerState(); } class YearPickerState extends ScrollableWidgetListState { - YearPickerState(YearPicker config) : super(config); - int get itemCount => config.lastDate.year - config.firstDate.year + 1; List buildItems(BuildContext context, int start, int count) { diff --git a/packages/flutter/lib/src/fn3/dismissable.dart b/packages/flutter/lib/src/fn3/dismissable.dart index 3745faf7e8..7767504f5d 100644 --- a/packages/flutter/lib/src/fn3/dismissable.dart +++ b/packages/flutter/lib/src/fn3/dismissable.dart @@ -44,11 +44,12 @@ class Dismissable extends StatefulComponent { DismissedCallback onDismissed; DismissDirection direction; - DismissableState createState() => new DismissableState(this); + DismissableState createState() => new DismissableState(); } -class DismissableState extends ComponentState { - DismissableState(Dismissable config) : super(config) { +class DismissableState extends State { + void initState(BuildContext context) { + super.initState(context); _fadePerformance = new AnimationPerformance(duration: _kCardDismissFadeout); _fadePerformance.addStatusListener((AnimationStatus status) { if (status == AnimationStatus.completed) diff --git a/packages/flutter/lib/src/fn3/drag_target.dart b/packages/flutter/lib/src/fn3/drag_target.dart index ccfd457c46..1b15baab32 100644 --- a/packages/flutter/lib/src/fn3/drag_target.dart +++ b/packages/flutter/lib/src/fn3/drag_target.dart @@ -25,12 +25,10 @@ class DragTarget extends StatefulComponent { final DragTargetWillAccept onWillAccept; final DragTargetAccept onAccept; - DragTargetState createState() => new DragTargetState(this); + DragTargetState createState() => new DragTargetState(); } -class DragTargetState extends ComponentState> { - DragTargetState(DragTarget config) : super(config); - +class DragTargetState extends State> { final List _candidateData = new List(); final List _rejectedData = new List(); diff --git a/packages/flutter/lib/src/fn3/drawer.dart b/packages/flutter/lib/src/fn3/drawer.dart index 4172941cde..4b2eceb912 100644 --- a/packages/flutter/lib/src/fn3/drawer.dart +++ b/packages/flutter/lib/src/fn3/drawer.dart @@ -53,11 +53,12 @@ class Drawer extends StatefulComponent { final DrawerDismissedCallback onDismissed; final NavigatorState navigator; - DrawerState createState() => new DrawerState(this); + DrawerState createState() => new DrawerState(); } -class DrawerState extends ComponentState { - DrawerState(Drawer config) : super(config) { +class DrawerState extends State { + void initState(BuildContext context) { + super.initState(context); _performance = new AnimationPerformance(duration: _kBaseSettleDuration); _performance.addStatusListener((AnimationStatus status) { if (status == AnimationStatus.dismissed) diff --git a/packages/flutter/lib/src/fn3/drawer_item.dart b/packages/flutter/lib/src/fn3/drawer_item.dart index 24d33e73d8..fe8a87e14e 100644 --- a/packages/flutter/lib/src/fn3/drawer_item.dart +++ b/packages/flutter/lib/src/fn3/drawer_item.dart @@ -24,12 +24,10 @@ class DrawerItem extends StatefulComponent { final GestureTapListener onPressed; final bool selected; - DrawerItemState createState() => new DrawerItemState(this); + DrawerItemState createState() => new DrawerItemState(); } class DrawerItemState extends ButtonState { - DrawerItemState(DrawerItem config) : super(config); - TextStyle _getTextStyle(ThemeData themeData) { TextStyle result = themeData.text.body2; if (config.selected) diff --git a/packages/flutter/lib/src/fn3/flat_button.dart b/packages/flutter/lib/src/fn3/flat_button.dart index 7ddc848cf9..353ebb47b8 100644 --- a/packages/flutter/lib/src/fn3/flat_button.dart +++ b/packages/flutter/lib/src/fn3/flat_button.dart @@ -19,12 +19,10 @@ class FlatButton extends MaterialButton { enabled: enabled, onPressed: onPressed); - FlatButtonState createState() => new FlatButtonState(this); + FlatButtonState createState() => new FlatButtonState(); } class FlatButtonState extends MaterialButtonState { - FlatButtonState(FlatButton config) : super(config); - Color getColor(BuildContext context) { if (!config.enabled || !highlight) return null; diff --git a/packages/flutter/lib/src/fn3/floating_action_button.dart b/packages/flutter/lib/src/fn3/floating_action_button.dart index f8d58cc0e1..f7ba07430f 100644 --- a/packages/flutter/lib/src/fn3/floating_action_button.dart +++ b/packages/flutter/lib/src/fn3/floating_action_button.dart @@ -28,12 +28,10 @@ class FloatingActionButton extends StatefulComponent { final Color backgroundColor; final GestureTapListener onPressed; - FloatingActionButtonState createState() => new FloatingActionButtonState(this); + FloatingActionButtonState createState() => new FloatingActionButtonState(); } class FloatingActionButtonState extends ButtonState { - FloatingActionButtonState(FloatingActionButton config) : super(config); - Widget buildContent(BuildContext context) { IconThemeColor iconThemeColor = IconThemeColor.white; Color materialColor = config.backgroundColor; diff --git a/packages/flutter/lib/src/fn3/focus.dart b/packages/flutter/lib/src/fn3/focus.dart index a8a488313d..d62cdef0bb 100644 --- a/packages/flutter/lib/src/fn3/focus.dart +++ b/packages/flutter/lib/src/fn3/focus.dart @@ -75,12 +75,10 @@ class Focus extends StatefulComponent { final bool autofocus; final Widget child; - FocusState createState() => new FocusState(this); + FocusState createState() => new FocusState(); } -class FocusState extends ComponentState { - FocusState(Focus config) : super(config); - +class FocusState extends State { GlobalKey _focusedWidget; // when null, the first component to ask if it's focused will get the focus GlobalKey _currentlyRegisteredWidgetRemovalListenerKey; @@ -164,6 +162,7 @@ class FocusState extends ComponentState { void dispose() { _updateWidgetRemovalListener(null); _updateScopeRemovalListener(null); + super.dispose(); } Widget build(BuildContext context) { diff --git a/packages/flutter/lib/src/fn3/framework.dart b/packages/flutter/lib/src/fn3/framework.dart index 9d785e6608..3cf2564fba 100644 --- a/packages/flutter/lib/src/fn3/framework.dart +++ b/packages/flutter/lib/src/fn3/framework.dart @@ -289,8 +289,8 @@ abstract class StatelessComponent extends Widget { } /// StatefulComponents provide the configuration for -/// [StatefulComponentElement]s, which wrap [ComponentState]s, which hold -/// mutable state and can dynamically and spontaneously ask to be rebuilt. +/// [StatefulComponentElement]s, which wrap [State]s, which hold mutable state +/// and can dynamically and spontaneously ask to be rebuilt. abstract class StatefulComponent extends Widget { const StatefulComponent({ Key key }) : super(key: key); @@ -300,49 +300,71 @@ abstract class StatefulComponent extends Widget { /// Returns an instance of the state to which this StatefulComponent is /// related, using this object as the configuration. Subclasses should - /// override this to return a new instance of the ComponentState class - /// associated with this StatefulComponent class, like this: + /// override this to return a new instance of the State class associated with + /// this StatefulComponent class, like this: /// - /// MyComponentState createState() => new MyComponentState(this); - ComponentState createState(); + /// MyState createState() => new MyState(this); + State createState(); +} + +enum _StateLifecycle { + created, + initialized, + ready, + defunct, } /// The logic and internal state for a StatefulComponent. -abstract class ComponentState { - ComponentState(this._config); - - StatefulComponentElement _element; - - /// Whenever you need to change internal state for a ComponentState object, - /// make the change in a function that you pass to setState(), as in: - /// - /// setState(() { myState = newValue }); - /// - /// If you just change the state directly without calling setState(), then - /// the component will not be scheduled for rebuilding, meaning that its - /// rendering will not be updated. - void setState(void fn()) { - fn(); - _element.markNeedsBuild(); - } - +abstract class State { /// The current configuration (an instance of the corresponding /// StatefulComponent class). T get config => _config; T _config; + /// This is used to verify that State objects move through life in an orderly fashion. + _StateLifecycle _debugLifecycleState = _StateLifecycle.created; + + /// Pointer to the owner Element object + StatefulComponentElement _element; + + /// Called when this object is inserted into the tree. Override this function + /// to perform initialization that depends on the location at which this + /// object was inserted into the tree or on the widget configuration object. + /// + /// If you override this, make sure your method starts with a call to + /// super.initState(context). + void initState(BuildContext context) { + assert(_debugLifecycleState == _StateLifecycle.created); + assert(() { _debugLifecycleState = _StateLifecycle.initialized; return true; }); + } + /// Called whenever the configuration changes. Override this method to update /// additional state when the config field's value is changed. void didUpdateConfig(T oldConfig) { } - /// Called when this object is inserted into the tree. Override this function - /// to perform initialization that depends on the location at which this - /// object was inserted into the tree. - void initState(BuildContext context) { } + /// Whenever you need to change internal state for a State object, make the + /// change in a function that you pass to setState(), as in: + /// + /// setState(() { myState = newValue }); + /// + /// If you just change the state directly without calling setState(), then the + /// component will not be scheduled for rebuilding, meaning that its rendering + /// will not be updated. + void setState(void fn()) { + assert(_debugLifecycleState == _StateLifecycle.ready); + fn(); + _element.markNeedsBuild(); + } /// Called when this object is removed from the tree. Override this to clean /// up any resources allocated by this object. - void dispose() { } + /// + /// If you override this, make sure to end your method with a call to + /// super.dispose(). + void dispose() { + assert(_debugLifecycleState == _StateLifecycle.ready); + assert(() { _debugLifecycleState = _StateLifecycle.defunct; return true; }); + } /// Returns another Widget out of which this StatefulComponent is built. /// Typically that Widget will have been configured with further children, @@ -634,8 +656,8 @@ abstract class BuildableElement extends Element { } /// Reinvokes the build() method of the StatelessComponent object (for - /// stateless components) or the ComponentState object (for stateful - /// components) and then updates the widget tree. + /// stateless components) or the State object (for stateful components) and + /// then updates the widget tree. /// /// Called automatically during mount() to generate the first build, by the /// binding when scheduleBuild() has been called to mark this element dirty, @@ -670,8 +692,8 @@ abstract class BuildableElement extends Element { static bool get _debugStateLocked => _debugStateLockLevel > 0; /// Calls the callback argument synchronously, but in a context where calls to - /// ComponentState.setState() will fail. Use this when it is possible that you - /// will trigger code in components but want to make sure that there is no + /// State.setState() will fail. Use this when it is possible that you will + /// trigger code in components but want to make sure that there is no /// possibility that any components will be marked dirty, for example because /// you are in the middle of layout and you are not going to be flushing the /// build queue (since that could mutate the layout tree). @@ -735,14 +757,19 @@ class StatelessComponentElement extends BuildableE class StatefulComponentElement extends BuildableElement { StatefulComponentElement(StatefulComponent widget) : _state = widget.createState(), super(widget) { - assert(_state._config == widget); assert(_state._element == null); _state._element = this; + assert(_state._config == null); + _state._config = widget; + assert(_state._debugLifecycleState == _StateLifecycle.created); + _state.initState(this); + assert(_state._debugLifecycleState == _StateLifecycle.initialized); + assert(() { _state._debugLifecycleState = _StateLifecycle.ready; return true; }); _builder = _state.build; } - ComponentState get state => _state; - ComponentState _state; + State get state => _state; + State _state; void update(StatefulComponent newWidget) { super.update(newWidget); @@ -757,6 +784,7 @@ class StatefulComponentElement extends BuildableElement { void unmount() { super.unmount(); _state.dispose(); + assert(_state._debugLifecycleState == _StateLifecycle.defunct); _state._element = null; _state = null; } diff --git a/packages/flutter/lib/src/fn3/gesture_detector.dart b/packages/flutter/lib/src/fn3/gesture_detector.dart index 36a6b3619e..0544602eaa 100644 --- a/packages/flutter/lib/src/fn3/gesture_detector.dart +++ b/packages/flutter/lib/src/fn3/gesture_detector.dart @@ -51,11 +51,12 @@ class GestureDetector extends StatefulComponent { final GestureScaleUpdateCallback onScaleUpdate; final GestureScaleEndCallback onScaleEnd; - GestureDetectorState createState() => new GestureDetectorState(this); + GestureDetectorState createState() => new GestureDetectorState(); } -class GestureDetectorState extends ComponentState { - GestureDetectorState(GestureDetector config) : super(config) { +class GestureDetectorState extends State { + void initState(BuildContext context) { + super.initState(context); didUpdateConfig(null); } @@ -120,6 +121,7 @@ class GestureDetectorState extends ComponentState { _horizontalDrag = _ensureDisposed(_horizontalDrag); _pan = _ensureDisposed(_pan); _scale = _ensureDisposed(_scale); + super.dispose(); } void didUpdateConfig(GestureDetector oldConfig) { diff --git a/packages/flutter/lib/src/fn3/homogeneous_viewport.dart b/packages/flutter/lib/src/fn3/homogeneous_viewport.dart index f661e34ae0..16d4e9930e 100644 --- a/packages/flutter/lib/src/fn3/homogeneous_viewport.dart +++ b/packages/flutter/lib/src/fn3/homogeneous_viewport.dart @@ -52,7 +52,6 @@ class HomogeneousViewportElement extends RenderObjectElement _children = const []; - bool _layoutDirty = true; int _layoutFirstIndex; int _layoutItemCount; diff --git a/packages/flutter/lib/src/fn3/material_button.dart b/packages/flutter/lib/src/fn3/material_button.dart index fb299b33ab..c2a647ba08 100644 --- a/packages/flutter/lib/src/fn3/material_button.dart +++ b/packages/flutter/lib/src/fn3/material_button.dart @@ -26,8 +26,6 @@ abstract class MaterialButton extends StatefulComponent { } abstract class MaterialButtonState extends ButtonState { - MaterialButtonState(T config) : super(config); - Color getColor(BuildContext context); int get level; diff --git a/packages/flutter/lib/src/fn3/mixed_viewport.dart b/packages/flutter/lib/src/fn3/mixed_viewport.dart index 59f4505f6c..b03385a50f 100644 --- a/packages/flutter/lib/src/fn3/mixed_viewport.dart +++ b/packages/flutter/lib/src/fn3/mixed_viewport.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:collection'; - import 'package:sky/rendering.dart'; import 'package:sky/src/fn3/framework.dart'; import 'package:sky/src/fn3/basic.dart'; @@ -63,9 +61,9 @@ class _ChildKey { } class MixedViewportElement extends RenderObjectElement { - MixedViewportElement(MixedViewport config) : super(config) { - if (config.onInvalidatorAvailable != null) - config.onInvalidatorAvailable(invalidate); + MixedViewportElement(MixedViewport widget) : super(widget) { + if (widget.onInvalidatorAvailable != null) + widget.onInvalidatorAvailable(invalidate); } /// _childOffsets contains the offsets of each child from the top of the list @@ -269,9 +267,13 @@ class MixedViewportElement extends RenderObjectElement { double _getOffset(Element element, BoxConstraints innerConstraints) { final RenderBox childRenderObject = element.renderObject; switch (widget.direction) { - case ScrollDirection.vertical: return childRenderObject.getMaxIntrinsicHeight(innerConstraints); - case ScrollDirection.horizontal: return childRenderObject.getMaxIntrinsicWidth(innerConstraints); - case ScrollDirection.both: assert(false); // we don't support ScrollDirection.both, see issue 888 + case ScrollDirection.vertical: + return childRenderObject.getMaxIntrinsicHeight(innerConstraints); + case ScrollDirection.horizontal: + return childRenderObject.getMaxIntrinsicWidth(innerConstraints); + case ScrollDirection.both: + assert(false); // we don't support ScrollDirection.both, see issue 888 + return double.NAN; } } diff --git a/packages/flutter/lib/src/fn3/navigator.dart b/packages/flutter/lib/src/fn3/navigator.dart index c7c6ebc45b..834e0da0da 100644 --- a/packages/flutter/lib/src/fn3/navigator.dart +++ b/packages/flutter/lib/src/fn3/navigator.dart @@ -90,7 +90,7 @@ class RouteState extends RouteBase { Function callback; RouteBase route; - ComponentState owner; + State owner; bool get isOpaque => false; @@ -152,15 +152,13 @@ class Navigator extends StatefulComponent { final NavigatorHistory history; - NavigatorState createState() => new NavigatorState(this); + NavigatorState createState() => new NavigatorState(); } -class NavigatorState extends ComponentState { - NavigatorState(Navigator config) : super(config); - +class NavigatorState extends State { RouteBase get currentRoute => config.history.currentRoute; - void pushState(ComponentState owner, Function callback) { + void pushState(State owner, Function callback) { RouteBase route = new RouteState( owner: owner, callback: callback, diff --git a/packages/flutter/lib/src/fn3/popup_menu.dart b/packages/flutter/lib/src/fn3/popup_menu.dart index 509d3ac245..c34d9b2134 100644 --- a/packages/flutter/lib/src/fn3/popup_menu.dart +++ b/packages/flutter/lib/src/fn3/popup_menu.dart @@ -43,11 +43,12 @@ class PopupMenu extends StatefulComponent { final NavigatorState navigator; final WatchableAnimationPerformance performance; - PopupMenuState createState() => new PopupMenuState(this); + PopupMenuState createState() => new PopupMenuState(); } -class PopupMenuState extends ComponentState { - PopupMenuState(PopupMenu config) : super(config) { +class PopupMenuState extends State { + void initState(BuildContext context) { + super.initState(context); _updateBoxPainter(); config.performance.addListener(_performanceChanged); } @@ -75,6 +76,7 @@ class PopupMenuState extends ComponentState { void dispose() { config.performance.removeListener(_performanceChanged); + super.dispose(); } void _performanceChanged() { diff --git a/packages/flutter/lib/src/fn3/progress_indicator.dart b/packages/flutter/lib/src/fn3/progress_indicator.dart index f77d31e5fc..99c1663024 100644 --- a/packages/flutter/lib/src/fn3/progress_indicator.dart +++ b/packages/flutter/lib/src/fn3/progress_indicator.dart @@ -31,11 +31,12 @@ abstract class ProgressIndicator extends StatefulComponent { Widget _buildIndicator(BuildContext context, double performanceValue); - ProgressIndicatorState createState() => new ProgressIndicatorState(this); + ProgressIndicatorState createState() => new ProgressIndicatorState(); } -class ProgressIndicatorState extends ComponentState { - ProgressIndicatorState(ProgressIndicator config) : super(config) { +class ProgressIndicatorState extends State { + void initState(BuildContext context) { + super.initState(context); _performance = new AnimationPerformance() ..duration = const Duration(milliseconds: 1500) ..variable = new AnimatedValue(0.0, end: 1.0, curve: ease); @@ -44,7 +45,6 @@ class ProgressIndicatorState extends ComponentState { _restartAnimation(); }); _performance.play(); - } AnimationPerformance _performance; diff --git a/packages/flutter/lib/src/fn3/radio.dart b/packages/flutter/lib/src/fn3/radio.dart index 2e5ed26f3d..76493c1b32 100644 --- a/packages/flutter/lib/src/fn3/radio.dart +++ b/packages/flutter/lib/src/fn3/radio.dart @@ -28,12 +28,10 @@ class Radio extends StatefulComponent { final Object groupValue; final RadioValueChanged onChanged; - RadioState createState() => new RadioState(this); + RadioState createState() => new RadioState(); } -class RadioState extends ComponentState { - RadioState(Radio config) : super(config); - +class RadioState extends State { Color _getColor(BuildContext context) { ThemeData themeData = Theme.of(context); if (config.value == config.groupValue) diff --git a/packages/flutter/lib/src/fn3/raised_button.dart b/packages/flutter/lib/src/fn3/raised_button.dart index b134c62d3a..99fe4f2900 100644 --- a/packages/flutter/lib/src/fn3/raised_button.dart +++ b/packages/flutter/lib/src/fn3/raised_button.dart @@ -21,12 +21,10 @@ class RaisedButton extends MaterialButton { assert(enabled != null); } - RaisedButtonState createState() => new RaisedButtonState(this); + RaisedButtonState createState() => new RaisedButtonState(); } class RaisedButtonState extends MaterialButtonState { - RaisedButtonState(RaisedButton config) : super(config); - Color getColor(BuildContext context) { if (config.enabled) { switch (Theme.of(context).brightness) { diff --git a/packages/flutter/lib/src/fn3/scrollable.dart b/packages/flutter/lib/src/fn3/scrollable.dart index 80a4db68bb..ae415533ad 100644 --- a/packages/flutter/lib/src/fn3/scrollable.dart +++ b/packages/flutter/lib/src/fn3/scrollable.dart @@ -9,8 +9,7 @@ import 'dart:sky' as sky; import 'package:newton/newton.dart'; import 'package:sky/animation.dart'; import 'package:sky/gestures.dart'; -import 'package:sky/src/rendering/box.dart'; -import 'package:sky/src/rendering/viewport.dart'; +import 'package:sky/rendering.dart'; import 'package:sky/src/fn3/basic.dart'; import 'package:sky/src/fn3/framework.dart'; import 'package:sky/src/fn3/gesture_detector.dart'; @@ -39,8 +38,9 @@ abstract class Scrollable extends StatefulComponent { final ScrollDirection scrollDirection; } -abstract class ScrollableState extends ComponentState { - ScrollableState(T config) : super(config) { +abstract class ScrollableState extends State { + void initState(BuildContext context) { + super.initState(context); if (config.initialScrollOffset is double) _scrollOffset = config.initialScrollOffset; _toEndAnimation = new AnimatedSimulation(_setScrollOffset); @@ -126,6 +126,7 @@ abstract class ScrollableState extends ComponentState { void dispose() { _stopAnimations(); + super.dispose(); } void _setScrollOffset(double newScrollOffset) { @@ -220,12 +221,10 @@ class ScrollableViewport extends Scrollable { final Widget child; - ScrollableViewportState createState() => new ScrollableViewportState(this); + ScrollableViewportState createState() => new ScrollableViewportState(); } class ScrollableViewportState extends ScrollableState { - ScrollableViewportState(ScrollableViewport config) : super(config); - ScrollBehavior createScrollBehavior() => new OverscrollWhenScrollableBehavior(); OverscrollWhenScrollableBehavior get scrollBehavior => super.scrollBehavior; @@ -320,8 +319,6 @@ abstract class ScrollableWidgetList extends Scrollable { } abstract class ScrollableWidgetListState extends ScrollableState { - ScrollableWidgetListState(T config) : super(config); - /// Subclasses must implement `get itemCount` to tell ScrollableWidgetList /// how many items there are in the list. int get itemCount; @@ -458,12 +455,10 @@ class ScrollableList extends ScrollableWidgetList { final List items; final ItemBuilder itemBuilder; - ScrollableListState> createState() => new ScrollableListState>(this); + ScrollableListState> createState() => new ScrollableListState>(); } class ScrollableListState> extends ScrollableWidgetListState { - ScrollableListState(Config config) : super(config); - ScrollBehavior createScrollBehavior() { return config.itemsWrap ? new UnboundedBehavior() : super.createScrollBehavior(); } @@ -512,8 +507,6 @@ class PageableList extends ScrollableList { } class PageableListState extends ScrollableListState> { - PageableListState(PageableList config) : super(config); - double _snapScrollOffset(double newScrollOffset) { double scaledScrollOffset = newScrollOffset / config.itemExtent; double previousScrollOffset = scaledScrollOffset.floor() * config.itemExtent; diff --git a/packages/flutter/lib/src/fn3/snack_bar.dart b/packages/flutter/lib/src/fn3/snack_bar.dart index 450a82470e..2c745b3aa6 100644 --- a/packages/flutter/lib/src/fn3/snack_bar.dart +++ b/packages/flutter/lib/src/fn3/snack_bar.dart @@ -56,12 +56,10 @@ class SnackBar extends AnimatedComponent { final List actions; final SnackBarDismissedCallback onDismissed; - SnackBarState createState() => new SnackBarState(this); + SnackBarState createState() => new SnackBarState(); } -class SnackBarState extends AnimatedComponentState { - SnackBarState(SnackBar config) : super(config); - +class SnackBarState extends AnimatedState { void handleDismissed() { if (config.onDismissed != null) config.onDismissed(); diff --git a/packages/flutter/lib/src/fn3/tabs.dart b/packages/flutter/lib/src/fn3/tabs.dart index b2c25ebe29..2739ec6aad 100644 --- a/packages/flutter/lib/src/fn3/tabs.dart +++ b/packages/flutter/lib/src/fn3/tabs.dart @@ -397,11 +397,12 @@ class TabBar extends Scrollable { final SelectedIndexChanged onChanged; final bool isScrollable; - TabBarState createState() => new TabBarState(this); + TabBarState createState() => new TabBarState(); } class TabBarState extends ScrollableState { - TabBarState(TabBar config) : super(config) { + void initState(BuildContext context) { + super.initState(context); _indicatorAnimation = new ValueAnimation() ..duration = _kTabBarScroll ..variable = new AnimatedRect(null, curve: ease); diff --git a/packages/flutter/lib/src/fn3/transitions.dart b/packages/flutter/lib/src/fn3/transitions.dart index aaee5ef9af..970f046813 100644 --- a/packages/flutter/lib/src/fn3/transitions.dart +++ b/packages/flutter/lib/src/fn3/transitions.dart @@ -23,11 +23,12 @@ abstract class TransitionComponent extends StatefulComponent { Widget build(BuildContext context); - TransitionComponentState createState() => new TransitionComponentState(this); + TransitionState createState() => new TransitionState(); } -class TransitionComponentState extends ComponentState { - TransitionComponentState(TransitionComponent config) : super(config) { +class TransitionState extends State { + void initState(BuildContext context) { + super.initState(context); config.performance.addListener(_performanceChanged); } @@ -40,6 +41,7 @@ class TransitionComponentState extends ComponentState { void dispose() { config.performance.removeListener(_performanceChanged); + super.dispose(); } void _performanceChanged() { diff --git a/packages/unit/test/fn3/test_widgets.dart b/packages/unit/test/fn3/test_widgets.dart index 479360cbef..9133ca8d9b 100644 --- a/packages/unit/test/fn3/test_widgets.dart +++ b/packages/unit/test/fn3/test_widgets.dart @@ -21,11 +21,10 @@ class FlipComponent extends StatefulComponent { final Widget left; final Widget right; - FlipComponentState createState() => new FlipComponentState(this); + FlipComponentState createState() => new FlipComponentState(); } -class FlipComponentState extends ComponentState { - FlipComponentState(FlipComponent config): super(config); +class FlipComponentState extends State { bool _showLeft = true; void flip() { diff --git a/packages/unit/test/fn3/widget_tester.dart b/packages/unit/test/fn3/widget_tester.dart index abc1060eb3..85e323de48 100644 --- a/packages/unit/test/fn3/widget_tester.dart +++ b/packages/unit/test/fn3/widget_tester.dart @@ -9,8 +9,7 @@ class RootComponent extends StatefulComponent { RootComponentState createState() => new RootComponentState(this); } -class RootComponentState extends ComponentState { - RootComponentState(RootComponent widget) : super(widget); +class RootComponentState extends State { Widget _child = new DecoratedBox(decoration: new BoxDecoration()); Widget get child => _child; void set child(Widget value) {