diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index fb30af03ad..8b1da1cd56 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -55,18 +55,26 @@ export 'package:flutter/rendering.dart' show /// This class paints its child into an intermediate buffer and then blends the /// child back into the scene partially transparent. /// -/// This class is relatively expensive because it requires painting the child -/// into an intermediate buffer. +/// For values of opacity other than 0.0 and 1.0, this class is relatively +/// expensive because it requires painting the child into an intermediate +/// buffer. For the value 0.0, the child is simply not painted at all. For the +/// value 1.0, the child is painted immediately without an intermediate buffer. class Opacity extends SingleChildRenderObjectWidget { Opacity({ Key key, this.opacity, Widget child }) : super(key: key, child: child) { - assert(opacity >= 0.0 && opacity <= 1.0); + assert(opacity != null && opacity >= 0.0 && opacity <= 1.0); } /// The fraction to scale the child's alpha value. /// /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent /// (i.e., invisible). + /// + /// The opacity must not be null. + /// + /// Values 1.0 and 0.0 are painted with a fast path. Other values + /// require painting the child into an intermediate buffer, which is + /// expensive. final double opacity; @override diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 68d712a54f..4a8c24c787 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -382,6 +382,23 @@ class AnimatedPositioned extends ImplicitlyAnimatedWidget { @override _AnimatedPositionedState createState() => new _AnimatedPositionedState(); + + @override + void debugFillDescription(List description) { + super.debugFillDescription(description); + if (left != null) + description.add('left: $left'); + if (top != null) + description.add('top: $top'); + if (right != null) + description.add('right: $right'); + if (bottom != null) + description.add('bottom: $bottom'); + if (width != null) + description.add('width: $width'); + if (height != null) + description.add('height: $height'); + } } class _AnimatedPositionedState extends AnimatedWidgetBaseState { @@ -433,3 +450,57 @@ class _AnimatedPositionedState extends AnimatedWidgetBaseState= 0.0 && opacity <= 1.0); + } + + /// The widget below this widget in the tree. + final Widget child; + + /// The target opacity. + /// + /// An opacity of 1.0 is fully opaque. An opacity of 0.0 is fully transparent + /// (i.e., invisible). + /// + /// The opacity must not be null. + final double opacity; + + @override + _AnimatedOpacityState createState() => new _AnimatedOpacityState(); + + @override + void debugFillDescription(List description) { + super.debugFillDescription(description); + description.add('opacity: $opacity'); + } +} + +class _AnimatedOpacityState extends AnimatedWidgetBaseState { + Tween _opacity; + + @override + void forEachTween(TweenVisitor visitor) { + // TODO(ianh): Use constructor tear-offs when it becomes possible + _opacity = visitor(_opacity, config.opacity, (dynamic value) => new Tween(begin: value)); + } + + @override + Widget build(BuildContext context) { + return new Opacity( + opacity: _opacity.evaluate(animation), + child: config.child + ); + } +}