zoukankan      html  css  js  c++  java
  • flutter 要求在MaterialApp里的builder写多个东西例如:插件等

    多个的时候可以这么写 以同时使用flutter_easyloading 跟 bot_toast这两个全局类的插件为例子

    final botToastBuilder = BotToastInit();
    final easyload = EasyLoading.init();
     
    MaterialApp(
       title: 'xxxx',
       builder: (context, child) {
        child = easyload(context, child);
        child = botToastBuilder(context, child);
        return child;
       }
    )
    

      如果是同时写一个方法,比如点击空白处键盘消失

    class MyApp extends StatelessWidget {
    
      final easyload = EasyLoading.init();
    
      @override
      Widget build(BuildContext context) {
        return GetMaterialApp(
          title: 'app名',
          theme: AppTheme.light,
          darkTheme: AppTheme.dark,
          themeMode: ThemeMode.system,
          debugShowCheckedModeBanner: false,
          initialRoute: AppRoutes.Splash,
          getPages: AppPages.routes,
          builder: (context, child){
            child = easyload(context, child);
            child = Scaffold(
                // Global GestureDetector that will dismiss the keyboard
                body: GestureDetector(
                onTap: () => hideKeyboard(context),
            child: child,
            ));
            return child;
          },
          unknownRoute: AppPages.unknownRoute,
          enableLog: true,
          logWriterCallback: Logger.write,
          initialBinding: LayoutBinding(),
        );
      }
    }
    
    void hideKeyboard(BuildContext context) {
      FocusScopeNode currentFocus = FocusScope.of(context);
      if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
        FocusManager.instance.primaryFocus.unfocus();
      }
    }
    

      

    特此记录

  • 相关阅读:
    mysql学习日志
    Python学习day10 Javascript/Jquery
    Python学习day07 多线程多进程及主机管理
    Linux基本命令
    django 用户认证/Excel导入Mysql
    转:iptables详解
    Python django前端导入Excel脚本
    Python学习day08 分布式监控系统开发实战
    Subline Text2
    MySQL 常用函数分析
  • 原文地址:https://www.cnblogs.com/ldlx-mars/p/15013932.html
Copyright © 2011-2022 走看看