在flutter项目的入口文件main.dart中编辑如下

    1. class MyApp extends StatelessWidget {
    2. @override
    3. Widget build(BuildContext context) {
    4. return MaterialApp(
    5. localizationsDelegates: [
    6. GlobalMaterialLocalizations.delegate,
    7. GlobalWidgetsLocalizations.delegate,
    8. ],
    9. supportedLocales: [const Locale('zh', 'CN'),const Locale('en', 'US'),],
    10. title: 'xxx',
    11. theme: myTheme(),
    12. // 以下是关键
    13. builder: (context, child) => Scaffold(
    14. body: GestureDetector(
    15. onTap: () {
    16. FocusScopeNode currentFocus = FocusScope.of(context);
    17. if (!currentFocus.hasPrimaryFocus &&
    18. currentFocus.focusedChild != null) {
    19. FocusManager.instance.primaryFocus.unfocus();
    20. }
    21. },
    22. child: child,
    23. ),
    24. ),
    25. home: Home({}),
    26. );
    27. }
    28. }