Fix dropdown crash (#69211)
This commit is contained in:
parent
e71655b7e9
commit
8cbc849222
@ -456,7 +456,9 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _dismiss() {
|
void _dismiss() {
|
||||||
navigator?.removeRoute(this);
|
if (isActive) {
|
||||||
|
navigator?.removeRoute(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double getItemOffset(int index) {
|
double getItemOffset(int index) {
|
||||||
|
@ -2615,4 +2615,52 @@ void main() {
|
|||||||
expect(value, equals('two'));
|
expect(value, equals('two'));
|
||||||
expect(menuItemTapCounters, <int>[0, 2, 1, 0]);
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user