Both WidgetsBinding.instance.addPostFrameCallback and SchedulerBinding.instance.addPostFrameCallback does wait before the page is build?

╄→尐↘猪︶ㄣ 提交于 2020-08-06 05:22:09

问题


I have the following build codes. What I need is for the first loading to ask for the permission only after the page is completely loaded. But what I notice the is that the permission comes out even before the page is loaded and causes very bad view cause its like stuck between the previous page and current page. How to avoid is this ? I have tried even this

SchedulerBinding.instance
                .addPostFrameCallback((_)

Widget build(BuildContext context) {
    WidgetsBinding.instance
        .addPostFrameCallback((_) => _listenForPermissionStatus(context));
    return BlocProviderTree(
        blocProviders: [
         BlocProvider<ApiBloc>(
            bloc: apiBLoC,
          ),
    ]
    ....
   // more codes here for the build. 
}
void _listenForPermissionStatus(context) async {
    var status = await Permission.notification.status;
    print("Notification STATUS IS:" + status.toString());

    //openAppSettings();
    if (status.isRestricted) {
      Map<Permission, PermissionStatus> statuses = await [
        Permission.notification,
      ].request();
      print("After restriscted :" + statuses[Permission.location].toString());
    }
    if (status.isUndetermined) {
      Map<Permission, PermissionStatus> statuses = await [
        Permission.notification,
      ].request();
      print("After undertermined :" + statuses[Permission.location].toString());
    }
    if (status.isDenied) {
      print("IS DENIED :");
      Map<Permission, PermissionStatus> statuses = await [
        Permission.notification,
      ].request();
      print("After denied :" + statuses[Permission.location].toString());
    }
  }

来源:https://stackoverflow.com/questions/63054221/both-widgetsbinding-instance-addpostframecallback-and-schedulerbinding-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!