How to show progress dialog on initState
jackyhieu1211-hn opened this issue · comments
Hello admin.
I use code like as. but progress dialog not show. Please guide me. thank you very much.
class UpdateAccount extends StatefulWidget {
@override
State<StatefulWidget> createState() => UpdateAccountState();
}
class UpdateAccountState extends State<UpdateAccount>
{
var user = User();
@override
void initState() {
super.initState();
_getUserInfo();
}
@override
Widget build(BuildContext context) {
_progressDialog = ProgressDialog(context);
return Scaffold(
.....
);
_getUserInfo() async {
_progressDialog?.show();
var userRe = await userRepo.find();
getInfoUser(userRe).then((user) {
setState(() {
this.user = user;
});
print("pr show? ${_progressDialog.isShowing()}");
if (_progressDialog.isShowing()) _progressDialog.hide();
}).catchError((error) {
if (_progressDialog.isShowing()) _progressDialog.hide();
});
}
}
@hieuseesaa why do you do spam, always you create issue on the same context and each time a duplicate
void main() => runApp(MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ProgressDialog progressDialog;
@override
Widget build(BuildContext context) {
progressDialog = ProgressDialog(context);
WidgetsBinding.instance.addPostFrameCallback((Duration d){
progressDialog.show();
});
return Scaffold(
);
}
}
@fayaz07 sorry sir. But I tried sample code. progress had show but it not hide :(
print("pr show? ${_progressDialog.isShowing()}"); return true
. But progress not hide :(
_progressDialog.hide();
Call this code whenever you want to hide it
@fayaz07
I called it . But progress still not hide.
_getUserInfo() async {
_progressDialog?.show();
var userRe = await userRepo.find();
getInfoUser(userRe).then((user) {
setState(() {
this.user = user;
});
print("pr show? ${_progressDialog.isShowing()}");
if (_progressDialog.isShowing()) _progressDialog.hide();
}).catchError((error) {
if (_progressDialog.isShowing()) _progressDialog.hide();
});
}
I found the problem. because I use await
. I removed await
and use then
and It worked. If someone has the same problem. I hope this helps.
_getUserInfo() async {
_progressDialog?.show();
userRepo.find().((userRe) {
getInfoUser(userRe).then((user) {
setState(() {
this.user = user;
});
print("pr show? ${_progressDialog.isShowing()}");
if (_progressDialog.isShowing()) _progressDialog.hide();
}).catchError((error) {
if (_progressDialog.isShowing()) _progressDialog.hide();
});
}
}