@@ -2108,3 +2108,110 @@ class _AnimatedPhysicalModelState extends AnimatedWidgetBaseState<AnimatedPhysic
2108
2108
);
2109
2109
}
2110
2110
}
2111
+
2112
+ /// Animated version of [FractionallySizedBox] which automatically transitions the
2113
+ /// child's size over a given duration whenever the given [widthFactor] or
2114
+ /// [heightFactor] changes, as well as the position whenever the given [alignment]
2115
+ /// changes.
2116
+ ///
2117
+ /// For the animation, you can choose a [curve] as well as a [duration] and the
2118
+ /// widget will automatically animate to the new target [widthFactor] or
2119
+ /// [heightFactor] .
2120
+ ///
2121
+ /// {@tool dartpad}
2122
+ /// The following example transitions an [AnimatedFractionallySizedBox]
2123
+ /// between two states. It adjusts the [heightFactor] , [widthFactor] , and
2124
+ /// [alignment] properties when tapped, using a [curve] of [Curves.fastOutSlowIn]
2125
+ ///
2126
+ /// ** See code in examples/api/lib/widgets/implicit_animations/animated_fractionally_sized_box.0.dart **
2127
+ /// {@end-tool}
2128
+ ///
2129
+ /// See also:
2130
+ ///
2131
+ /// * [AnimatedAlign] , which is an implicitly animated version of [Align] .
2132
+ /// * [AnimatedContainer] , which can transition more values at once.
2133
+ /// * [AnimatedSlide] , which can animate the translation of child by a given offset relative to its size.
2134
+ /// * [AnimatedPositioned] , which, as a child of a [Stack] , automatically
2135
+ /// transitions its child's position over a given duration whenever the given
2136
+ /// position changes.
2137
+ class AnimatedFractionallySizedBox extends ImplicitlyAnimatedWidget {
2138
+ /// Creates a widget that sizes its child to a fraction of the total available
2139
+ /// space that animates implicitly, and positions its child by an alignment
2140
+ /// that animates implicitly.
2141
+ ///
2142
+ /// The [curve] and [duration] argument must not be null
2143
+ /// If non-null, the [widthFactor] and [heightFactor] arguments must be
2144
+ /// non-negative.
2145
+ const AnimatedFractionallySizedBox ({
2146
+ super .key,
2147
+ this .alignment = Alignment .center,
2148
+ this .child,
2149
+ this .heightFactor,
2150
+ this .widthFactor,
2151
+ super .curve,
2152
+ required super .duration,
2153
+ super .onEnd,
2154
+ }) : assert (alignment != null ),
2155
+ assert (widthFactor == null || widthFactor >= 0.0 ),
2156
+ assert (heightFactor == null || heightFactor >= 0.0 );
2157
+
2158
+ /// The widget below this widget in the tree.
2159
+ ///
2160
+ /// {@macro flutter.widgets.ProxyWidget.child}
2161
+ final Widget ? child;
2162
+
2163
+ /// {@macro flutter.widgets.basic.fractionallySizedBox.heightFactor}
2164
+ final double ? heightFactor;
2165
+
2166
+ /// {@macro flutter.widgets.basic.fractionallySizedBox.widthFactor}
2167
+ final double ? widthFactor;
2168
+
2169
+ /// {@macro flutter.widgets.basic.fractionallySizedBox.alignment}
2170
+ final AlignmentGeometry alignment;
2171
+
2172
+ @override
2173
+ AnimatedWidgetBaseState <AnimatedFractionallySizedBox > createState () => _AnimatedFractionallySizedBoxState ();
2174
+
2175
+ @override
2176
+ void debugFillProperties (DiagnosticPropertiesBuilder properties) {
2177
+ super .debugFillProperties (properties);
2178
+ properties.add (DiagnosticsProperty <AlignmentGeometry >('alignment' , alignment));
2179
+ properties.add (DiagnosticsProperty <double >('widthFactor' , widthFactor));
2180
+ properties.add (DiagnosticsProperty <double >('heightFactor' , heightFactor));
2181
+ }
2182
+ }
2183
+
2184
+ class _AnimatedFractionallySizedBoxState extends AnimatedWidgetBaseState <AnimatedFractionallySizedBox > {
2185
+ AlignmentGeometryTween ? _alignment;
2186
+ Tween <double >? _heightFactorTween;
2187
+ Tween <double >? _widthFactorTween;
2188
+
2189
+ @override
2190
+ void forEachTween (TweenVisitor <dynamic > visitor) {
2191
+ _alignment = visitor (_alignment, widget.alignment, (dynamic value) => AlignmentGeometryTween (begin: value as AlignmentGeometry )) as AlignmentGeometryTween ? ;
2192
+ if (widget.heightFactor != null ) {
2193
+ _heightFactorTween = visitor (_heightFactorTween, widget.heightFactor, (dynamic value) => Tween <double >(begin: value as double )) as Tween <double >? ;
2194
+ }
2195
+ if (widget.widthFactor != null ) {
2196
+ _widthFactorTween = visitor (_widthFactorTween, widget.widthFactor, (dynamic value) => Tween <double >(begin: value as double )) as Tween <double >? ;
2197
+ }
2198
+ }
2199
+
2200
+ @override
2201
+ Widget build (BuildContext context) {
2202
+ return FractionallySizedBox (
2203
+ alignment: _alignment! .evaluate (animation)! ,
2204
+ heightFactor: _heightFactorTween? .evaluate (animation),
2205
+ widthFactor: _widthFactorTween? .evaluate (animation),
2206
+ child: widget.child,
2207
+ );
2208
+ }
2209
+
2210
+ @override
2211
+ void debugFillProperties (DiagnosticPropertiesBuilder description) {
2212
+ super .debugFillProperties (description);
2213
+ description.add (DiagnosticsProperty <AlignmentGeometryTween >('alignment' , _alignment, defaultValue: null ));
2214
+ description.add (DiagnosticsProperty <Tween <double >>('widthFactor' , _widthFactorTween, defaultValue: null ));
2215
+ description.add (DiagnosticsProperty <Tween <double >>('heightFactor' , _heightFactorTween, defaultValue: null ));
2216
+ }
2217
+ }
0 commit comments