fayaz07 / progress_dialog

A light weight library to easily manage a progress dialog with simple steps whenever you need to do it. You can easily show and hide it.

Home Page:https://fayaz07.github.io/progress_dialog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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();
    });
  }
  }