Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreikastsiuk/774c23322304bd33ab01ac6b807952fc to your computer and use it in GitHub Desktop.
Save andreikastsiuk/774c23322304bd33ab01ac6b807952fc to your computer and use it in GitHub Desktop.
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
builder: (context, child) => Scaffold(
// Global GestureDetector that will dismiss the keyboard
body: GestureDetector(
onTap: () {
// When running in iOS, dismiss the keyboard when any Tap happens outside a TextField
if (Platform.isIOS) hideKeyboard(context);
},
child: child,
),
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
void hideKeyboard(BuildContext context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
FocusManager.instance.primaryFocus.unfocus();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment