show static method
dynamic
show(
- BuildContext context, {
- Widget? loading,
- int? duration,
- Color? color,
- bool closable = false,
显示 Loading
loading
- 自定义的 Loading 视图
duration
- 指定毫秒后,自动隐藏。如果为 null,则不自动隐藏
color
- loading 时的背景颜色,默认为 Colors.black54
closable
- 是否可以通过返回按钮关闭 loading
Display Loading
loading
-custom loading view
duration
-automatically hide after specified milliseconds. If null, do not hide automatically
color
-background color when loading, default is Colors.black54
closable
-Is it possible to close loading via the back button
Implementation
static show(BuildContext context,
{Widget? loading, int? duration, Color? color, bool closable = false}) {
if (!_isShow) {
_isShow = true;
showGeneralDialog(
context: context,
pageBuilder: (BuildContext buildContext, Animation<double> animation,
Animation<double> secondaryAnimation) {
final Widget pageChild = Builder(builder: (context) {
_cacheContext = context;
Widget widget = loading ?? _loading ?? CupertinoActivityIndicator();
return WillPopScope(
onWillPop: () async {
if (closable) {
hide();
}
return Future.value(false);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [widget],
),
);
});
return pageChild;
},
barrierDismissible: false,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: (color ?? _backgroundColor ?? Colors.black38),
transitionDuration: const Duration(milliseconds: 150),
transitionBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return FadeTransition(
opacity: CurvedAnimation(
parent: animation,
curve: Curves.easeOut,
),
child: child,
);
},
useRootNavigator: true,
routeSettings: null,
);
if (duration != null) {
_timer = Timer(Duration(milliseconds: duration), () {
hide();
});
}
}
}