Skip to content

Commit b7e6337

Browse files
authored
Merge pull request #396 from AhmedLSayed9/fix_incorrect_dropdown_position_on_web
Fix incorrect dropdown position when resizing the window rapidly on web
2 parents 6413452 + 005498e commit b7e6337

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## UNRELEASED
22

3-
- Avoid dropdown internal FocusNode listener leak when replaced by an external FocusNode
3+
- Avoid dropdown internal FocusNode listener leak when replaced by an external FocusNode.
4+
- Fix incorrect dropdown position when resizing the window rapidly on web, closes #395.
45

56
## 3.0.0-beta.22
67

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,17 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
546546

547547
@override
548548
void didChangeMetrics() {
549-
//This fix the bug of calling didChangeMetrics() on iOS when app starts
549+
// This fixes the bug of calling didChangeMetrics() on iOS when app starts.
550550
if (_buttonRect.value == null) {
551551
return;
552552
}
553-
_buttonRect.value = _getButtonRect();
553+
554+
// Defer rect calculation to next frame to ensure layout is complete and dimensions are accurate.
555+
WidgetsBinding.instance.addPostFrameCallback((_) {
556+
if (mounted && _buttonRectKey.currentContext != null) {
557+
_buttonRect.value = _getButtonRect();
558+
}
559+
});
554560
}
555561

556562
TextStyle? get _textStyle => widget.style ?? Theme.of(context).textTheme.titleMedium;

0 commit comments

Comments
 (0)