问题
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