flutter-回收键盘

///build
  @override
  Widget build(BuildContext context) {
    //配置全局点击空白回收键盘
    return GestureDetector(
        onTap: () {
          FocusScopeNode currentFocus = FocusScope.of(context);
          if (!currentFocus.hasPrimaryFocus &&
              currentFocus.focusedChild != null) {
            FocusManager.instance.primaryFocus.unfocus();
          }
        },
        child: initDefaultBuild(context));
  }
  /// 回收键盘
  _keyboardBack() {
    logs("回收键盘...");
    if (!FocusScope.of(context).hasPrimaryFocus &&
        FocusScope.of(context).focusedChild != null) {
      FocusManager.instance.primaryFocus.unfocus();
    }
  }

你可能感兴趣的:(flutter-回收键盘)