Skip to content

Commit 80633c6

Browse files
authored
Merge pull request #438 from AhmedLSayed9/inherit_local_input_decoration_theme
Inherit local InputDecorationTheme (contentPadding, border, visualDensity) instead of only the global theme
2 parents e0f6ce7 + ba8b187 commit 80633c6

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Re-lay out dropdown menu on ancestor scroll.
1010
- Add `barrierBlocksInteraction` to allow interaction with underlying widgets while the dropdown menu is open.
1111
- Properly dispose internal FocusNode when replaced by an external FocusNode.
12+
- Inherit local `InputDecorationTheme` (contentPadding, border, visualDensity) instead of only the global theme.
1213

1314
## 3.0.0
1415

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,23 +633,24 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
633633
EdgeInsets? _getInputDecorationPadding() {
634634
// Return the contentPadding only if inputDecoration is defined.
635635
if (widget._inputDecoration case final decoration?) {
636-
final ThemeData theme = Theme.of(context);
636+
final InputDecorationThemeData inputDecorationTheme = InputDecorationTheme.of(context);
637637
final TextDirection? textDirection = Directionality.maybeOf(context);
638638

639639
final EdgeInsets? contentPadding =
640-
(decoration.contentPadding ?? theme.inputDecorationTheme.contentPadding)?.resolve(
640+
(decoration.contentPadding ?? inputDecorationTheme.contentPadding)?.resolve(
641641
textDirection,
642642
);
643643

644644
// InputDecorator adds gapPadding horizontally for OutlineInputBorder.
645-
final border = decoration.border ?? theme.inputDecorationTheme.border;
645+
final border = decoration.border ?? inputDecorationTheme.border;
646646
final double gapPadding = switch (border) {
647647
OutlineInputBorder(:final gapPadding) => gapPadding,
648648
_ => 0.0,
649649
};
650650

651-
// Use inputDecorationTheme.visualDensity when added (https://github.com/flutter/flutter/issues/166201#issuecomment-2774622584)
652-
final Offset densityOffset = theme.visualDensity.baseSizeAdjustment;
651+
final Offset densityOffset =
652+
(inputDecorationTheme.visualDensity ?? Theme.of(context).visualDensity)
653+
.baseSizeAdjustment;
653654

654655
return contentPadding?.copyWith(
655656
left: contentPadding.left + gapPadding,
@@ -1148,7 +1149,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
11481149
final _DropdownButtonFormField2State<T> state =
11491150
field as _DropdownButtonFormField2State<T>;
11501151
InputDecoration effectiveDecoration = (decoration ?? const InputDecoration())
1151-
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
1152+
.applyDefaults(InputDecorationTheme.of(field.context));
11521153

11531154
final bool showSelectedItem =
11541155
items != null &&

0 commit comments

Comments
 (0)