copyWith method

CodeSnippetTheme copyWith({
  1. ValueGetter<Color?>? backgroundColor,
  2. ValueGetter<Color?>? borderColor,
  3. ValueGetter<double?>? borderWidth,
  4. ValueGetter<BorderRadiusGeometry?>? borderRadius,
  5. ValueGetter<EdgeInsetsGeometry?>? padding,
})

Creates a copy of this theme with the given values replaced.

Returns a new CodeSnippetTheme instance with the same values as this theme, except for any parameters that are explicitly provided. Use ValueGetter functions to specify new values.

Parameters are ValueGetter functions that return the new value when called. This allows for conditional value setting and proper null handling.

Example:

final newTheme = originalTheme.copyWith(
  backgroundColor: () => Colors.blue.shade50,
  padding: () => EdgeInsets.all(12.0),
);

Implementation

CodeSnippetTheme copyWith({
  ValueGetter<Color?>? backgroundColor,
  ValueGetter<Color?>? borderColor,
  ValueGetter<double?>? borderWidth,
  ValueGetter<BorderRadiusGeometry?>? borderRadius,
  ValueGetter<EdgeInsetsGeometry?>? padding,
}) {
  return CodeSnippetTheme(
    backgroundColor:
        backgroundColor == null ? this.backgroundColor : backgroundColor(),
    borderColor: borderColor == null ? this.borderColor : borderColor(),
    borderWidth: borderWidth == null ? this.borderWidth : borderWidth(),
    borderRadius: borderRadius == null ? this.borderRadius : borderRadius(),
    padding: padding == null ? this.padding : padding(),
  );
}