sách gpt4 ai đã đi

Flutter ProgressDialog ẩn

In lại 作者:行者123 更新时间:2023-12-04 10:51:50 31 4
mua khóa gpt4 Nike

我开发了一个 Flutter 应用程序,我使用了 ProgressDialog小部件 ( progress_dialog: ^1.2.0 )。首先,我展示了 ProgressDialog小部件和一些代码之后,然后我尝试隐藏 ProgressDialog。但它不起作用。

这是我的代码

class SignUp extends StatefulWidget {
@ghi đè
_SignUpState createState() => _SignUpState();
}

class _SignUpState extends State {

@ghi đè
Xây dựng tiện ích (BuildContext context) {
pr = new ProgressDialog(context,type: ProgressDialogType.Normal);
pr.style(
message: 'Sing Up .......',
borderRadius: 20.0,
backgroundColor: Colors.white,
progressWidget: CircularProgressIndicator(),
maxProgress: 1.0,
);

return Scaffold(
backgroundColor: Color.fromRGBO(23, 63, 73, 1),
appBar: AppBar(
title: Text("Sign up"),
backgroundColor: Colors.black,
),body: Stack(

......
_addUser();

),
);
}

Future _addUser() async {
pr.show();

.........

pr.hide();
}

}

之后,我找到了这个问题的解决方案。
Future.delayed(Duration(seconds: 3)).then((value) {
pr.hide();
});

但是为什么 ProgressDialog.hide()在这里不起作用,但它在延迟过程后起作用了??

1 Câu trả lời

当您的代码执行到 pr.hide() 时,progress_dialog 仍然没有显示在屏幕上
所以你的 pr.hide() 不起作用
你可以看到问题 https://github.com/fayaz07/progress_dialog/issues/38
并检查 pr.isShowing() 将不起作用,因为在 progress_dialog https://github.com/fayaz07/progress_dialog/blob/master/lib/progress_dialog.dart 的源代码中
bool _isShowing领先于真实showDialog()progress_dialog 的代码片段

void show() {
if (!_isShowing) {
_dialog = new _Body();
_isShowing = true;

if (_showLogs) debugPrint('ProgressDialog shown');

showDialog(
context: _context,
barrierDismissible: false,
builder: (BuildContext context) {
_dismissingContext = context;
return WillPopScope(
onWillPop: () {
return Future.value(_barrierDismissible);
},
child: Dialog(
backgroundColor: _backgroundColor,
insetAnimationCurve: _insetAnimCurve,
insetAnimationDuration: Duration(milliseconds: 100),
elevation: _dialogElevation,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(_borderRadius))),
child: _dialog),
);
},
);
} khác {
if (_showLogs) debugPrint("ProgressDialog already shown/showing");
}
}
}

完整的测试代码
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:progress_dialog/progress_dialog.dart';

ProgressDialog pr;

void main() {
runApp(MaterialApp(
home: FirstScreen(),
));
}

class MyApp extends StatelessWidget {
double percentage = 0.0;

@ghi đè
Xây dựng tiện ích (BuildContext context) {
// pr = new ProgressDialog(context,
// type: ProgressDialogType.Normal, isDismissible: false);
pr = new ProgressDialog(context, type: ProgressDialogType.Download);

pr.style(
message: 'Downloading file...',
borderRadius: 10.0,
backgroundColor: Colors.white,
elevation: 10.0,
insetAnimCurve: Curves.easeInOut,
progress: 0.0,
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),
);

return Scaffold(
body: Center(
child: RaisedButton(
child: Text(
'Show Dialog',
style: TextStyle(color: Colors.white),
),
color: Colors.blue,
onPressed: () {
pr.show();

Future.delayed(Duration(seconds: 2)).then((onvalue) {
percentage = percentage + 30.0;
print(percentage);

pr.update(
progress: percentage,
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),
);

Future.delayed(Duration(seconds: 2)).then((value) {
percentage = percentage + 30.0;
pr.update(
progress: percentage, message: "Few more seconds...");
print(percentage);
Future.delayed(Duration(seconds: 2)).then((value) {
percentage = percentage + 30.0;
pr.update(progress: percentage, message: "Almost done...");
print(percentage);

Future.delayed(Duration(seconds: 2)).then((value) {
pr.hide().whenComplete(() {
print(pr.isShowing());
});
percentage = 0.0;
});
});
});
});

Future.delayed(Duration(seconds: 10)).then((onValue) {
print("PR status ${pr.isShowing()}");
if (pr.isShowing())
pr.hide().then((isHidden) {
print(isHidden);
});
print("PR status ${pr.isShowing()}");
});
}),
),
);
}
}

class FirstScreen extends StatefulWidget {
@ghi đè
_FirstScreenState createState() => _FirstScreenState();
}

class _FirstScreenState extends State {
ProgressDialog pr;

@ghi đè
Xây dựng tiện ích (BuildContext context) {
pr = new ProgressDialog(context, showLogs: true);
pr.style(message: 'Please wait...');

return Scaffold(
body: Center(
child: RaisedButton(
child: Text('Show dialog and go to next screen',
style: TextStyle(color: Colors.white)),
color: Colors.blueAccent,
onPressed: () async{
print("before pr show");
pr.show();
print("after pr show");
print(pr.isShowing());
pr.hide().whenComplete((){print("hide complete");}
);
print("after pr hide");
print(pr.isShowing());
/*Future.delayed(Duration(seconds: 3)).then((value) {
pr.hide().whenComplete(() {
Navigator.of(context).push(CupertinoPageRoute(
builder: (BuildContext context) => SecondScreen()));
});
});*/
},
),
),
);
}
}

class SecondScreen extends StatefulWidget {
@ghi đè
_SecondScreenState createState() => _SecondScreenState();
}

class _SecondScreenState extends State {
@ghi đè
Xây dựng tiện ích (BuildContext context) {
return Scaffold(
body: Center(child: Text('I am second screen')),
);
}
}

关于Flutter ProgressDialog 隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59448216/

31 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com