icon_theme_data.dart 1.6 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
import 'package:flutter/foundation.dart';
6 7 8 9 10
import 'package:flutter/widgets.dart';
import 'colors.dart';

/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved
/// using [IconTheme.of].
11
class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin {
12 13 14 15 16 17 18 19 20 21
  /// Creates a [CupertinoIconThemeData].
  ///
  /// The opacity applies to both explicit and default icon colors. The value
  /// is clamped between 0.0 and 1.0.
  const CupertinoIconThemeData({
    Color color,
    double opacity,
    double size
  }) : super(color: color, opacity: opacity, size: size);

Dan Field's avatar
Dan Field committed
22
  /// Called by [IconTheme.of] to resolve [color] against the given [BuildContext].
23 24 25 26 27
  @override
  IconThemeData resolve(BuildContext context) {
    final Color resolvedColor = CupertinoDynamicColor.resolve(color, context);
    return resolvedColor == color ? this : copyWith(color: resolvedColor);
  }
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  /// Creates a copy of this icon theme but with the given fields replaced with
  /// the new values.
  @override
  CupertinoIconThemeData copyWith({ Color color, double opacity, double size }) {
    return CupertinoIconThemeData(
      color: color ?? this.color,
      opacity: opacity ?? this.opacity,
      size: size ?? this.size,
    );
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(createCupertinoColorProperty('color', color, defaultValue: null));
  }
45
}