mRoot function
点击空白处关闭键盘
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,
);
}