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 5 6 7 8 9
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/animation.dart';
import 'package:flutter/painting.dart';

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

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

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

  /// Returns the value this variable has at the given animation clock value.
  @override
52
  Alignment lerp(double t) => Alignment.lerp(begin, end, t)!;
53 54 55 56 57 58 59 60 61 62 63 64
}

/// 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.
65
class AlignmentGeometryTween extends Tween<AlignmentGeometry?> {
66 67 68 69
  /// Creates a fractional offset geometry tween.
  ///
  /// The [begin] and [end] properties may be null; the null value
  /// is treated as meaning the center.
70
  AlignmentGeometryTween({
71 72
    AlignmentGeometry? begin,
    AlignmentGeometry? end,
73 74 75 76
  }) : super(begin: begin, end: end);

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