Created
August 1, 2020 16:58
-
-
Save guilherme-v/d1a92332a8a4f32d6fd6d3798e93a3d7 to your computer and use it in GitHub Desktop.
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
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