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

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

Generated by: LCOV version 2.0-1