Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: checkAndRequest & requestPermissions not async #131

Open
IbrahimYildirim opened this issue Aug 15, 2023 · 1 comment
Open

iOS: checkAndRequest & requestPermissions not async #131

IbrahimYildirim opened this issue Aug 15, 2023 · 1 comment

Comments

@IbrahimYildirim
Copy link

IbrahimYildirim commented Aug 15, 2023

When using checkAndRequest or requestPermissions, with await it doesn't wait for the user input but rather just jumps to the next line.

Example

    await _audioQuery.checkAndRequest().then((value) async {
        _hasPermission = await _audioQuery.permissionsStatus();
        print('Has permission to access library: $_hasPermission');
    });
    print('Done requesting before user response');

In this case both print's gets triggered as soon as this method is called. It doesn't wait for user input.

Only tested on latest iOS 16.6

@IbrahimYildirim
Copy link
Author

For now I have made a "Workaround" by using WidgetsBindingObserver like this

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed && mounted) {
      context.read<BackgroundMusicData>().loadLocalBackgroundMusicIfNeeded();
    }
  }

As the AppLifeCycleState becomes inactive while the permission for library access is shown and then resumed is called when user has clicked on a action. It would be much better if the methods would work and I wouldn't need this workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant