tweens.dart 2.54 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({ super.begin, super.end });
24

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

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

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

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

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