mRoot function

Widget mRoot({
  1. required Widget child,
  2. WillPopCallback? onWillPop,
  3. bool safeArea = true,
  4. bool safeTop = false,
  5. bool safeBottom = true,
  6. bool safeLeft = true,
  7. bool safeRight = true,
  8. Color? safeAreaBgColor = BaseColors.cWhite,
})

点击空白处关闭键盘

Implementation

Widget mRoot({
  required Widget child,
  WillPopCallback? onWillPop, // 当存在返回拦截时才使用WillPopScope,否则会导致popGesture无效(iOS手势返回上一页)
  bool safeArea = true,
  bool safeTop = false,
  bool safeBottom = true,
  bool safeLeft = true,
  bool safeRight = true,
  Color? safeAreaBgColor = BaseColors.cWhite, // 当有safeArea时,safeArea之外的区域需要手动设置背景色,否则会变黑;
}) {
  var cc = GestureDetector(
      onTap: hideKeyboard,
      child: safeArea
          ? Container(
              color: safeAreaBgColor,
              child: SafeArea(
                top: safeTop,
                bottom: safeBottom,
                left: safeLeft,
                right: safeRight,
                child: child,
              ),
            )
          : child);
  return onWillPop == null && Nav.isPopEnable() // 没有手动拦截,且能返回,才不添加WillPopScope
      ? cc
      : mWillPopScope(
          onWillPop: onWillPop,
          child: cc,
        );
}