Skip to content

Commit b025e38

Browse files
authored
fix a throw due to double precison (flutter#92486)
1 parent 9afb45a commit b025e38

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/flutter/lib/src/material/dropdown.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
577577
scrollOffset = math.min(scrollOffset, preferredMenuHeight - menuHeight);
578578
}
579579

580-
assert(menuHeight == menuBottom - menuTop);
580+
assert((menuBottom - menuTop - menuHeight).abs() < precisionErrorTolerance);
581581
return _MenuLimits(menuTop, menuBottom, menuHeight, scrollOffset);
582582
}
583583
}

packages/flutter/test/material/dropdown_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,4 +3595,39 @@ void main() {
35953595
}
35963596
}
35973597
});
3598+
3599+
// Regression test for https://github.com/flutter/flutter/issues/92438
3600+
testWidgets('Do not throw due to the double precision', (WidgetTester tester) async {
3601+
const String value = 'One';
3602+
const double itemHeight = 77.701;
3603+
final List<DropdownMenuItem<String>> menuItems = <String>[
3604+
value,
3605+
'Two',
3606+
'Free',
3607+
].map<DropdownMenuItem<String>>((String value) {
3608+
return DropdownMenuItem<String>(
3609+
value: value,
3610+
child: Text(value),
3611+
);
3612+
}).toList();
3613+
await tester.pumpWidget(
3614+
MaterialApp(
3615+
home: Scaffold(
3616+
body: Center(
3617+
child: DropdownButton<String>(
3618+
value: value,
3619+
itemHeight: itemHeight,
3620+
onChanged: (_) {},
3621+
items: menuItems,
3622+
),
3623+
),
3624+
),
3625+
),
3626+
);
3627+
3628+
await tester.tap(find.text(value));
3629+
await tester.pumpAndSettle();
3630+
3631+
expect(tester.takeException(), null);
3632+
});
35983633
}

0 commit comments

Comments
 (0)