diff --git a/packages/dropdown_button2/lib/src/dropdown_style_data.dart b/packages/dropdown_button2/lib/src/dropdown_style_data.dart index 9a02b6a..9702c1e 100644 --- a/packages/dropdown_button2/lib/src/dropdown_style_data.dart +++ b/packages/dropdown_button2/lib/src/dropdown_style_data.dart @@ -56,6 +56,28 @@ class ButtonStyleData { /// match a component's state: /// . final MaterialStateProperty? 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? 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. @@ -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. @@ -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. @@ -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? 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. @@ -306,4 +401,23 @@ class DropdownSearchData { /// item.value.toString().toLowerCase().contains(searchValue.toLowerCase()); /// ``` final SearchMatchFn? searchMatchFn; + + /// Create a clone of the current [DropdownSearchData] but with the provided + /// parameters overridden. + DropdownSearchData copyWith({ + TextEditingController? searchController, + Widget? searchBarWidget, + double? searchBarWidgetHeight, + Widget? noResultsWidget, + SearchMatchFn? searchMatchFn, + }) { + return DropdownSearchData( + searchController: searchController ?? this.searchController, + searchBarWidget: searchBarWidget ?? this.searchBarWidget, + searchBarWidgetHeight: + searchBarWidgetHeight ?? this.searchBarWidgetHeight, + noResultsWidget: noResultsWidget ?? this.noResultsWidget, + searchMatchFn: searchMatchFn ?? this.searchMatchFn, + ); + } }