Created
April 28, 2023 14:25
-
-
Save rei-codes/f02aa53c6e428b5b8e7ef1b1c7191481 to your computer and use it in GitHub Desktop.
Unfocus on scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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