简体   繁体   中英

Can you do me a script for Flutter photo access permisson?

This is a sample of my Flutter source code which controlled behavior of photo access permisson:

class __ImageWidgetState extends State<_ImageWidget> {
  Future<bool> requestGalleryPermission() async {
    const Permission _photos = Permission.photos;
    final PermissionStatus permissionss = await _photos.request();

    if (permissionss == PermissionStatus.granted) {
      return true;
    } else  {
     return openAppSettings();
     // return false;
    }
  }

With this code, if users press Don't Allow they will be redirected to Photo Setting automatically.

I have changed openAppSettings() by false so nothing happens if users press Don't Allow, but they can't upload image until they go to Photo Setting to choose Allow manually.

I'm new to Flutter, so can you please help me with my below scritp?

Users pressing Don't Allow will see a popup saying that: Because you choose Don't Allow so you won't be able to change profile image and upload image.

They press OK button to close this popup. Everytime they want to change/upload image they will see popup which requires access photo again.

Thank you! I'm so grateful to you!

在此处输入图像描述

If the user don't allow the access for photos you can show an AlertDialog.

https://api.flutter.dev/flutter/material/AlertDialog-class.html

If it is allowed you just ask for permission again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM