Skip to content

Commit 95c0ec5

Browse files
authored
Merge pull request #357 from AhmedLSayed9/use_decoration_hint_text_for_dropdown
Use decoration hint text as the default value for dropdown button hin…
2 parents 7c2fb6b + 014c02b commit 95c0ec5

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Add semantics to dropdown menu items [Flutter core].
1111
- Support helperStyle/helperMaxLines/errorMaxLines for DropdownButtonFormField2.
1212
- Add `MenuItemStyleData.useDecorationHorizontalPadding`, used to determine whether to use the horizontal padding from "decoration.contentPadding" for menu items when using `DropdownButtonFormField2`.
13+
- Use decoration hint text as the default value for dropdown button hints [Flutter core].
1314

1415
## 3.0.0-beta.21
1516

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,18 +1044,24 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10441044
items
10451045
.where((DropdownItem<T> item) => item.value == state.value)
10461046
.isNotEmpty;
1047-
bool isHintOrDisabledHintAvailable() {
1048-
final bool isDropdownDisabled =
1049-
onChanged == null || (items == null || items.isEmpty);
1050-
if (isDropdownDisabled) {
1051-
return hint != null || disabledHint != null;
1052-
} else {
1053-
return hint != null;
1054-
}
1055-
}
1056-
1047+
final bool isDropdownEnabled =
1048+
onChanged != null && items != null && items.isNotEmpty;
1049+
// If decoration hintText is provided, use it as the default value for both hint and disabledHint.
1050+
final Widget? decorationHint = effectiveDecoration.hintText != null
1051+
? Text(
1052+
effectiveDecoration.hintText!,
1053+
style: effectiveDecoration.hintStyle,
1054+
textDirection: effectiveDecoration.hintTextDirection,
1055+
maxLines: effectiveDecoration.hintMaxLines,
1056+
)
1057+
: null;
1058+
final Widget? effectiveHint = hint ?? decorationHint;
1059+
final Widget? effectiveDisabledHint = disabledHint ?? effectiveHint;
1060+
final bool isHintOrDisabledHintAvailable = isDropdownEnabled
1061+
? effectiveHint != null
1062+
: effectiveHint != null || effectiveDisabledHint != null;
10571063
final bool isEmpty =
1058-
!showSelectedItem && !isHintOrDisabledHintAvailable();
1064+
!showSelectedItem && !isHintOrDisabledHintAvailable;
10591065

10601066
// An unFocusable Focus widget so that this widget can detect if its
10611067
// descendants have focus or not.
@@ -1068,8 +1074,8 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10681074
selectedItemBuilder: selectedItemBuilder,
10691075
valueListenable: valueListenable,
10701076
multiValueListenable: multiValueListenable,
1071-
hint: hint,
1072-
disabledHint: disabledHint,
1077+
hint: effectiveHint,
1078+
disabledHint: effectiveDisabledHint,
10731079
onChanged: onChanged == null ? null : state.didChange,
10741080
onMenuStateChange: onMenuStateChange,
10751081
style: style,

0 commit comments

Comments
 (0)