1. /// 移除键盘核心代码
    2. FocusScope.of(context).requestFocus(new FocusNode());

    创建dart文件,并添加如下类。在需要点击或者拖拽的view外面嵌入如下类,触发相关方法的时候就可以收回键盘

    1. //点击收回键盘
    2. import 'package:flutter/material.dart';
    3. class TouchHideKeyBoard extends StatelessWidget {
    4. final Widget child;
    5. TouchHideKeyBoard({this.child});
    6. @override
    7. Widget build(BuildContext context) {
    8. return GestureDetector(
    9. behavior: HitTestBehavior.translucent,
    10. onTap: () {
    11. FocusScope.of(context).requestFocus(new FocusNode());
    12. },
    13. onHorizontalDragEnd: (_) {
    14. FocusScope.of(context).requestFocus(new FocusNode());
    15. },
    16. onVerticalDragEnd: (_) {
    17. FocusScope.of(context).requestFocus(new FocusNode());
    18. },
    19. child: child,
    20. );
    21. }
    22. }