• Pierre-Louis's avatar
    Add support for fill, weight, grade, and optical size to `Icon` (#106896) · be3802c9
    Pierre-Louis authored
    * wip
    
    * update documentation
    
    * x
    
    * remove trailing spaces
    
    * x
    
    * remove useless CupertinoIconThemeData copyWith override
    
    * add tests
    
    * remove trailing spaces
    
    * fix isConcrete
    
    * x
    
    * x
    
    * x
    
    * remove trailing spaces
    
    * tweak docs
    
    * mention that font filenames often indicate the supported axes
    
    * add back cupertino IconThemeData copyWith
    
    * update copyWith
    Unverified
    be3802c9
icon_theme_data.dart 1.83 KB
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'colors.dart';

/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved
/// using [IconTheme.of].
class CupertinoIconThemeData extends IconThemeData with Diagnosticable {
  /// Creates a [CupertinoIconThemeData].
  const CupertinoIconThemeData({
    super.size,
    super.fill,
    super.weight,
    super.grade,
    super.opticalSize,
    super.color,
    super.opacity,
    super.shadows,
  });

  /// Called by [IconTheme.of] to resolve [color] against the given [BuildContext].
  @override
  IconThemeData resolve(BuildContext context) {
    final Color? resolvedColor = CupertinoDynamicColor.maybeResolve(color, context);
    return resolvedColor == color ? this : copyWith(color: resolvedColor);
  }

  /// Creates a copy of this icon theme but with the given fields replaced with
  /// the new values.
  @override
  CupertinoIconThemeData copyWith({
    double? size,
    double? fill,
    double? weight,
    double? grade,
    double? opticalSize,
    Color? color,
    double? opacity,
    List<Shadow>? shadows,
  }) {
    return CupertinoIconThemeData(
      size: size ?? this.size,
      fill: fill ?? this.fill,
      weight: weight ?? this.weight,
      grade: grade ?? this.grade,
      opticalSize: opticalSize ?? this.opticalSize,
      color: color ?? this.color,
      opacity: opacity ?? this.opacity,
      shadows: shadows ?? this.shadows,
    );
  }

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