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

            Line data    Source code
       1              : part of 'foss_button.dart';
       2              : 
       3              : /// Visual overrides for a [FossButton]. Every field is optional; a null field
       4              : /// falls back to the value the theme resolves for the button's variant and
       5              : /// size. Pass one to a single button via `style:` to tweak a one-off, without
       6              : /// changing the theme for every other button.
       7              : ///
       8              : /// Stateful fields ([backgroundColor], [foregroundColor]) are
       9              : /// [WidgetStateProperty]s resolved against the button's interactive state set
      10              : /// (hovered, pressed, focused, disabled); the rest are plain values.
      11              : ///
      12              : /// A solid fill and pill corners:
      13              : ///
      14              : /// ```dart
      15              : /// FossButton(
      16              : ///   onPressed: save,
      17              : ///   style: const FossButtonStyle(
      18              : ///     borderRadius: 999,
      19              : ///     backgroundColor: WidgetStatePropertyAll(Color(0xFF6D28D9)),
      20              : ///   ),
      21              : ///   child: const Text('Save'),
      22              : /// );
      23              : /// ```
      24              : ///
      25              : /// A fill that darkens on hover and press, via
      26              : /// [WidgetStateProperty.resolveWith]:
      27              : ///
      28              : /// ```dart
      29              : /// FossButton(
      30              : ///   onPressed: save,
      31              : ///   style: FossButtonStyle(
      32              : ///     backgroundColor: WidgetStateProperty.resolveWith((states) {
      33              : ///       if (states.contains(WidgetState.pressed)) {
      34              : ///         return const Color(0xFF4C1D95);
      35              : ///       }
      36              : ///       if (states.contains(WidgetState.hovered)) {
      37              : ///         return const Color(0xFF5B21B6);
      38              : ///       }
      39              : ///       return const Color(0xFF6D28D9);
      40              : ///     }),
      41              : ///   ),
      42              : ///   child: const Text('Save'),
      43              : /// );
      44              : /// ```
      45              : ///
      46              : /// A compact, borderless, shadowless override:
      47              : ///
      48              : /// ```dart
      49              : /// FossButton(
      50              : ///   onPressed: save,
      51              : ///   style: const FossButtonStyle(
      52              : ///     side: BorderSide.none,
      53              : ///     shadow: [],
      54              : ///     padding: EdgeInsets.symmetric(horizontal: 8),
      55              : ///     minHeight: 28,
      56              : ///     gap: 4,
      57              : ///   ),
      58              : ///   child: const Text('Save'),
      59              : /// );
      60              : /// ```
      61              : @immutable
      62              : class FossButtonStyle {
      63              :   /// Creates a set of button overrides. All fields default to null (inherit).
      64            1 :   const FossButtonStyle({
      65              :     this.backgroundColor,
      66              :     this.foregroundColor,
      67              :     this.side,
      68              :     this.borderRadius,
      69              :     this.padding,
      70              :     this.minHeight,
      71              :     this.textStyle,
      72              :     this.shadow,
      73              :     this.iconSize,
      74              :     this.gap,
      75              :     this.disabledOpacity,
      76              :   });
      77              : 
      78              :   /// Fill color per interactive state.
      79              :   final WidgetStateProperty<Color>? backgroundColor;
      80              : 
      81              :   /// Label and icon color per interactive state.
      82              :   final WidgetStateProperty<Color>? foregroundColor;
      83              : 
      84              :   /// Border drawn around the button, or [BorderSide.none] for none.
      85              :   final BorderSide? side;
      86              : 
      87              :   /// Corner radius in logical pixels.
      88              :   final double? borderRadius;
      89              : 
      90              :   /// Inner padding around the content.
      91              :   final EdgeInsetsGeometry? padding;
      92              : 
      93              :   /// Minimum content height in logical pixels; grows with text scale.
      94              :   final double? minHeight;
      95              : 
      96              :   /// Label text style; its color is taken from [foregroundColor].
      97              :   final TextStyle? textStyle;
      98              : 
      99              :   /// Drop shadow layers; empty for none.
     100              :   final List<BoxShadow>? shadow;
     101              : 
     102              :   /// Leading and trailing icon size in logical pixels.
     103              :   final double? iconSize;
     104              : 
     105              :   /// Gap between icon and label in logical pixels.
     106              :   final double? gap;
     107              : 
     108              :   /// Opacity applied to the whole button when disabled.
     109              :   final double? disabledOpacity;
     110              : 
     111              :   /// Returns a copy with every non-null field of [other] laid over this one.
     112              :   /// Used to layer a per-instance override on the theme-resolved defaults.
     113              :   ///
     114              :   /// ```dart
     115              :   /// const base = FossButtonStyle(borderRadius: 8, minHeight: 36);
     116              :   /// const override = FossButtonStyle(minHeight: 28);
     117              :   /// base.merge(override); // borderRadius 8 kept, minHeight becomes 28
     118              :   /// ```
     119            1 :   FossButtonStyle merge(FossButtonStyle? other) {
     120              :     if (other == null) return this;
     121            1 :     return FossButtonStyle(
     122            2 :       backgroundColor: other.backgroundColor ?? backgroundColor,
     123            2 :       foregroundColor: other.foregroundColor ?? foregroundColor,
     124            2 :       side: other.side ?? side,
     125            2 :       borderRadius: other.borderRadius ?? borderRadius,
     126            2 :       padding: other.padding ?? padding,
     127            2 :       minHeight: other.minHeight ?? minHeight,
     128            2 :       textStyle: other.textStyle ?? textStyle,
     129            2 :       shadow: other.shadow ?? shadow,
     130            2 :       iconSize: other.iconSize ?? iconSize,
     131            2 :       gap: other.gap ?? gap,
     132            2 :       disabledOpacity: other.disabledOpacity ?? disabledOpacity,
     133              :     );
     134              :   }
     135              : }
        

Generated by: LCOV version 2.0-1