tweens.dart 2.7 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7 8 9 10 11
import 'package:flutter/animation.dart';
import 'package:flutter/painting.dart';

/// An interpolation between two fractional offsets.
///
12 13
/// This class specializes the interpolation of [Tween<FractionalOffset>] to be
/// appropriate for fractional offsets.
14 15
///
/// See [Tween] for a discussion on how to use interpolation objects.
16 17 18
///
/// See also:
///
19
///  * [AlignmentTween], which interpolates between to [Alignment] objects.
20 21 22
class FractionalOffsetTween extends Tween<FractionalOffset> {
  /// Creates a fractional offset tween.
  ///
23
  /// The [begin] and [end] properties may be null; the null value
24
  /// is treated as meaning the center.
25 26 27
  FractionalOffsetTween({ FractionalOffset begin, FractionalOffset end })
    : super(begin: begin, end: end);

28
  /// Returns the value this variable has at the given animation clock value.
29 30 31
  @override
  FractionalOffset lerp(double t) => FractionalOffset.lerp(begin, end, t);
}
32

33
/// An interpolation between two alignments.
34
///
35 36
/// This class specializes the interpolation of [Tween<Alignment>] to be
/// appropriate for alignments.
37 38 39 40 41
///
/// See [Tween] for a discussion on how to use interpolation objects.
///
/// See also:
///
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
///  * [AlignmentGeometryTween], which interpolates between two
///    [AlignmentGeometry] objects.
class AlignmentTween extends Tween<Alignment> {
  /// Creates a fractional offset tween.
  ///
  /// The [begin] and [end] properties may be null; the null value
  /// is treated as meaning the center.
  AlignmentTween({ Alignment begin, Alignment end })
    : super(begin: begin, end: end);

  /// Returns the value this variable has at the given animation clock value.
  @override
  Alignment lerp(double t) => Alignment.lerp(begin, end, t);
}

/// An interpolation between two [AlignmentGeometry].
///
/// This class specializes the interpolation of [Tween<AlignmentGeometry>]
/// to be appropriate for alignments.
///
/// See [Tween] for a discussion on how to use interpolation objects.
///
/// See also:
///
///  * [AlignmentTween], which interpolates between two [Alignment] objects.
class AlignmentGeometryTween extends Tween<AlignmentGeometry> {
68 69 70 71
  /// Creates a fractional offset geometry tween.
  ///
  /// The [begin] and [end] properties may be null; the null value
  /// is treated as meaning the center.
72 73 74
  AlignmentGeometryTween({
    AlignmentGeometry begin,
    AlignmentGeometry end,
75 76 77 78
  }) : super(begin: begin, end: end);

  /// Returns the value this variable has at the given animation clock value.
  @override
79
  AlignmentGeometry lerp(double t) => AlignmentGeometry.lerp(begin, end, t);
80
}