add ScrollViewKeyboardDismissBehavior to CustomScrollView constructor (#66014)

This commit is contained in:
Raouf Rahiche 2020-09-21 19:12:06 +01:00 committed by GitHub
parent 36a6ef6486
commit e0afee5b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -596,6 +596,7 @@ class CustomScrollView extends ScrollView {
this.slivers = const <Widget>[],
int? semanticChildCount,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
String? restorationId,
Clip clipBehavior = Clip.hardEdge,
}) : super(
@ -611,6 +612,7 @@ class CustomScrollView extends ScrollView {
cacheExtent: cacheExtent,
semanticChildCount: semanticChildCount,
dragStartBehavior: dragStartBehavior,
keyboardDismissBehavior: keyboardDismissBehavior,
restorationId: restorationId,
clipBehavior: clipBehavior,
);

View File

@ -799,6 +799,45 @@ void main() {
log.clear();
});
testWidgets('CustomScrollView dismiss keyboard onDrag test', (WidgetTester tester) async {
final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());
await tester.pumpWidget(textFieldBoilerplate(
child: CustomScrollView(
dragStartBehavior: DragStartBehavior.down,
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
focusNodes.map((FocusNode focusNode) {
return Container(
height: 50,
color: Colors.green,
child: TextField(
focusNode: focusNode,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
)
),
);
}).toList(),
),
),
],
),
));
final Finder finder = find.byType(TextField).first;
final TextField textField = tester.widget(finder);
await tester.showKeyboard(finder);
expect(textField.focusNode.hasFocus, isTrue);
await tester.drag(finder, const Offset(0.0, -40.0));
await tester.pumpAndSettle();
expect(textField.focusNode.hasFocus, isFalse);
});
testWidgets('Can jumpTo during drag', (WidgetTester tester) async {
final List<Type> log = <Type>[];
final ScrollController controller = ScrollController();