Unverified Commit 874804e5 authored by Faisal Ansari's avatar Faisal Ansari Committed by GitHub

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
parent 487d42f9
...@@ -493,6 +493,9 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> { ...@@ -493,6 +493,9 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
void refreshLeadingPadding() { void refreshLeadingPadding() {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) {
return;
}
setState(() { setState(() {
leadingPadding = getWidth(_leadingKey); leadingPadding = getWidth(_leadingKey);
}); });
......
...@@ -1910,6 +1910,34 @@ void main() { ...@@ -1910,6 +1910,34 @@ void main() {
expect(tester.takeException(), isNull); 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 { testWidgets('Menu shows scrollbar when height is limited', (WidgetTester tester) async {
final List<DropdownMenuEntry<TestMenu>> menuItems = <DropdownMenuEntry<TestMenu>>[ final List<DropdownMenuEntry<TestMenu>> menuItems = <DropdownMenuEntry<TestMenu>>[
DropdownMenuEntry<TestMenu>( DropdownMenuEntry<TestMenu>(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment