LCOV - code coverage report
Current view: top level - components/chip - foss_chip_style.dart Coverage Total Hit
Test: fossui coverage Lines: 100.0 % 13 13
Test Date: 2026-11-29 09:15:47 Functions: - 0 0

            Line data    Source code
       1              : part of 'foss_chip.dart';
       2              : 
       3              : /// Visual overrides for a [FossChip]. Every field is optional; a null field
       4              : /// falls back to the value the theme resolves for the chip's variant and size.
       5              : /// Pass one to a single chip via `style:` to tweak a one-off, without changing
       6              : /// the theme for every other chip.
       7              : ///
       8              : /// Stateful fields ([backgroundColor], [foregroundColor]) are
       9              : /// [WidgetStateProperty]s resolved against the chip's interactive state set
      10              : /// (selected, hovered, disabled); the rest are plain values. Selection resolves
      11              : /// as [WidgetState.selected].
      12              : ///
      13              : /// A green selected fill:
      14              : ///
      15              : /// ```dart
      16              : /// FossChip(
      17              : ///   label: const Text('Design'),
      18              : ///   selected: on,
      19              : ///   onSelected: (v) => setState(() => on = v),
      20              : ///   style: FossChipStyle(
      21              : ///     backgroundColor: WidgetStateProperty.resolveWith((states) {
      22              : ///       if (states.contains(WidgetState.selected)) {
      23              : ///         return const Color(0xFF16A34A);
      24              : ///       }
      25              : ///       return const Color(0x0A000000);
      26              : ///     }),
      27              : ///   ),
      28              : /// );
      29              : /// ```
      30              : @immutable
      31              : class FossChipStyle {
      32              :   /// Creates a set of chip overrides. All fields default to null (inherit).
      33            2 :   const FossChipStyle({
      34              :     this.backgroundColor,
      35              :     this.foregroundColor,
      36              :     this.side,
      37              :     this.borderRadius,
      38              :     this.padding,
      39              :     this.minHeight,
      40              :     this.textStyle,
      41              :     this.iconSize,
      42              :     this.gap,
      43              :     this.disabledOpacity,
      44              :   });
      45              : 
      46              :   /// Fill color per interactive state.
      47              :   final WidgetStateProperty<Color>? backgroundColor;
      48              : 
      49              :   /// Label, icon, and close mark color per interactive state.
      50              :   final WidgetStateProperty<Color>? foregroundColor;
      51              : 
      52              :   /// Border drawn around the chip in every state, or [BorderSide.none] for
      53              :   /// none.
      54              :   final BorderSide? side;
      55              : 
      56              :   /// Uniform corner radius in logical pixels, applied to all four corners.
      57              :   final double? borderRadius;
      58              : 
      59              :   /// Horizontal inset between the pill edge and its content.
      60              :   final double? padding;
      61              : 
      62              :   /// Minimum pill height in logical pixels; grows with text scale.
      63              :   final double? minHeight;
      64              : 
      65              :   /// Label text style; its color is taken from [foregroundColor].
      66              :   final TextStyle? textStyle;
      67              : 
      68              :   /// Leading icon size in logical pixels.
      69              :   final double? iconSize;
      70              : 
      71              :   /// Gap between the leading icon and the label in logical pixels.
      72              :   final double? gap;
      73              : 
      74              :   /// Opacity applied to the whole chip when disabled.
      75              :   final double? disabledOpacity;
      76              : 
      77              :   /// Returns a copy with every non-null field of [other] laid over this one.
      78              :   /// Used to layer a per-instance override on the theme-resolved defaults.
      79              :   ///
      80              :   /// ```dart
      81              :   /// const base = FossChipStyle(borderRadius: 8, minHeight: 32);
      82              :   /// const override = FossChipStyle(minHeight: 24);
      83              :   /// base.merge(override); // borderRadius 8 kept, minHeight becomes 24
      84              :   /// ```
      85            1 :   FossChipStyle merge(FossChipStyle? other) {
      86              :     if (other == null) return this;
      87            1 :     return FossChipStyle(
      88            2 :       backgroundColor: other.backgroundColor ?? backgroundColor,
      89            2 :       foregroundColor: other.foregroundColor ?? foregroundColor,
      90            2 :       side: other.side ?? side,
      91            2 :       borderRadius: other.borderRadius ?? borderRadius,
      92            2 :       padding: other.padding ?? padding,
      93            1 :       minHeight: other.minHeight ?? minHeight,
      94            2 :       textStyle: other.textStyle ?? textStyle,
      95            2 :       iconSize: other.iconSize ?? iconSize,
      96            1 :       gap: other.gap ?? gap,
      97            2 :       disabledOpacity: other.disabledOpacity ?? disabledOpacity,
      98              :     );
      99              :   }
     100              : }
        

Generated by: LCOV version 2.0-1