refactor(ui_components): add CopyWith method in ThemeStyle
This commit is contained in:
		
							parent
							
								
									4030511f4a
								
							
						
					
					
						commit
						cae4b68046
					
				| @ -107,6 +107,30 @@ class FileSelectionButtonStyle extends ButtonStyle<FileSelectionButtonStyle> { | ||||
|   final TextStyle? subTitle; | ||||
| 
 | ||||
|   @override | ||||
|   FileSelectionButtonStyle mergeWith(FileSelectionButtonStyle? other) => | ||||
|       FileSelectionButtonStyle.merge(this, other)!; | ||||
|   FileSelectionButtonStyle? mergeWith(FileSelectionButtonStyle? other) => | ||||
|       FileSelectionButtonStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   FileSelectionButtonStyle? copyWith({ | ||||
|     TextStyle? title, | ||||
|     TextStyle? subTitle, | ||||
|     BorderRadiusGeometry? radius, | ||||
|     EdgeInsetsGeometry? padding, | ||||
|     MultiColor? foregroundColors, | ||||
|     MultiColor? backgroundColors, | ||||
|     MultiColor? borderColors, | ||||
|     double? stroke, | ||||
|     BoxShadow? shadow, | ||||
|   }) => | ||||
|       FileSelectionButtonStyle( | ||||
|         title: title ?? this.title, | ||||
|         subTitle: subTitle ?? this.subTitle, | ||||
|         radius: radius ?? this.radius, | ||||
|         padding: padding ?? this.padding, | ||||
|         foregroundColors: foregroundColors ?? this.foregroundColors, | ||||
|         backgroundColors: backgroundColors ?? this.backgroundColors, | ||||
|         borderColors: borderColors ?? this.borderColors, | ||||
|         stroke: stroke ?? this.stroke, | ||||
|         shadow: shadow ?? this.shadow, | ||||
|       ); | ||||
| } | ||||
|  | ||||
| @ -99,6 +99,28 @@ class FlatButtonStyle extends ButtonStyle<FlatButtonStyle> { | ||||
|   final TextStyle? label; | ||||
| 
 | ||||
|   @override | ||||
|   FlatButtonStyle mergeWith(FlatButtonStyle? other) => | ||||
|       FlatButtonStyle.merge(this, other)!; | ||||
|   FlatButtonStyle? mergeWith(FlatButtonStyle? other) => | ||||
|       FlatButtonStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   FlatButtonStyle? copyWith({ | ||||
|     TextStyle? label, | ||||
|     BorderRadiusGeometry? radius, | ||||
|     EdgeInsetsGeometry? padding, | ||||
|     MultiColor? foregroundColors, | ||||
|     MultiColor? backgroundColors, | ||||
|     MultiColor? borderColors, | ||||
|     double? stroke, | ||||
|     BoxShadow? shadow, | ||||
|   }) => | ||||
|       FlatButtonStyle( | ||||
|         label: label ?? this.label, | ||||
|         radius: radius ?? this.radius, | ||||
|         padding: padding ?? this.padding, | ||||
|         foregroundColors: foregroundColors ?? this.foregroundColors, | ||||
|         backgroundColors: backgroundColors ?? this.backgroundColors, | ||||
|         borderColors: borderColors ?? this.borderColors, | ||||
|         stroke: stroke ?? this.stroke, | ||||
|         shadow: shadow ?? this.shadow, | ||||
|       ); | ||||
| } | ||||
|  | ||||
| @ -99,6 +99,28 @@ class SimpleIconButtonStyle extends ButtonStyle<SimpleIconButtonStyle> { | ||||
|   final double? dimension; | ||||
| 
 | ||||
|   @override | ||||
|   SimpleIconButtonStyle mergeWith(SimpleIconButtonStyle? other) => | ||||
|       SimpleIconButtonStyle.merge(this, other)!; | ||||
|   SimpleIconButtonStyle? mergeWith(SimpleIconButtonStyle? other) => | ||||
|       SimpleIconButtonStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   SimpleIconButtonStyle copyWith({ | ||||
|     double? dimension, | ||||
|     BorderRadiusGeometry? radius, | ||||
|     EdgeInsetsGeometry? padding, | ||||
|     MultiColor? foregroundColors, | ||||
|     MultiColor? backgroundColors, | ||||
|     MultiColor? borderColors, | ||||
|     double? stroke, | ||||
|     BoxShadow? shadow, | ||||
|   }) => | ||||
|       SimpleIconButtonStyle( | ||||
|         dimension: dimension ?? this.dimension, | ||||
|         radius: radius ?? this.radius, | ||||
|         padding: padding ?? this.padding, | ||||
|         foregroundColors: foregroundColors ?? this.foregroundColors, | ||||
|         backgroundColors: backgroundColors ?? this.backgroundColors, | ||||
|         borderColors: borderColors ?? this.borderColors, | ||||
|         stroke: stroke ?? this.stroke, | ||||
|         shadow: shadow ?? this.shadow, | ||||
|       ); | ||||
| } | ||||
|  | ||||
| @ -107,6 +107,30 @@ class SymbolButtonStyle extends ButtonStyle<SymbolButtonStyle> { | ||||
|   final double? dimension; | ||||
| 
 | ||||
|   @override | ||||
|   SymbolButtonStyle mergeWith(SymbolButtonStyle? other) => | ||||
|       SymbolButtonStyle.merge(this, other)!; | ||||
|   SymbolButtonStyle? mergeWith(SymbolButtonStyle? other) => | ||||
|       SymbolButtonStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   SymbolButtonStyle? copyWith({ | ||||
|     TextStyle? label, | ||||
|     double? dimension, | ||||
|     BorderRadiusGeometry? radius, | ||||
|     EdgeInsetsGeometry? padding, | ||||
|     MultiColor? foregroundColors, | ||||
|     MultiColor? backgroundColors, | ||||
|     MultiColor? borderColors, | ||||
|     double? stroke, | ||||
|     BoxShadow? shadow, | ||||
|   }) => | ||||
|       SymbolButtonStyle( | ||||
|         label: label ?? this.label, | ||||
|         dimension: dimension ?? this.dimension, | ||||
|         radius: radius ?? this.radius, | ||||
|         padding: padding ?? this.padding, | ||||
|         foregroundColors: foregroundColors ?? this.foregroundColors, | ||||
|         backgroundColors: backgroundColors ?? this.backgroundColors, | ||||
|         borderColors: borderColors ?? this.borderColors, | ||||
|         stroke: stroke ?? this.stroke, | ||||
|         shadow: shadow ?? this.shadow, | ||||
|       ); | ||||
| } | ||||
|  | ||||
| @ -68,7 +68,17 @@ class LoaderStyle extends ThemeStyle<LoaderStyle> { | ||||
|   final double? stroke; | ||||
| 
 | ||||
|   @override | ||||
|   LoaderStyle mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other)!; | ||||
|   LoaderStyle? mergeWith(LoaderStyle? other) => LoaderStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   LoaderStyle copyWith({ | ||||
|     MultiColor? colors, | ||||
|     double? stroke, | ||||
|   }) => | ||||
|       LoaderStyle( | ||||
|         colors: colors ?? this.colors, | ||||
|         stroke: stroke ?? this.stroke, | ||||
|       ); | ||||
| 
 | ||||
|   @override | ||||
|   String toString() => 'LoaderStyle($colors, $stroke)'; | ||||
|  | ||||
| @ -67,6 +67,16 @@ class RichTextBuilderStyle extends ThemeStyle<RichTextBuilderStyle> { | ||||
|   final Map<String, TextStyle>? styles; | ||||
| 
 | ||||
|   @override | ||||
|   RichTextBuilderStyle mergeWith(RichTextBuilderStyle? other) => | ||||
|       RichTextBuilderStyle.merge(this, other)!; | ||||
|   RichTextBuilderStyle? mergeWith(RichTextBuilderStyle? other) => | ||||
|       RichTextBuilderStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   RichTextBuilderStyle? copyWith({ | ||||
|     TextStyle? defaultStyle, | ||||
|     Map<String, TextStyle>? styles, | ||||
|   }) => | ||||
|       RichTextBuilderStyle( | ||||
|         defaultStyle: defaultStyle ?? this.defaultStyle, | ||||
|         styles: styles ?? this.styles, | ||||
|       ); | ||||
| } | ||||
|  | ||||
| @ -58,19 +58,19 @@ class TextInputStyle extends ThemeStyle<TextInputStyle> { | ||||
|     if (a == null) { | ||||
|       return b.copyWith(); | ||||
|     } | ||||
|     return a.copyWith( | ||||
|       labelStyle: b.labelStyle, | ||||
|       hintStyle: b.hintStyle, | ||||
|       backgroundColors: b.backgroundColors, | ||||
|       borderColors: b.borderColors, | ||||
|       boxShadow: b.boxShadow, | ||||
|       radius: b.radius, | ||||
|       inputStyle: b.inputStyle, | ||||
|       iconColor: b.iconColor, | ||||
|       prefixStyle: b.prefixStyle, | ||||
|       prefixIconColor: b.prefixIconColor, | ||||
|       suffixIconColor: b.suffixIconColor, | ||||
|       suffixStyle: b.suffixStyle, | ||||
|     return b.copyWith( | ||||
|       labelStyle: a.labelStyle, | ||||
|       hintStyle: a.hintStyle, | ||||
|       backgroundColors: a.backgroundColors, | ||||
|       borderColors: a.borderColors, | ||||
|       boxShadow: a.boxShadow, | ||||
|       radius: a.radius, | ||||
|       inputStyle: a.inputStyle, | ||||
|       iconColor: a.iconColor, | ||||
|       prefixStyle: a.prefixStyle, | ||||
|       prefixIconColor: a.prefixIconColor, | ||||
|       suffixIconColor: a.suffixIconColor, | ||||
|       suffixStyle: a.suffixStyle, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
| @ -103,4 +103,34 @@ class TextInputStyle extends ThemeStyle<TextInputStyle> { | ||||
|   @override | ||||
|   TextInputStyle? mergeWith(TextInputStyle? other) => | ||||
|       TextInputStyle.merge(this, other); | ||||
| 
 | ||||
|   @override | ||||
|   TextInputStyle copyWith({ | ||||
|     TextStyle? labelStyle, | ||||
|     TextStyle? hintStyle, | ||||
|     MultiColor? backgroundColors, | ||||
|     MultiColor? borderColors, | ||||
|     BoxShadow? boxShadow, | ||||
|     BorderRadiusGeometry? radius, | ||||
|     TextStyle? inputStyle, | ||||
|     Color? iconColor, | ||||
|     TextStyle? prefixStyle, | ||||
|     Color? prefixIconColor, | ||||
|     TextStyle? suffixStyle, | ||||
|     Color? suffixIconColor, | ||||
|   }) => | ||||
|       TextInputStyle( | ||||
|         labelStyle: labelStyle ?? this.labelStyle, | ||||
|         hintStyle: hintStyle ?? this.hintStyle, | ||||
|         backgroundColors: backgroundColors ?? this.backgroundColors, | ||||
|         radius: radius ?? this.radius, | ||||
|         borderColors: borderColors ?? this.borderColors, | ||||
|         boxShadow: boxShadow ?? this.boxShadow, | ||||
|         inputStyle: inputStyle ?? this.inputStyle, | ||||
|         prefixStyle: prefixStyle ?? this.prefixStyle, | ||||
|         suffixStyle: suffixStyle ?? this.suffixStyle, | ||||
|         prefixIconColor: prefixIconColor ?? this.prefixIconColor, | ||||
|         suffixIconColor: suffixIconColor ?? this.suffixIconColor, | ||||
|         iconColor: iconColor ?? this.iconColor, | ||||
|       ); | ||||
| } | ||||
|  | ||||
| @ -19,4 +19,7 @@ abstract class ThemeStyle<T> { | ||||
| 
 | ||||
|   /// Merges non-null `other` attributes in `this` and returns a copy. | ||||
|   T? mergeWith(T? other); | ||||
| 
 | ||||
|   /// Copy with (mandatory for mergeWith, needs to be simple and ignore `null`) | ||||
|   T? copyWith(); | ||||
| } | ||||
|  | ||||
| @ -15,11 +15,13 @@ dependencies: | ||||
|     git: | ||||
|       url: ssh://git@git.wyatt-studio.fr:993/Wyatt-FOSS/wyatt-packages.git | ||||
|       path: packages/wyatt_component_copy_with_extension | ||||
|   freezed_annotation: ^2.2.0 | ||||
| 
 | ||||
| dev_dependencies: | ||||
|   build_runner: ^2.3.3 | ||||
|   copy_with_extension_gen: ^5.0.0 | ||||
|   flutter_test: { sdk: flutter } | ||||
|   freezed: ^2.3.2 | ||||
|   wyatt_analysis: | ||||
|     hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub | ||||
|     version: ^2.4.0 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user