Skip to content

Instantly share code, notes, and snippets.

@rei-codes
Created April 28, 2023 14:25
Show Gist options
  • Save rei-codes/f02aa53c6e428b5b8e7ef1b1c7191481 to your computer and use it in GitHub Desktop.
Save rei-codes/f02aa53c6e428b5b8e7ef1b1c7191481 to your computer and use it in GitHub Desktop.
Unfocus on scroll
class UnfocusOnScroll extends StatelessWidget {
const UnfocusOnScroll({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Unfocus on scroll'),
bottom: const PreferredSize(
preferredSize: Size.fromHeight(60),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: TextField(
decoration: InputDecoration(hintText: 'Click here to focus'),
),
),
),
),
body: ListView.builder(
// Magic happens here
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
padding: const EdgeInsets.all(16),
itemBuilder: (_, i) {
return Card(
child: Padding(
padding: const EdgeInsets.all(32),
child: Text('card $i'),
),
);
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment