Unverified Commit 8cbc8492 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix dropdown crash (#69211)

parent e71655b7
......@@ -456,7 +456,9 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
}
void _dismiss() {
navigator?.removeRoute(this);
if (isActive) {
navigator?.removeRoute(this);
}
}
double getItemOffset(int index) {
......
......@@ -2615,4 +2615,52 @@ void main() {
expect(value, equals('two'));
expect(menuItemTapCounters, <int>[0, 2, 1, 0]);
});
testWidgets('does not crash when option is selected without waiting for opening animation to complete', (WidgetTester tester) async {
// Regression test for b/171846624.
final List<String> options = <String>['first', 'second', 'third'];
String? value = options.first;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) => DropdownButton<String>(
value: value,
items: options.map((String s) => DropdownMenuItem<String>(
value: s,
child: Text(s),
)).toList(),
onChanged: (String? v) {
setState(() {
value = v;
});
},
),
),
),
),
);
expect(find.text('first').hitTestable(), findsOneWidget);
expect(find.text('second').hitTestable(), findsNothing);
expect(find.text('third').hitTestable(), findsNothing);
// Open dropdown.
await tester.tap(find.text('first').hitTestable());
await tester.pump();
expect(find.text('third').hitTestable(), findsOneWidget);
expect(find.text('first').hitTestable(), findsOneWidget);
expect(find.text('second').hitTestable(), findsOneWidget);
// Deliberately not waiting for opening animation to complete!
// Select an option in dropdown.
await tester.tap(find.text('third').hitTestable());
await tester.pump();
expect(find.text('third').hitTestable(), findsOneWidget);
expect(find.text('first').hitTestable(), findsNothing);
expect(find.text('second').hitTestable(), findsNothing);
});
}
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