icon_theme_data.dart 1.95 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 Diagnosticable {
12 13
  /// Creates a [CupertinoIconThemeData].
  const CupertinoIconThemeData({
14 15 16 17 18
    super.size,
    super.fill,
    super.weight,
    super.grade,
    super.opticalSize,
19 20 21
    super.color,
    super.opacity,
    super.shadows,
22
    super.applyTextScaling,
23
  });
24

Dan Field's avatar
Dan Field committed
25
  /// Called by [IconTheme.of] to resolve [color] against the given [BuildContext].
26 27
  @override
  IconThemeData resolve(BuildContext context) {
28
    final Color? resolvedColor = CupertinoDynamicColor.maybeResolve(color, context);
29 30
    return resolvedColor == color ? this : copyWith(color: resolvedColor);
  }
31 32 33 34

  /// Creates a copy of this icon theme but with the given fields replaced with
  /// the new values.
  @override
35 36 37 38 39 40 41 42 43
  CupertinoIconThemeData copyWith({
    double? size,
    double? fill,
    double? weight,
    double? grade,
    double? opticalSize,
    Color? color,
    double? opacity,
    List<Shadow>? shadows,
44
    bool? applyTextScaling,
45
  }) {
46
    return CupertinoIconThemeData(
47 48 49 50 51
      size: size ?? this.size,
      fill: fill ?? this.fill,
      weight: weight ?? this.weight,
      grade: grade ?? this.grade,
      opticalSize: opticalSize ?? this.opticalSize,
52 53
      color: color ?? this.color,
      opacity: opacity ?? this.opacity,
54
      shadows: shadows ?? this.shadows,
55
      applyTextScaling: applyTextScaling ?? this.applyTextScaling,
56 57 58 59 60 61 62 63
    );
  }

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