Rename ComponentState and use initState().
ComponentState becomes State, for brevity. Instead of overriding its constructor, override initState(). This makes writing States much simpler.
This commit is contained in:
@@ -10,12 +10,10 @@ class BigSwitch extends StatefulComponent {
|
||||
|
||||
final double scale;
|
||||
|
||||
BigSwitchState createState() => new BigSwitchState(this);
|
||||
BigSwitchState createState() => new BigSwitchState();
|
||||
}
|
||||
|
||||
class BigSwitchState extends ComponentState<BigSwitch> {
|
||||
BigSwitchState(BigSwitch config) : super(config);
|
||||
|
||||
class BigSwitchState extends State<BigSwitch> {
|
||||
bool _value = false;
|
||||
|
||||
void _handleOnChanged(bool value) {
|
||||
|
||||
@@ -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<DatePickerDemo> {
|
||||
DatePickerDemoState(DatePickerDemo config) : super(config) {
|
||||
class DatePickerDemoState extends State<DatePickerDemo> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
DateTime now = new DateTime.now();
|
||||
_dateTime = new DateTime(now.year, now.month, now.day);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,10 @@ class DragData {
|
||||
}
|
||||
|
||||
class ExampleDragTarget extends StatefulComponent {
|
||||
ExampleDragTargetState createState() => new ExampleDragTargetState(this);
|
||||
ExampleDragTargetState createState() => new ExampleDragTargetState();
|
||||
}
|
||||
|
||||
class ExampleDragTargetState extends ComponentState<ExampleDragTarget> {
|
||||
ExampleDragTargetState(ExampleDragTarget config) : super(config);
|
||||
|
||||
class ExampleDragTargetState extends State<ExampleDragTarget> {
|
||||
String _text = 'ready';
|
||||
|
||||
void _handleAccept(DragData data) {
|
||||
@@ -71,9 +69,7 @@ class DragAndDropApp extends StatefulComponent {
|
||||
DragAndDropAppState createState() => new DragAndDropAppState(this);
|
||||
}
|
||||
|
||||
class DragAndDropAppState extends ComponentState<DragAndDropApp> {
|
||||
DragAndDropAppState(DragAndDropApp config) : super(config);
|
||||
|
||||
class DragAndDropAppState extends State<DragAndDropApp> {
|
||||
DragController _dragController;
|
||||
Offset _displacement = Offset.zero;
|
||||
|
||||
|
||||
@@ -61,12 +61,10 @@ List<Route> routes = [
|
||||
];
|
||||
|
||||
class NavigationExampleApp extends StatefulComponent {
|
||||
NavigationExampleAppState createState() => new NavigationExampleAppState(this);
|
||||
NavigationExampleAppState createState() => new NavigationExampleAppState();
|
||||
}
|
||||
|
||||
class NavigationExampleAppState extends ComponentState<NavigationExampleApp> {
|
||||
NavigationExampleAppState(NavigationExampleApp config) : super(config);
|
||||
|
||||
class NavigationExampleAppState extends State<NavigationExampleApp> {
|
||||
NavigatorHistory _history = new NavigatorHistory(routes);
|
||||
|
||||
void onBack() {
|
||||
|
||||
@@ -20,8 +20,9 @@ class PageableListApp extends StatefulComponent {
|
||||
PageableListAppState createState() => new PageableListAppState(this);
|
||||
}
|
||||
|
||||
class PageableListAppState extends ComponentState<PageableListApp> {
|
||||
PageableListAppState(PageableListApp config) : super(config) {
|
||||
class PageableListAppState extends State<PageableListApp> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
List<Size> cardSizes = [
|
||||
[100.0, 300.0], [300.0, 100.0], [200.0, 400.0], [400.0, 400.0], [300.0, 400.0]
|
||||
]
|
||||
|
||||
@@ -10,8 +10,9 @@ class ProgressIndicatorApp extends StatefulComponent {
|
||||
ProgressIndicatorAppState createState() => new ProgressIndicatorAppState(this);
|
||||
}
|
||||
|
||||
class ProgressIndicatorAppState extends ComponentState<ProgressIndicatorApp> {
|
||||
ProgressIndicatorAppState(ProgressIndicatorApp config) : super(config) {
|
||||
class ProgressIndicatorAppState extends State<ProgressIndicatorApp> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
valueAnimation = new ValueAnimation<double>()
|
||||
..duration = const Duration(milliseconds: 1500)
|
||||
..variable = new AnimatedValue<double>(
|
||||
|
||||
@@ -10,8 +10,9 @@ class ScaleApp extends StatefulComponent {
|
||||
ScaleAppState createState() => new ScaleAppState(this);
|
||||
}
|
||||
|
||||
class ScaleAppState extends ComponentState<ScaleApp> {
|
||||
ScaleAppState(ScaleApp config) : super(config) {
|
||||
class ScaleAppState extends State<ScaleApp> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_offset = Offset.zero;
|
||||
_zoom = 1.0;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ abstract class AnimatedComponent extends StatefulComponent {
|
||||
final Direction direction;
|
||||
}
|
||||
|
||||
abstract class AnimatedComponentState<T extends AnimatedComponent> extends ComponentState<T> {
|
||||
AnimatedComponentState(T config) : super(config) {
|
||||
abstract class AnimatedState<T extends AnimatedComponent> extends State<T> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_performance = new AnimationPerformance(duration: config.duration);
|
||||
performance.addStatusListener(_handleAnimationStatusChanged);
|
||||
if (buildDependsOnPerformance) {
|
||||
|
||||
@@ -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<ImageListener> {
|
||||
ImageListenerState(ImageListener config) : super(config) {
|
||||
class ImageListenerState extends State<ImageListener> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
config.image.addListener(_handleImageChanged);
|
||||
}
|
||||
|
||||
@@ -742,6 +743,7 @@ class ImageListenerState extends ComponentState<ImageListener> {
|
||||
|
||||
void dispose() {
|
||||
config.image.removeListener(_handleImageChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void didUpdateConfig(ImageListener oldConfig) {
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
import 'package:sky/src/fn3/basic.dart';
|
||||
import 'package:sky/src/fn3/framework.dart';
|
||||
|
||||
abstract class ButtonState<T extends StatefulComponent> extends ComponentState<T> {
|
||||
ButtonState(T config) : super(config);
|
||||
|
||||
abstract class ButtonState<T extends StatefulComponent> extends State<T> {
|
||||
bool highlight = false;
|
||||
|
||||
void _handlePointerDown(_) {
|
||||
|
||||
@@ -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<DatePicker> {
|
||||
DatePickerState(DatePicker config) : super(config);
|
||||
|
||||
class DatePickerState extends State<DatePicker> {
|
||||
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<MonthPicker> {
|
||||
MonthPickerState(MonthPicker config) : super(config) {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_updateCurrentDate();
|
||||
}
|
||||
|
||||
@@ -342,6 +341,7 @@ class MonthPickerState extends ScrollableWidgetListState<MonthPicker> {
|
||||
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<YearPicker> {
|
||||
YearPickerState(YearPicker config) : super(config);
|
||||
|
||||
int get itemCount => config.lastDate.year - config.firstDate.year + 1;
|
||||
|
||||
List<Widget> buildItems(BuildContext context, int start, int count) {
|
||||
|
||||
@@ -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<Dismissable> {
|
||||
DismissableState(Dismissable config) : super(config) {
|
||||
class DismissableState extends State<Dismissable> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_fadePerformance = new AnimationPerformance(duration: _kCardDismissFadeout);
|
||||
_fadePerformance.addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed)
|
||||
|
||||
@@ -25,12 +25,10 @@ class DragTarget<T> extends StatefulComponent {
|
||||
final DragTargetWillAccept<T> onWillAccept;
|
||||
final DragTargetAccept<T> onAccept;
|
||||
|
||||
DragTargetState<T> createState() => new DragTargetState<T>(this);
|
||||
DragTargetState<T> createState() => new DragTargetState<T>();
|
||||
}
|
||||
|
||||
class DragTargetState<T> extends ComponentState<DragTarget<T>> {
|
||||
DragTargetState(DragTarget<T> config) : super(config);
|
||||
|
||||
class DragTargetState<T> extends State<DragTarget<T>> {
|
||||
final List<T> _candidateData = new List<T>();
|
||||
final List<dynamic> _rejectedData = new List<dynamic>();
|
||||
|
||||
|
||||
@@ -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<Drawer> {
|
||||
DrawerState(Drawer config) : super(config) {
|
||||
class DrawerState extends State<Drawer> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_performance = new AnimationPerformance(duration: _kBaseSettleDuration);
|
||||
_performance.addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.dismissed)
|
||||
|
||||
@@ -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<DrawerItem> {
|
||||
DrawerItemState(DrawerItem config) : super(config);
|
||||
|
||||
TextStyle _getTextStyle(ThemeData themeData) {
|
||||
TextStyle result = themeData.text.body2;
|
||||
if (config.selected)
|
||||
|
||||
@@ -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<FlatButton> {
|
||||
FlatButtonState(FlatButton config) : super(config);
|
||||
|
||||
Color getColor(BuildContext context) {
|
||||
if (!config.enabled || !highlight)
|
||||
return null;
|
||||
|
||||
@@ -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<FloatingActionButton> {
|
||||
FloatingActionButtonState(FloatingActionButton config) : super(config);
|
||||
|
||||
Widget buildContent(BuildContext context) {
|
||||
IconThemeColor iconThemeColor = IconThemeColor.white;
|
||||
Color materialColor = config.backgroundColor;
|
||||
|
||||
@@ -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<Focus> {
|
||||
FocusState(Focus config) : super(config);
|
||||
|
||||
class FocusState extends State<Focus> {
|
||||
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<Focus> {
|
||||
void dispose() {
|
||||
_updateWidgetRemovalListener(null);
|
||||
_updateScopeRemovalListener(null);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -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<T extends StatefulComponent> {
|
||||
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<T extends StatefulComponent> {
|
||||
/// 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<T extends Widget> extends Element<T> {
|
||||
}
|
||||
|
||||
/// 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<T extends Widget> extends Element<T> {
|
||||
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<T extends StatelessComponent> extends BuildableE
|
||||
class StatefulComponentElement extends BuildableElement<StatefulComponent> {
|
||||
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<StatefulComponent> {
|
||||
void unmount() {
|
||||
super.unmount();
|
||||
_state.dispose();
|
||||
assert(_state._debugLifecycleState == _StateLifecycle.defunct);
|
||||
_state._element = null;
|
||||
_state = null;
|
||||
}
|
||||
|
||||
@@ -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<GestureDetector> {
|
||||
GestureDetectorState(GestureDetector config) : super(config) {
|
||||
class GestureDetectorState extends State<GestureDetector> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
didUpdateConfig(null);
|
||||
}
|
||||
|
||||
@@ -120,6 +121,7 @@ class GestureDetectorState extends ComponentState<GestureDetector> {
|
||||
_horizontalDrag = _ensureDisposed(_horizontalDrag);
|
||||
_pan = _ensureDisposed(_pan);
|
||||
_scale = _ensureDisposed(_scale);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void didUpdateConfig(GestureDetector oldConfig) {
|
||||
|
||||
@@ -52,7 +52,6 @@ class HomogeneousViewportElement extends RenderObjectElement<HomogeneousViewport
|
||||
HomogeneousViewportElement(HomogeneousViewport widget) : super(widget);
|
||||
|
||||
List<Element> _children = const <Element>[];
|
||||
bool _layoutDirty = true;
|
||||
int _layoutFirstIndex;
|
||||
int _layoutItemCount;
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ abstract class MaterialButton extends StatefulComponent {
|
||||
}
|
||||
|
||||
abstract class MaterialButtonState<T extends MaterialButton> extends ButtonState<T> {
|
||||
MaterialButtonState(T config) : super(config);
|
||||
|
||||
Color getColor(BuildContext context);
|
||||
int get level;
|
||||
|
||||
|
||||
@@ -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<MixedViewport> {
|
||||
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<MixedViewport> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Navigator> {
|
||||
NavigatorState(Navigator config) : super(config);
|
||||
|
||||
class NavigatorState extends State<Navigator> {
|
||||
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,
|
||||
|
||||
@@ -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<PopupMenu> {
|
||||
PopupMenuState(PopupMenu config) : super(config) {
|
||||
class PopupMenuState extends State<PopupMenu> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_updateBoxPainter();
|
||||
config.performance.addListener(_performanceChanged);
|
||||
}
|
||||
@@ -75,6 +76,7 @@ class PopupMenuState extends ComponentState<PopupMenu> {
|
||||
|
||||
void dispose() {
|
||||
config.performance.removeListener(_performanceChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _performanceChanged() {
|
||||
|
||||
@@ -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<ProgressIndicator> {
|
||||
ProgressIndicatorState(ProgressIndicator config) : super(config) {
|
||||
class ProgressIndicatorState extends State<ProgressIndicator> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_performance = new AnimationPerformance()
|
||||
..duration = const Duration(milliseconds: 1500)
|
||||
..variable = new AnimatedValue<double>(0.0, end: 1.0, curve: ease);
|
||||
@@ -44,7 +45,6 @@ class ProgressIndicatorState extends ComponentState<ProgressIndicator> {
|
||||
_restartAnimation();
|
||||
});
|
||||
_performance.play();
|
||||
|
||||
}
|
||||
|
||||
AnimationPerformance _performance;
|
||||
|
||||
@@ -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<Radio> {
|
||||
RadioState(Radio config) : super(config);
|
||||
|
||||
class RadioState extends State<Radio> {
|
||||
Color _getColor(BuildContext context) {
|
||||
ThemeData themeData = Theme.of(context);
|
||||
if (config.value == config.groupValue)
|
||||
|
||||
@@ -21,12 +21,10 @@ class RaisedButton extends MaterialButton {
|
||||
assert(enabled != null);
|
||||
}
|
||||
|
||||
RaisedButtonState createState() => new RaisedButtonState(this);
|
||||
RaisedButtonState createState() => new RaisedButtonState();
|
||||
}
|
||||
|
||||
class RaisedButtonState extends MaterialButtonState<RaisedButton> {
|
||||
RaisedButtonState(RaisedButton config) : super(config);
|
||||
|
||||
Color getColor(BuildContext context) {
|
||||
if (config.enabled) {
|
||||
switch (Theme.of(context).brightness) {
|
||||
|
||||
@@ -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<T extends Scrollable> extends ComponentState<T> {
|
||||
ScrollableState(T config) : super(config) {
|
||||
abstract class ScrollableState<T extends Scrollable> extends State<T> {
|
||||
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<T extends Scrollable> extends ComponentState<T> {
|
||||
|
||||
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<ScrollableViewport> {
|
||||
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<T extends ScrollableWidgetList> extends ScrollableState<T> {
|
||||
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<T> extends ScrollableWidgetList {
|
||||
final List<T> items;
|
||||
final ItemBuilder<T> itemBuilder;
|
||||
|
||||
ScrollableListState<T, ScrollableList<T>> createState() => new ScrollableListState<T, ScrollableList<T>>(this);
|
||||
ScrollableListState<T, ScrollableList<T>> createState() => new ScrollableListState<T, ScrollableList<T>>();
|
||||
}
|
||||
|
||||
class ScrollableListState<T, Config extends ScrollableList<T>> extends ScrollableWidgetListState<Config> {
|
||||
ScrollableListState(Config config) : super(config);
|
||||
|
||||
ScrollBehavior createScrollBehavior() {
|
||||
return config.itemsWrap ? new UnboundedBehavior() : super.createScrollBehavior();
|
||||
}
|
||||
@@ -512,8 +507,6 @@ class PageableList<T> extends ScrollableList<T> {
|
||||
}
|
||||
|
||||
class PageableListState<T> extends ScrollableListState<T, PageableList<T>> {
|
||||
PageableListState(PageableList<T> config) : super(config);
|
||||
|
||||
double _snapScrollOffset(double newScrollOffset) {
|
||||
double scaledScrollOffset = newScrollOffset / config.itemExtent;
|
||||
double previousScrollOffset = scaledScrollOffset.floor() * config.itemExtent;
|
||||
|
||||
@@ -56,12 +56,10 @@ class SnackBar extends AnimatedComponent {
|
||||
final List<SnackBarAction> actions;
|
||||
final SnackBarDismissedCallback onDismissed;
|
||||
|
||||
SnackBarState createState() => new SnackBarState(this);
|
||||
SnackBarState createState() => new SnackBarState();
|
||||
}
|
||||
|
||||
class SnackBarState extends AnimatedComponentState<SnackBar> {
|
||||
SnackBarState(SnackBar config) : super(config);
|
||||
|
||||
class SnackBarState extends AnimatedState<SnackBar> {
|
||||
void handleDismissed() {
|
||||
if (config.onDismissed != null)
|
||||
config.onDismissed();
|
||||
|
||||
@@ -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<TabBar> {
|
||||
TabBarState(TabBar config) : super(config) {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
_indicatorAnimation = new ValueAnimation<Rect>()
|
||||
..duration = _kTabBarScroll
|
||||
..variable = new AnimatedRect(null, curve: ease);
|
||||
|
||||
@@ -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<TransitionComponent> {
|
||||
TransitionComponentState(TransitionComponent config) : super(config) {
|
||||
class TransitionState extends State<TransitionComponent> {
|
||||
void initState(BuildContext context) {
|
||||
super.initState(context);
|
||||
config.performance.addListener(_performanceChanged);
|
||||
}
|
||||
|
||||
@@ -40,6 +41,7 @@ class TransitionComponentState extends ComponentState<TransitionComponent> {
|
||||
|
||||
void dispose() {
|
||||
config.performance.removeListener(_performanceChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _performanceChanged() {
|
||||
|
||||
@@ -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<FlipComponent> {
|
||||
FlipComponentState(FlipComponent config): super(config);
|
||||
class FlipComponentState extends State<FlipComponent> {
|
||||
bool _showLeft = true;
|
||||
|
||||
void flip() {
|
||||
|
||||
@@ -9,8 +9,7 @@ class RootComponent extends StatefulComponent {
|
||||
RootComponentState createState() => new RootComponentState(this);
|
||||
}
|
||||
|
||||
class RootComponentState extends ComponentState<RootComponent> {
|
||||
RootComponentState(RootComponent widget) : super(widget);
|
||||
class RootComponentState extends State<RootComponent> {
|
||||
Widget _child = new DecoratedBox(decoration: new BoxDecoration());
|
||||
Widget get child => _child;
|
||||
void set child(Widget value) {
|
||||
|
||||
Reference in New Issue
Block a user