animated_size.dart 2.27 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
6
import 'package:flutter/rendering.dart';
7
import 'package:flutter/scheduler.dart';
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

import 'basic.dart';
import 'framework.dart';

/// Animated widget that automatically transitions its size over a given
/// duration whenever the given child's size changes.
class AnimatedSize extends SingleChildRenderObjectWidget {
  /// Creates a widget that animates its size to match that of its child.
  ///
  /// The [curve] and [duration] arguments must not be null.
  AnimatedSize({
    Key key,
    Widget child,
    this.alignment: FractionalOffset.center,
    this.curve: Curves.linear,
23 24
    @required this.duration,
    @required this.vsync,
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  }) : super(key: key, child: child);

  /// The alignment of the child within the parent when the parent is not yet
  /// the same size as the child.
  ///
  /// The x and y values of the alignment control the horizontal and vertical
  /// alignment, respectively. An x value of 0.0 means that the left edge of
  /// the child is aligned with the left edge of the parent whereas an x value
  /// of 1.0 means that the right edge of the child is aligned with the right
  /// edge of the parent. Other values interpolate (and extrapolate) linearly.
  /// For example, a value of 0.5 means that the center of the child is aligned
  /// with the center of the parent.
  final FractionalOffset alignment;

  /// The animation curve when transitioning this widget's size to match the
  /// child's size.
  final Curve curve;

  /// The duration when transitioning this widget's size to match the child's
  /// size.
  final Duration duration;

47 48 49
  /// The [TickerProvider] for this widget.
  final TickerProvider vsync;

50 51 52 53 54
  @override
  RenderAnimatedSize createRenderObject(BuildContext context) {
    return new RenderAnimatedSize(
      alignment: alignment,
      duration: duration,
55 56
      curve: curve,
      vsync: vsync,
57 58 59 60 61 62 63 64 65
    );
  }

  @override
  void updateRenderObject(BuildContext context,
                          RenderAnimatedSize renderObject) {
    renderObject
      ..alignment = alignment
      ..duration = duration
66 67
      ..curve = curve
      ..vsync = vsync;
68 69
  }
}