当您使用异步调用启动progressDialog & hide时,请使用await关键字:
await progressDialog.show();
await progressDialog.hide();
示例:
添加包:
dependencies:
progress_dialog: ^1.2.4
import 'package:progress_dialog/progress_dialog.dart';
在build() 方法中创建并初始化一个ProgressDialog 对象,将上下文传递给它。
初始化ProgressDialog对象:
final ProgressDialog pr = ProgressDialog(context);
默认情况下,它是一个显示一些消息的普通对话框,如果你想用它来显示完成的百分比,指定可选的type参数并指定你是否希望你的对话框在按下后退按钮时关闭isDismissible参数(可选):
//For normal dialog
pr = ProgressDialog(context,type: ProgressDialogType.Normal, isDismissible: true/false, showLogs: true/false);
//For showing progress percentage
pr = ProgressDialog(context,type: ProgressDialogType.Download, isDismissible: true/false, showLogs: true/false);
> Note: Please initialize the ```ProgressDialog```, where you have availability of the context
Style the progress dialog (Optional)
pr.style(
message: 'Downloading file...',
borderRadius: 10.0,
backgroundColor: Colors.white,
progressWidget: CircularProgressIndicator(),
elevation: 10.0,
insetAnimCurve: Curves.easeInOut,
progress: 0.0,
textDirection: TextDirection.rtl,
maxProgress: 100.0,
progressTextStyle: TextStyle(
color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
messageTextStyle: TextStyle(
color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600)
);
注意:您不需要使用所有参数,它们都是可选的。
显示进度对话框:
await pr.show();
Dynamically update the content shown out there
pr.update(
progress: 50.0,
message: "Please wait...",
progressWidget: Container(
padding: EdgeInsets.all(8.0), child: CircularProgressIndicator()),
maxProgress: 100.0,
progressTextStyle: TextStyle(
color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
messageTextStyle: TextStyle(
color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600),
);
关闭进度对话框:
pr.hide().then((isHidden) {
print(isHidden);
});
// or
await pr.hide();
导航到下一个屏幕必须在完成 Future - hide() 之后完成。例如,请参见此处。
检查是否显示进度对话框:
bool isProgressDialogShowing = pr.isShowing();
print(isProgressDialogShowing);
Use custom body
pr = ProgressDialog(
context,
type: ProgressDialogType.Normal,
isDismissible: true,
/// your body here
customBody: LinearProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.blueAccent),
backgroundColor: Colors.white,
),
);
更多详情:https://flutterrepos.com/repo/fayaz07-progress_dialog-