Hide keyboard on scroll in Flutter

The ScrollView widget now has a keyboardDismissBehavior attribute that you can use for this purpose. The attribute is inherited by ListView, GridView and CustomScrollView.

The attribute defaults to ScrollViewKeyboardDismissBehavior.manual but can be changed to ScrollViewKeyboardDismissBehavior.onDrag.

https://api.flutter.dev/flutter/widgets/ScrollView/keyboardDismissBehavior.html

Example

ListView.builder(
  keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
  itemCount: itemCount,
  itemBuilder: (BuildContext context, int index) {
    return ListTile(
      title: Text('Item ${index + 1}'),
    );
  },
)

At least at the time of this writing the attribute is not yet passed on to its parent by CustomScrollView in the Flutter stable branch, but a pull request to add this attribute has already been merged into master on Sep 21, 2020 and will probably be available soon.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)