• 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 3813:Column check constraint 'tb_course_chk_3' references other column.
    sleep()和wait()的异同
    线程通信——wait(),notify(),notifyAll()
    对王建民老师的评价&JAVA结课自我总结
    JAVA学习日报 12/19
    JAVA学习日报 12/18
    JAVA学习日报 12/17
    JAVA学习日报 12/11
  • 原文地址:https://www.cnblogs.com/ldlx-mars/p/15013932.html
Copyright © 2020-2023  润新知