Progress dialog is not show when invoke show method.
liudonghua123 opened this issue · comments
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
If I changed pr.show()
to
WidgetsBinding.instance.addPostFrameCallback((Duration d) {
pr.show();
});
Then it seems work, I will do more test about this.
please use await pr.show()
usually in flutter, for the initialization of dialog takes 200 ms
@fayaz07 Hi, I tried to await
it, but it's the same, the dialog is not show.
thanks @liudonghua123, I will checkit out
can you post the updated code without the work you include from other files
If I changed
pr.show()
toWidgetsBinding.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
@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, 😃