Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Progress dialog is not show when invoke show method. #44

Closed
liudonghua123 opened this issue Mar 26, 2020 · 7 comments
Closed

Progress dialog is not show when invoke show method. #44

liudonghua123 opened this issue Mar 26, 2020 · 7 comments
Assignees
Labels
waiting for response waiting for the customer to respond with the updated code/comment

Comments

@liudonghua123
Copy link

liudonghua123 commented Mar 26, 2020

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:
I write some code like the following. It is for multi-platform. And the progress dialog is not show in android/web, however the dialog is show in windows platform.

class IndexPage extends StatefulWidget {
  IndexPage({Key key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

// AutomaticKeepAliveClientMixin, see https://blog.csdn.net/a875801/article/details/92829950
// TickerProviderStateMixin, see https://blog.csdn.net/u011272795/article/details/82740389
class _IndexPageState extends State<IndexPage>
    with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  List<Course> recommendCourses = [];
  List<Course> freeCourses = [];
  List<News> recommendNews = [];
  ProgressDialog pr;
  TabController _tabController;

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    print('Index, initState');
    pr = new ProgressDialog(context, showLogs: true);
    _tabController = TabController(length: categories.length, vsync: this);
    _updateState();
    super.initState();
  }

  @override
  void dispose() {
    print('Index, dispose');
    _tabController.dispose();
    super.dispose();
  }

  void _updateState() async {
    pr.show();
    print('pr.show()');
    var _recommendCourses = await CommonService().getRecommendCourses(3);
    var _freeCourses = await CommonService().getfreeCourses(2);
    var _recommendNews = await CommonService().getRecommendNews(3);
    print('_updateState: ${_recommendCourses}');
    setState(() {
      print('setState: ${_recommendCourses}');
      recommendCourses = _recommendCourses;
      freeCourses = _freeCourses;
      recommendNews = _recommendNews;
      pr.hide();
      print('pr.hide()');
    });
  }
  //...
}

Expected behavior
The dialog show as expected.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome 80
@liudonghua123
Copy link
Author

If I changed pr.show() to

    WidgetsBinding.instance.addPostFrameCallback((Duration d) {
      pr.show();
    });

Then it seems work, I will do more test about this.

@fayaz07
Copy link
Owner

fayaz07 commented Apr 8, 2020

please use await pr.show()
usually in flutter, for the initialization of dialog takes 200 ms

@liudonghua123
Copy link
Author

@fayaz07 Hi, I tried to await it, but it's the same, the dialog is not show.

@fayaz07
Copy link
Owner

fayaz07 commented Apr 8, 2020

thanks @liudonghua123, I will checkit out

@fayaz07
Copy link
Owner

fayaz07 commented Apr 11, 2020

can you post the updated code without the work you include from other files

@fayaz07 fayaz07 self-assigned this Apr 15, 2020
@fayaz07 fayaz07 added the waiting for response waiting for the customer to respond with the updated code/comment label Apr 15, 2020
@xsahil03x
Copy link
Contributor

If I changed pr.show() to

    WidgetsBinding.instance.addPostFrameCallback((Duration d) {
      pr.show();
    });

Then it seems work, I will do more test about this.

This is because you are trying to show dialog when nothing is rendered on screen. So you need to wait for flutter to render its first screen, then only you can show dialog

@liudonghua123
Copy link
Author

@fayaz07 @xsahil03x Thanks, because I have deleted those issued code, and I can't reproduce it, I will reopen it if necessary or I can reproduce the issue. Thanks, 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for response waiting for the customer to respond with the updated code/comment
Projects
None yet
Development

No branches or pull requests

3 participants