class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
initialRoute: "/",
routes: {
"/": (context) => HomePage(),
},
theme: ThemeData(
primarySwatch: Colors.blue,
),
builder: (BuildContext context, child) => Scaffold(
body: GestureDetector(
child: child,
onTap: () {
hideKeyboard(context);
},
),
),
);
}
void hideKeyboard(BuildContext context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
FocusManager.instance.primaryFocus.unfocus();
}
}
}
网友评论