Unverified Commit a21a22a6 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Convert AnimatedSize to a StatefulWidget (#80554)

parent 44c284ba
...@@ -377,7 +377,6 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker ...@@ -377,7 +377,6 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
key: _expandingBottomSheetKey, key: _expandingBottomSheetKey,
duration: const Duration(milliseconds: 225), duration: const Duration(milliseconds: 225),
curve: Curves.easeInOut, curve: Curves.easeInOut,
vsync: this,
alignment: FractionalOffset.topLeft, alignment: FractionalOffset.topLeft,
child: WillPopScope( child: WillPopScope(
onWillPop: _onWillPop, onWillPop: _onWillPop,
......
...@@ -7,6 +7,7 @@ import 'package:flutter/scheduler.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter/scheduler.dart';
import 'basic.dart'; import 'basic.dart';
import 'framework.dart'; import 'framework.dart';
import 'ticker_provider.dart';
/// Animated widget that automatically transitions its size over a given /// Animated widget that automatically transitions its size over a given
/// duration whenever the given child's size changes. /// duration whenever the given child's size changes.
...@@ -35,7 +36,6 @@ import 'framework.dart'; ...@@ -35,7 +36,6 @@ import 'framework.dart';
/// color: Colors.amberAccent, /// color: Colors.amberAccent,
/// child: AnimatedSize( /// child: AnimatedSize(
/// curve: Curves.easeIn, /// curve: Curves.easeIn,
/// vsync: this,
/// duration: const Duration(seconds: 1), /// duration: const Duration(seconds: 1),
/// child: FlutterLogo(size: _size), /// child: FlutterLogo(size: _size),
/// ), /// ),
...@@ -49,21 +49,27 @@ import 'framework.dart'; ...@@ -49,21 +49,27 @@ import 'framework.dart';
/// See also: /// See also:
/// ///
/// * [SizeTransition], which changes its size based on an [Animation]. /// * [SizeTransition], which changes its size based on an [Animation].
class AnimatedSize extends SingleChildRenderObjectWidget { class AnimatedSize extends StatefulWidget {
/// Creates a widget that animates its size to match that of its child. /// Creates a widget that animates its size to match that of its child.
/// ///
/// The [curve] and [duration] arguments must not be null. /// The [curve] and [duration] arguments must not be null.
const AnimatedSize({ const AnimatedSize({
Key? key, Key? key,
Widget? child, this.child,
this.alignment = Alignment.center, this.alignment = Alignment.center,
this.curve = Curves.linear, this.curve = Curves.linear,
required this.duration, required this.duration,
this.reverseDuration, this.reverseDuration,
required this.vsync, // TODO(jsimmons): deprecate when customers tests are updated.
TickerProvider? vsync, // ignore: avoid_unused_constructor_parameters
this.clipBehavior = Clip.hardEdge, this.clipBehavior = Clip.hardEdge,
}) : assert(clipBehavior != null), }) : assert(clipBehavior != null),
super(key: key, child: child); super(key: key);
/// The widget below this widget in the tree.
///
/// {@macro flutter.widgets.ProxyWidget.child}
final Widget? child;
/// The alignment of the child within the parent when the parent is not yet /// The alignment of the child within the parent when the parent is not yet
/// the same size as the child. /// the same size as the child.
...@@ -100,14 +106,54 @@ class AnimatedSize extends SingleChildRenderObjectWidget { ...@@ -100,14 +106,54 @@ class AnimatedSize extends SingleChildRenderObjectWidget {
/// If not specified, defaults to [duration]. /// If not specified, defaults to [duration].
final Duration? reverseDuration; final Duration? reverseDuration;
/// The [TickerProvider] for this widget.
final TickerProvider vsync;
/// {@macro flutter.material.Material.clipBehavior} /// {@macro flutter.material.Material.clipBehavior}
/// ///
/// Defaults to [Clip.hardEdge], and must not be null. /// Defaults to [Clip.hardEdge], and must not be null.
final Clip clipBehavior; final Clip clipBehavior;
@override
_AnimatedSizeState createState() => _AnimatedSizeState();
}
class _AnimatedSizeState
extends State<AnimatedSize> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return _AnimatedSize(
child: widget.child,
alignment: widget.alignment,
curve: widget.curve,
duration: widget.duration,
reverseDuration: widget.reverseDuration,
vsync: this,
clipBehavior: widget.clipBehavior,
);
}
}
class _AnimatedSize extends SingleChildRenderObjectWidget {
const _AnimatedSize({
Key? key,
Widget? child,
this.alignment = Alignment.center,
this.curve = Curves.linear,
required this.duration,
this.reverseDuration,
required this.vsync,
this.clipBehavior = Clip.hardEdge,
}) : assert(clipBehavior != null),
super(key: key, child: child);
final AlignmentGeometry alignment;
final Curve curve;
final Duration duration;
final Duration? reverseDuration;
/// The [TickerProvider] for this widget.
final TickerProvider vsync;
final Clip clipBehavior;
@override @override
RenderAnimatedSize createRenderObject(BuildContext context) { RenderAnimatedSize createRenderObject(BuildContext context) {
return RenderAnimatedSize( return RenderAnimatedSize(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment