Skip to content

Instantly share code, notes, and snippets.

@rei-codes
Created April 28, 2023 14:22
Show Gist options
  • Save rei-codes/811b629339437b8ed1dec9f9c56b4759 to your computer and use it in GitHub Desktop.
Save rei-codes/811b629339437b8ed1dec9f9c56b4759 to your computer and use it in GitHub Desktop.
Auto focus on open
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