Unverified Commit 0a461894 authored by YeungKC's avatar YeungKC Committed by GitHub

Improve Dropdown Menu (#74906)

parent 9fd3c22e
......@@ -290,19 +290,13 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
behavior: const _DropdownScrollBehavior(),
child: PrimaryScrollController(
controller: widget.route.scrollController!,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final double menuTotalHeight = widget.route.itemHeights.reduce((double total, double height) => total + height);
final bool isScrollable = kMaterialListPadding.vertical + menuTotalHeight > constraints.maxHeight;
return Scrollbar(
isAlwaysShown: isScrollable,
child: Scrollbar(
isAlwaysShown: true,
child: ListView(
padding: kMaterialListPadding,
shrinkWrap: true,
children: children,
),
);
},
),
),
),
......
......@@ -2923,13 +2923,31 @@ void main() {
testWidgets('Dropdown menu should persistently show a scrollbar if it is scrollable', (WidgetTester tester) async {
await tester.pumpWidget(buildFrame(
value: '0',
// menu is short enough to fit onto the screen.
items: List<String>.generate(/*length=*/10, (int index) => index.toString()),
onChanged: onChanged,
));
await tester.tap(find.text('0'));
await tester.pumpAndSettle();
ScrollController scrollController = PrimaryScrollController.of(tester.element(find.byType(ListView)))!;
// The scrollbar shouldn't show if the list fits into the screen.
expect(scrollController.position.maxScrollExtent, 0);
expect(find.byType(Scrollbar), isNot(paints..rect()));
await tester.tap(find.text('0').last);
await tester.pumpAndSettle();
await tester.pumpWidget(buildFrame(
value: '0',
// menu is too long to fit onto the screen.
items: List<String>.generate(/*length=*/100, (int index) => index.toString()),
onChanged: onChanged,
));
await tester.tap(find.text('0'));
await tester.pumpAndSettle();
final ScrollController scrollController = PrimaryScrollController.of(tester.element(find.byType(ListView)))!;
scrollController = PrimaryScrollController.of(tester.element(find.byType(ListView)))!;
// The scrollbar is shown when the list is longer than the height of the screen.
expect(scrollController.position.maxScrollExtent > 0, isTrue);
expect(find.byType(Scrollbar), paints..rect());
});
......
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