diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index d51516598b..c1392cdf4b 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -3547,6 +3547,121 @@ class InputDecorationTheme extends Diagnosticable { /// behavior of aligning the label with the center of the [TextField]. final bool alignLabelWithHint; + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + InputDecorationTheme copyWith({ + TextStyle labelStyle, + TextStyle helperStyle, + TextStyle hintStyle, + TextStyle errorStyle, + int errorMaxLines, + bool hasFloatingPlaceholder, + bool isDense, + EdgeInsetsGeometry contentPadding, + bool isCollapsed, + TextStyle prefixStyle, + TextStyle suffixStyle, + TextStyle counterStyle, + bool filled, + Color fillColor, + Color focusColor, + Color hoverColor, + InputBorder errorBorder, + InputBorder focusedBorder, + InputBorder focusedErrorBorder, + InputBorder disabledBorder, + InputBorder enabledBorder, + InputBorder border, + bool alignLabelWithHint, + }) { + return InputDecorationTheme( + labelStyle: labelStyle ?? this.labelStyle, + helperStyle: helperStyle ?? this.helperStyle, + hintStyle: hintStyle ?? this.hintStyle, + errorStyle: errorStyle ?? this.errorStyle, + errorMaxLines: errorMaxLines ?? this.errorMaxLines, + hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder, + isDense: isDense ?? this.isDense, + contentPadding: contentPadding ?? this.contentPadding, + isCollapsed: isCollapsed ?? this.isCollapsed, + prefixStyle: prefixStyle ?? this.prefixStyle, + suffixStyle: suffixStyle ?? this.suffixStyle, + counterStyle: counterStyle ?? this.counterStyle, + filled: filled ?? this.filled, + fillColor: fillColor ?? this.fillColor, + focusColor: focusColor ?? this.focusColor, + hoverColor: hoverColor ?? this.hoverColor, + errorBorder: errorBorder ?? this.errorBorder, + focusedBorder: focusedBorder ?? this.focusedBorder, + focusedErrorBorder: focusedErrorBorder ?? this.focusedErrorBorder, + disabledBorder: disabledBorder ?? this.disabledBorder, + enabledBorder: enabledBorder ?? this.enabledBorder, + border: border ?? this.border, + alignLabelWithHint: alignLabelWithHint ?? this.alignLabelWithHint, + ); + } + + @override + int get hashCode { + return hashList([ + labelStyle, + helperStyle, + hintStyle, + errorStyle, + errorMaxLines, + hasFloatingPlaceholder, + isDense, + contentPadding, + isCollapsed, + prefixStyle, + suffixStyle, + counterStyle, + filled, + fillColor, + focusColor, + hoverColor, + errorBorder, + focusedBorder, + focusedErrorBorder, + disabledBorder, + enabledBorder, + border, + alignLabelWithHint, + ]); + } + + @override + bool operator==(Object other) { + if (identical(this, other)) + return true; + if (other.runtimeType != runtimeType) + return false; + final InputDecorationTheme typedOther = other; + return typedOther.labelStyle == labelStyle + && typedOther.helperStyle == helperStyle + && typedOther.hintStyle == hintStyle + && typedOther.errorStyle == errorStyle + && typedOther.errorMaxLines == errorMaxLines + && typedOther.isDense == isDense + && typedOther.contentPadding == contentPadding + && typedOther.isCollapsed == isCollapsed + && typedOther.prefixStyle == prefixStyle + && typedOther.suffixStyle == suffixStyle + && typedOther.counterStyle == counterStyle + && typedOther.filled == filled + && typedOther.fillColor == fillColor + && typedOther.focusColor == focusColor + && typedOther.hoverColor == hoverColor + && typedOther.errorBorder == errorBorder + && typedOther.focusedBorder == focusedBorder + && typedOther.focusedErrorBorder == focusedErrorBorder + && typedOther.disabledBorder == disabledBorder + && typedOther.enabledBorder == enabledBorder + && typedOther.border == border + && typedOther.alignLabelWithHint == alignLabelWithHint + && typedOther.disabledBorder == disabledBorder; + } + @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 405182550d..ad5739a377 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -2424,6 +2424,27 @@ void main() { expect(getOpacity(tester, 'label'), 0.0); }, skip: isBrowser); + test('InputDecorationTheme copyWith, ==, hashCode basics', () { + expect(const InputDecorationTheme(), const InputDecorationTheme().copyWith()); + expect(const InputDecorationTheme().hashCode, const InputDecorationTheme().copyWith().hashCode); + }); + + test('InputDecorationTheme copyWith correctly copies and replaces values', () { + const InputDecorationTheme original = InputDecorationTheme( + focusColor: Colors.orange, + fillColor: Colors.green, + ); + final InputDecorationTheme copy = original.copyWith( + focusColor: Colors.yellow, + fillColor: Colors.blue, + ); + + expect(original.focusColor, Colors.orange); + expect(original.fillColor, Colors.green); + expect(copy.focusColor, Colors.yellow); + expect(copy.fillColor, Colors.blue); + }); + testWidgets('InputDecorationTheme outline border', (WidgetTester tester) async { await tester.pumpWidget( buildInputDecorator(