zoukankan      html  css  js  c++  java
  • flutter-全局控制键盘收回和单独控制键盘收回

    局部控制键盘收回

    import 'package:flutter/material.dart';
    import 'package:TLDF/main.dart';
    
    class KeyboardBack {
      static BuildContext context = navigatorKey.currentState.overlay.context;
      static FocusScopeNode currentFocus = FocusScope.of(context);
      static void keyboardBack() {
        if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
          FocusManager.instance.primaryFocus.unfocus();
        }
      }
    }
    //需要的地方执行
      KeyboardBack.KeyboardBack();

    全局控制键盘收回

    在main.dart
    child: MaterialApp(
            title: KString.mainTitle,
            //Flutter商城
            debugShowCheckedModeBanner: false,
            navigatorKey: navigatorKey,
            onGenerateRoute: Application.router.generator,
            //主题
            theme: ThemeData(
                primaryColor: KColor.primaryColor,
                ///全局解决ios键盘默认颜色dark
                brightness: Brightness.light, //指定亮度主题,有白色/黑色两种可选。
                primaryColorBrightness: Brightness.light,
                accentColorBrightness: Brightness.light),
            home: SplashScreen(),
            navigatorObservers: [MyApp.routeObserver],
            //全局监听键盘
            builder: (context, child) => Scaffold(
              body: Listener(
                onPointerDown: (PointerDownEvent event){
                  _event=event;
                  print("按下"+_event.timeStamp.toString());
                },
                onPointerUp: (PointerUpEvent event) {
                 int interval=event.timeStamp.inSeconds-_event.timeStamp.inSeconds;
            //防止复制粘贴时触发
    if (interval<1) { FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) { FocusManager.instance.primaryFocus.unfocus(); } } }, child: child, ), ),
  • 相关阅读:
    HTML 样式表
    HTML笔记(框架)
    HTML笔记1
    SQL server 笔记9(备份还原触发器事务三范式)
    拦截器传参问题
    MethodFilterInterceptor(方法拦截器)配置excludeMethors
    js基础学习笔记(五)
    js基础学习笔记(四)
    笔记:CSS常用中文字体英文名称对照表
    推荐:掌握单页网站设计的5大技巧(转)
  • 原文地址:https://www.cnblogs.com/mingv/p/14077881.html
Copyright © 2011-2022 走看看