1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/foundation.dart';
6import 'package:flutter/widgets.dart';
7import 'colors.dart';
8
9/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved
10/// using [IconTheme.of].
11class CupertinoIconThemeData extends IconThemeData with Diagnosticable {
12 /// Creates a [CupertinoIconThemeData].
13 const CupertinoIconThemeData({
14 super.size,
15 super.fill,
16 super.weight,
17 super.grade,
18 super.opticalSize,
19 super.color,
20 super.opacity,
21 super.shadows,
22 super.applyTextScaling,
23 });
24
25 /// Called by [IconTheme.of] to resolve [color] against the given [BuildContext].
26 @override
27 IconThemeData resolve(BuildContext context) {
28 final Color? resolvedColor = CupertinoDynamicColor.maybeResolve(color, context);
29 return resolvedColor == color ? this : copyWith(color: resolvedColor);
30 }
31
32 /// Creates a copy of this icon theme but with the given fields replaced with
33 /// the new values.
34 @override
35 CupertinoIconThemeData copyWith({
36 double? size,
37 double? fill,
38 double? weight,
39 double? grade,
40 double? opticalSize,
41 Color? color,
42 double? opacity,
43 List<Shadow>? shadows,
44 bool? applyTextScaling,
45 }) {
46 return CupertinoIconThemeData(
47 size: size ?? this.size,
48 fill: fill ?? this.fill,
49 weight: weight ?? this.weight,
50 grade: grade ?? this.grade,
51 opticalSize: opticalSize ?? this.opticalSize,
52 color: color ?? this.color,
53 opacity: opacity ?? this.opacity,
54 shadows: shadows ?? this.shadows,
55 applyTextScaling: applyTextScaling ?? this.applyTextScaling,
56 );
57 }
58
59 @override
60 void debugFillProperties(DiagnosticPropertiesBuilder properties) {
61 super.debugFillProperties(properties);
62 properties.add(createCupertinoColorProperty('color', color, defaultValue: null));
63 }
64}
65