icon_theme_data.dart 1.06 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4
// Copyright 2015 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 'dart:ui' as ui show lerpDouble;
Adam Barth's avatar
Adam Barth committed
6
import 'dart:ui' show Color, hashValues;
Adam Barth's avatar
Adam Barth committed
7 8

class IconThemeData {
9 10
  const IconThemeData({ this.color, this.opacity });

Adam Barth's avatar
Adam Barth committed
11 12 13 14
  /// The default color for icons.
  final Color color;

  /// An opacity to apply to both explicit and default icon colors.
15 16 17
  final double opacity;

  double get clampedOpacity => (opacity ?? 1.0).clamp(0.0, 1.0);
Adam Barth's avatar
Adam Barth committed
18

19 20
  static IconThemeData lerp(IconThemeData begin, IconThemeData end, double t) {
    return new IconThemeData(
Adam Barth's avatar
Adam Barth committed
21
      color: Color.lerp(begin.color, end.color, t),
22
      opacity: ui.lerpDouble(begin.clampedOpacity, end.clampedOpacity, t)
23 24 25
    );
  }

Adam Barth's avatar
Adam Barth committed
26 27 28 29
  bool operator ==(dynamic other) {
    if (other is! IconThemeData)
      return false;
    final IconThemeData typedOther = other;
30
    return color == typedOther.color && opacity == typedOther.opacity;
Adam Barth's avatar
Adam Barth committed
31 32
  }

33
  int get hashCode => hashValues(color, opacity);
Adam Barth's avatar
Adam Barth committed
34 35 36

  String toString() => '$color';
}