Fixed -> DropdownMenu throws exception when it is in any scrollable l… (#140566)

Fixed -> DropdownMenu throws exception when it is in any scrollable list view and scrolls quickly #139871
This commit is contained in:
Faisal Ansari 2024-03-08 02:16:03 +05:30 committed by GitHub
parent 487d42f9ee
commit 874804e511
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View file

@ -493,6 +493,9 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
void refreshLeadingPadding() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
setState(() {
leadingPadding = getWidth(_leadingKey);
});

View file

@ -1910,6 +1910,34 @@ void main() {
expect(tester.takeException(), isNull);
});
// Regression test for https://github.com/flutter/flutter/issues/139871.
testWidgets('setState is not called through addPostFrameCallback after DropdownMenu is unmounted', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ListView.builder(
itemCount: 500,
itemBuilder: (BuildContext context, int index) {
if (index == 250) {
return DropdownMenu<TestMenu>(
dropdownMenuEntries: menuChildren,
);
} else {
return Container(height: 50);
}
},
),
),
),
);
await tester.fling(find.byType(ListView), const Offset(0, -20000), 200000.0);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
testWidgets('Menu shows scrollbar when height is limited', (WidgetTester tester) async {
final List<DropdownMenuEntry<TestMenu>> menuItems = <DropdownMenuEntry<TestMenu>>[
DropdownMenuEntry<TestMenu>(