Skip to content

Commit

Permalink
Merge pull request #315 from AhmedLSayed9/add_copy_with_method_for_st…
Browse files Browse the repository at this point in the history
…yle_data_classes

Add copyWith method for style data classes
  • Loading branch information
AhmedLSayed9 authored Sep 8, 2024
2 parents b474e80 + 5c14cfe commit 8dabea8
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions packages/dropdown_button2/lib/src/dropdown_style_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ class ButtonStyleData {
/// match a component's state:
/// <https://material.io/design/interaction/states.html#anatomy>.
final MaterialStateProperty<Color?>? overlayColor;

/// Create a clone of the current [ButtonStyleData] but with the provided
/// parameters overridden.
ButtonStyleData copyWith({
double? height,
double? width,
EdgeInsetsGeometry? padding,
BoxDecoration? decoration,
BoxDecoration? foregroundDecoration,
int? elevation,
MaterialStateProperty<Color?>? overlayColor,
}) {
return ButtonStyleData(
height: height ?? this.height,
width: width ?? this.width,
padding: padding ?? this.padding,
decoration: decoration ?? this.decoration,
foregroundDecoration: foregroundDecoration ?? this.foregroundDecoration,
elevation: elevation ?? this.elevation,
overlayColor: overlayColor ?? this.overlayColor,
);
}
}

/// A class to configure the theme of the button's icon.
Expand Down Expand Up @@ -97,6 +119,24 @@ class IconStyleData {

/// Shows different icon when dropdown menu is open
final Widget? openMenuIcon;

/// Create a clone of the current [IconStyleData] but with the provided
/// parameters overridden.
IconStyleData copyWith({
Widget? icon,
Color? iconDisabledColor,
Color? iconEnabledColor,
double? iconSize,
Widget? openMenuIcon,
}) {
return IconStyleData(
icon: icon ?? this.icon,
iconDisabledColor: iconDisabledColor ?? this.iconDisabledColor,
iconEnabledColor: iconEnabledColor ?? this.iconEnabledColor,
iconSize: iconSize ?? this.iconSize,
openMenuIcon: openMenuIcon ?? this.openMenuIcon,
);
}
}

/// A class to configure the theme of the dropdown menu.
Expand Down Expand Up @@ -205,6 +245,44 @@ class DropdownStyleData {
/// },
/// ```
final DropdownBuilder? dropdownBuilder;

/// Create a clone of the current [DropdownStyleData] but with the provided
/// parameters overridden.
DropdownStyleData copyWith({
double? maxHeight,
double? width,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? scrollPadding,
BoxDecoration? decoration,
int? elevation,
DropdownDirection? direction,
Offset? offset,
bool? isOverButton,
bool? useSafeArea,
bool? isFullScreen,
bool? useRootNavigator,
ScrollbarThemeData? scrollbarTheme,
Interval? openInterval,
DropdownBuilder? dropdownBuilder,
}) {
return DropdownStyleData(
maxHeight: maxHeight ?? this.maxHeight,
width: width ?? this.width,
padding: padding ?? this.padding,
scrollPadding: scrollPadding ?? this.scrollPadding,
decoration: decoration ?? this.decoration,
elevation: elevation ?? this.elevation,
direction: direction ?? this.direction,
offset: offset ?? this.offset,
isOverButton: isOverButton ?? this.isOverButton,
useSafeArea: useSafeArea ?? this.useSafeArea,
isFullScreen: isFullScreen ?? this.isFullScreen,
useRootNavigator: useRootNavigator ?? this.useRootNavigator,
scrollbarTheme: scrollbarTheme ?? this.scrollbarTheme,
openInterval: openInterval ?? this.openInterval,
dropdownBuilder: dropdownBuilder ?? this.dropdownBuilder,
);
}
}

/// A class to configure the theme of the dropdown menu items.
Expand Down Expand Up @@ -267,6 +345,23 @@ class MenuItemStyleData {
/// },
/// ```
final SelectedMenuItemBuilder? selectedMenuItemBuilder;

/// Create a clone of the current [MenuItemStyleData] but with the provided
/// parameters overridden.
MenuItemStyleData copyWith({
EdgeInsetsGeometry? padding,
BorderRadius? borderRadius,
MaterialStateProperty<Color?>? overlayColor,
SelectedMenuItemBuilder? selectedMenuItemBuilder,
}) {
return MenuItemStyleData(
padding: padding ?? this.padding,
borderRadius: borderRadius ?? this.borderRadius,
overlayColor: overlayColor ?? this.overlayColor,
selectedMenuItemBuilder:
selectedMenuItemBuilder ?? this.selectedMenuItemBuilder,
);
}
}

/// A class to configure searchable dropdowns.
Expand Down Expand Up @@ -306,4 +401,23 @@ class DropdownSearchData<T> {
/// item.value.toString().toLowerCase().contains(searchValue.toLowerCase());
/// ```
final SearchMatchFn<T>? searchMatchFn;

/// Create a clone of the current [DropdownSearchData] but with the provided
/// parameters overridden.
DropdownSearchData<T> copyWith({
TextEditingController? searchController,
Widget? searchBarWidget,
double? searchBarWidgetHeight,
Widget? noResultsWidget,
SearchMatchFn<T>? searchMatchFn,
}) {
return DropdownSearchData<T>(
searchController: searchController ?? this.searchController,
searchBarWidget: searchBarWidget ?? this.searchBarWidget,
searchBarWidgetHeight:
searchBarWidgetHeight ?? this.searchBarWidgetHeight,
noResultsWidget: noResultsWidget ?? this.noResultsWidget,
searchMatchFn: searchMatchFn ?? this.searchMatchFn,
);
}
}

0 comments on commit 8dabea8

Please sign in to comment.