copyWith method

TInputFieldTheme copyWith({
  1. TInputSize? size,
  2. Widget? preWidget,
  3. Widget? postWidget,
  4. double? height,
  5. EdgeInsets? padding,
  6. double? fontSize,
  7. TInputDecorationType? decorationType,
  8. WidgetStateProperty<Color>? color,
  9. WidgetStateProperty<Color>? backgroundColor,
  10. WidgetStateProperty<Color>? borderColor,
  11. WidgetStateProperty<TextStyle>? labelStyle,
  12. WidgetStateProperty<TextStyle>? helperTextStyle,
  13. WidgetStateProperty<TextStyle>? errorTextStyle,
  14. WidgetStateProperty<TextStyle>? tagStyle,
  15. WidgetStateProperty<double>? borderRadius,
  16. WidgetStateProperty<double>? borderWidth,
  17. WidgetStateProperty<BoxDecoration>? decoration,
  18. WidgetStateProperty<LabelBuilder>? labelBuilder,
  19. WidgetStateProperty<HelperTextBuilder>? helperTextBuilder,
  20. WidgetStateProperty<ErrorsBuilder>? errorsBuilder,
})

Implementation

TInputFieldTheme copyWith({
  TInputSize? size,
  Widget? preWidget,
  Widget? postWidget,
  double? height,
  EdgeInsets? padding,
  double? fontSize,
  TInputDecorationType? decorationType,
  WidgetStateProperty<Color>? color,
  WidgetStateProperty<Color>? backgroundColor,
  WidgetStateProperty<Color>? borderColor,
  WidgetStateProperty<TextStyle>? labelStyle,
  WidgetStateProperty<TextStyle>? helperTextStyle,
  WidgetStateProperty<TextStyle>? errorTextStyle,
  WidgetStateProperty<TextStyle>? tagStyle,
  WidgetStateProperty<double>? borderRadius,
  WidgetStateProperty<double>? borderWidth,
  WidgetStateProperty<BoxDecoration>? decoration,
  WidgetStateProperty<LabelBuilder>? labelBuilder,
  WidgetStateProperty<HelperTextBuilder>? helperTextBuilder,
  WidgetStateProperty<ErrorsBuilder>? errorsBuilder,
}) {
  final newDecorationType = decorationType ?? this.decorationType;
  final newBackgroundColor = backgroundColor ?? this.backgroundColor;
  final newBorderColor = borderColor ?? this.borderColor;
  final newBorderWidth = borderWidth ?? this.borderWidth;
  final newBorderRadius = borderRadius ?? this.borderRadius;
  final newLabelStyle = labelStyle ?? this.labelStyle;
  final newHelperTextStyle = helperTextStyle ?? this.helperTextStyle;
  final newErrorTextStyle = errorTextStyle ?? this.errorTextStyle;
  final newTagStyle = tagStyle ?? this.tagStyle;

  final shouldRebuildDecoration =
      decorationType != null || borderWidth != null || borderRadius != null || backgroundColor != null || borderColor != null;

  final shouldRebuildLabel = labelStyle != null || tagStyle != null || errorTextStyle != null || backgroundColor != null;

  return TInputFieldTheme(
    decorationType: newDecorationType,
    backgroundColor: newBackgroundColor,
    borderColor: newBorderColor,
    labelStyle: newLabelStyle,
    helperTextStyle: newHelperTextStyle,
    errorTextStyle: newErrorTextStyle,
    tagStyle: newTagStyle,
    size: size ?? this.size,
    color: color ?? this.color,
    preWidget: preWidget ?? this.preWidget,
    postWidget: postWidget ?? this.postWidget,
    height: height ?? this.height,
    padding: padding ?? this.padding,
    fontSize: fontSize ?? this.fontSize,
    borderRadius: newBorderRadius,
    borderWidth: newBorderWidth,
    decoration: decoration ??
        (shouldRebuildDecoration
            ? _createDecoration(newDecorationType, newBorderWidth, newBorderRadius, newBackgroundColor, newBorderColor)
            : this.decoration),
    labelBuilder: labelBuilder ??
        (shouldRebuildLabel ? _createLabelBuilder(newLabelStyle, newTagStyle, newErrorTextStyle, newBackgroundColor) : this.labelBuilder),
    helperTextBuilder:
        helperTextBuilder ?? (helperTextStyle != null ? _createHelperTextBuilder(newHelperTextStyle) : this.helperTextBuilder),
    errorsBuilder: errorsBuilder ?? (errorTextStyle != null ? _createErrorsBuilder(newErrorTextStyle) : this.errorsBuilder),
  );
}