Unverified Commit b6e758ad authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Fixes #138773, port autocomplete to OverlayPortal (#140285)

Fixes #138773, port autocomplete to OverlayPortal
parent b5262f0d
...@@ -126,6 +126,7 @@ class Autocomplete<T extends Object> extends StatelessWidget { ...@@ -126,6 +126,7 @@ class Autocomplete<T extends Object> extends StatelessWidget {
displayStringForOption: displayStringForOption, displayStringForOption: displayStringForOption,
onSelected: onSelected, onSelected: onSelected,
options: options, options: options,
openDirection: optionsViewOpenDirection,
maxOptionsHeight: optionsMaxHeight, maxOptionsHeight: optionsMaxHeight,
); );
}, },
...@@ -166,6 +167,7 @@ class _AutocompleteOptions<T extends Object> extends StatelessWidget { ...@@ -166,6 +167,7 @@ class _AutocompleteOptions<T extends Object> extends StatelessWidget {
super.key, super.key,
required this.displayStringForOption, required this.displayStringForOption,
required this.onSelected, required this.onSelected,
required this.openDirection,
required this.options, required this.options,
required this.maxOptionsHeight, required this.maxOptionsHeight,
}); });
...@@ -173,14 +175,19 @@ class _AutocompleteOptions<T extends Object> extends StatelessWidget { ...@@ -173,14 +175,19 @@ class _AutocompleteOptions<T extends Object> extends StatelessWidget {
final AutocompleteOptionToString<T> displayStringForOption; final AutocompleteOptionToString<T> displayStringForOption;
final AutocompleteOnSelected<T> onSelected; final AutocompleteOnSelected<T> onSelected;
final OptionsViewOpenDirection openDirection;
final Iterable<T> options; final Iterable<T> options;
final double maxOptionsHeight; final double maxOptionsHeight;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final AlignmentDirectional optionsAlignment = switch (openDirection) {
OptionsViewOpenDirection.up => AlignmentDirectional.bottomStart,
OptionsViewOpenDirection.down => AlignmentDirectional.topStart,
};
return Align( return Align(
alignment: Alignment.topLeft, alignment: optionsAlignment,
child: Material( child: Material(
elevation: 4.0, elevation: 4.0,
child: ConstrainedBox( child: ConstrainedBox(
......
...@@ -552,9 +552,11 @@ void main() { ...@@ -552,9 +552,11 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: Autocomplete<String>( body: Center(
optionsViewOpenDirection: OptionsViewOpenDirection.up, child: Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) => <String>['a'], optionsViewOpenDirection: OptionsViewOpenDirection.up,
optionsBuilder: (TextEditingValue textEditingValue) => <String>['aa'],
),
), ),
), ),
), ),
...@@ -562,6 +564,10 @@ void main() { ...@@ -562,6 +564,10 @@ void main() {
final OptionsViewOpenDirection actual = tester.widget<RawAutocomplete<String>>(find.byType(RawAutocomplete<String>)) final OptionsViewOpenDirection actual = tester.widget<RawAutocomplete<String>>(find.byType(RawAutocomplete<String>))
.optionsViewOpenDirection; .optionsViewOpenDirection;
expect(actual, equals(OptionsViewOpenDirection.up)); expect(actual, equals(OptionsViewOpenDirection.up));
await tester.tap(find.byType(RawAutocomplete<String>));
await tester.enterText(find.byType(RawAutocomplete<String>), 'a');
expect(find.text('aa').hitTestable(), findsOneWidget);
}); });
}); });
} }
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