mRoot function

Widget mRoot({
  1. required Widget child,
  2. String? route,
  3. bool? canPop,
  4. PopInvokedCallback? popInvokedCallback,
  5. bool safeArea = true,
  6. bool safeTop = false,
  7. bool safeBottom = true,
  8. bool safeLeft = true,
  9. bool safeRight = true,
  10. Color? safeAreaBgColor,
  11. GestureTapCallback? onScreenTap,
})

点击空白处关闭键盘

Implementation

Widget mRoot({
  required Widget child,
  String? route,
  bool? canPop,
  PopInvokedCallback? popInvokedCallback,
  bool safeArea = true,
  bool safeTop = false,
  bool safeBottom = true,
  bool safeLeft = true,
  bool safeRight = true,
  Color? safeAreaBgColor, // 当有safeArea时,safeArea之外的区域需要手动设置背景色,否则会变黑;
  GestureTapCallback? onScreenTap,
}) {
  var cc = GestureDetector(
      onTap: onScreenTap ?? hideKeyboard,
      child: safeArea
          ? Builder(
              builder: (ctx) => Container(
                color: safeAreaBgColor ?? Theme.of(ctx).colorScheme.surface,
                child: SafeArea(
                  top: safeTop,
                  bottom: safeBottom,
                  left: safeLeft,
                  right: safeRight,
                  child: child,
                ),
              ),
            )
          : child);
  return (popInvokedCallback == null && canPop == null && Nav.isPopEnable(route: route)) // 没有手动拦截,且能返回,才不添加WillPopScope
      ? cc
      : mPopScope(
          canPop: canPop,
          onPopInvoked: popInvokedCallback,
          child: cc,
          route: route,
        );
}