copyWith method

  1. @useResult
FThemeData copyWith({
  1. FAlertStyles? alertStyles,
  2. FAvatarStyle? avatarStyle,
  3. FBadgeStyles? badgeStyles,
  4. FBottomNavigationBarStyle? bottomNavigationBarStyle,
  5. FButtonStyles? buttonStyles,
  6. FCalendarStyle? calendarStyle,
  7. FCardStyle? cardStyle,
  8. FCheckboxStyle? checkboxStyle,
  9. FDialogStyle? dialogStyle,
  10. FHeaderStyles? headerStyle,
  11. FLabelStyles? labelStyles,
  12. FPopoverStyle? popoverStyle,
  13. FProgressStyle? progressStyle,
  14. FRadioStyle? radioStyle,
  15. FResizableStyle? resizableStyle,
  16. FTabsStyle? tabsStyle,
  17. FTextFieldStyle? textFieldStyle,
  18. FTooltipStyle? tooltipStyle,
  19. FScaffoldStyle? scaffoldStyle,
  20. FSelectGroupStyle? selectGroupStyle,
  21. FDividerStyles? dividerStyles,
  22. FSwitchStyle? switchStyle,
})

Returns a copy of this FThemeData with the given properties replaced.

final theme = FThemeData(
  alertStyles: ...,
  avatarStyle: ...,
);

final copy = theme.copyWith(avatarStyle: bar);

print(theme.alertStyles == copy.alertStyles); // true
print(theme.avatarStyle == copy.avatarStyle); // false

To modify colorScheme, typography, and/or style, create a new FThemeData using FThemeData.inherit first. This allows the global theme data to propagate to widget-specific theme data.

@override
Widget build(BuildContext context) {
  final theme = FThemeData.inherit(
    colorScheme: FThemes.zinc.light.colorScheme.copyWith(
      primary: const Color(0xFF0D47A1), // dark blue
      primaryForeground: const Color(0xFFFFFFFF), // white
    ),
    typography: FThemes.zinc.light.typography.copyWith(
      defaultFontFamily: 'Roboto',
    ).scale(sizeScalar: 0.8),
    style: FThemes.zinc.light.style.copyWith(
      borderRadius: BorderRadius.zero,
    ),
  );

  return FTheme(
    data: theme.copyWith(
      cardStyle: theme.cardStyle.copyWith(
        decoration: theme.cardStyle.decoration.copyWith(
          borderRadius: const BorderRadius.all(Radius.circular(8)),
        ),
      ),
    ),
    child: const FScaffold(...),
  );
}

Implementation

@useResult
FThemeData copyWith({
  FAlertStyles? alertStyles,
  FAvatarStyle? avatarStyle,
  FBadgeStyles? badgeStyles,
  FBottomNavigationBarStyle? bottomNavigationBarStyle,
  FButtonStyles? buttonStyles,
  FCalendarStyle? calendarStyle,
  FCardStyle? cardStyle,
  FCheckboxStyle? checkboxStyle,
  FDialogStyle? dialogStyle,
  FHeaderStyles? headerStyle,
  FLabelStyles? labelStyles,
  FPopoverStyle? popoverStyle,
  FProgressStyle? progressStyle,
  FRadioStyle? radioStyle,
  FResizableStyle? resizableStyle,
  FTabsStyle? tabsStyle,
  FTextFieldStyle? textFieldStyle,
  FTooltipStyle? tooltipStyle,
  FScaffoldStyle? scaffoldStyle,
  FSelectGroupStyle? selectGroupStyle,
  FDividerStyles? dividerStyles,
  FSwitchStyle? switchStyle,
}) =>
    FThemeData(
      colorScheme: colorScheme,
      typography: typography,
      style: style,
      alertStyles: alertStyles ?? this.alertStyles,
      avatarStyle: avatarStyle ?? this.avatarStyle,
      badgeStyles: badgeStyles ?? this.badgeStyles,
      bottomNavigationBarStyle: bottomNavigationBarStyle ?? this.bottomNavigationBarStyle,
      buttonStyles: buttonStyles ?? this.buttonStyles,
      calendarStyle: calendarStyle ?? this.calendarStyle,
      cardStyle: cardStyle ?? this.cardStyle,
      checkboxStyle: checkboxStyle ?? this.checkboxStyle,
      dialogStyle: dialogStyle ?? this.dialogStyle,
      dividerStyles: dividerStyles ?? this.dividerStyles,
      headerStyle: headerStyle ?? this.headerStyle,
      labelStyles: labelStyles ?? this.labelStyles,
      popoverStyle: popoverStyle ?? this.popoverStyle,
      progressStyle: progressStyle ?? this.progressStyle,
      radioStyle: radioStyle ?? this.radioStyle,
      resizableStyle: resizableStyle ?? this.resizableStyle,
      tabsStyle: tabsStyle ?? this.tabsStyle,
      textFieldStyle: textFieldStyle ?? this.textFieldStyle,
      tooltipStyle: tooltipStyle ?? this.tooltipStyle,
      scaffoldStyle: scaffoldStyle ?? this.scaffoldStyle,
      selectGroupStyle: selectGroupStyle ?? this.selectGroupStyle,
      switchStyle: switchStyle ?? this.switchStyle,
    );