Created
April 28, 2023 14:22
-
-
Save rei-codes/811b629339437b8ed1dec9f9c56b4759 to your computer and use it in GitHub Desktop.
Auto focus on open
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 AutoFocusOnOpen extends StatelessWidget { | |
const AutoFocusOnOpen({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Auto focus on open'), | |
), | |
body: const Center( | |
child: Padding( | |
padding: EdgeInsets.all(16), | |
child: TextField( | |
// Magic happens here | |
// makes the app focus immediately after widget built | |
autofocus: true, | |
decoration: InputDecoration(hintText: 'Search'), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment