How to ask for permission inside flutter application ? Flutter Permission Handler Package.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys in this video we are going to see how we can ask for the permission from the user using in inside our flutter application so basically inside this application i am asking for three permission first is microphone permission second is camera permission third is the storage and the last is we will ask for the permission all these permission at the same time that is all for permission was asked at the same time so when i click on storage permission it will show the popup to ask for the permission so when i click on allow storage permission is now run so let's see how we can implement this so before asking for the permission to the user first you need to do that you have implemented the dependency of permission handler inside your pubspec.yaml so if you have not done this you can visit to pub.dev and search for permission handler and then copy this dependency and paste it inside your pubspec.yaml file under the dependencies here you have to paste it and the second thing you need to do that is to whatever your permission you want to access you want to access the from the user so search for that permission inside the this website and then go inside that permission and copy the constant value of that permission that is this and then copy this permission constant value and then paste it inside your androidmanifest.xml file so it will be inside our android and then app and then src and inside you have get two properties that is debug and main so do not do this inside the debug come inside main and then provide the android manifest xml so you you will get the same android manifest xml inside debug as well so you don't have to do inside the debug just come inside me and inside the manifest androidmanifest.xml above the application tag paste this a ask for user's permission and then provide the name of the permission you want to access so here in this app i am asking for three permission first to record the audio that is that is asking for microphone permission and second is to access camera and third is to write the storage that is accessing the storage so i have provided these three permission inside out inside the user's permission tag and under the name i have provided the permission which i needed so in this way you can you have to provide the permission inside manifest androidmanifest.xml if you not do this then your app will then whenever you ask for the permission using that plugin you will get a debug saying that the permission is not available inside android manifest xml so it is needed to provide the permission inside the androidmanifest.xml file so if you are using ios then you have to visit this page that i will provide the link inside the description for both the pages that is manifest.permission and also for the apple developer so inside this you have to edit the info dot plist file so you have to read this and then provide edit our edit your info plist file and then ask for the permission after this we are ready to proceed further so i have so i have already told you that i will ask three permission that is my permission camera permission and storage permission so let's see how we can ask for the permission so i have created the list type and all these four list tile is inside our column widget the first is our mic permission and the on tap of this mic permission we will ask for microphone permission so create a permission status variable microphone status and inside this we have to wait so wait for the function to execute call so we need to use a sync so now what i will do i will call permission dot microphone dot request so i will request for the permission and then this request function will give the status of the permission that i was requested so if the status of our permission is granted that user is granted we can perform the operation over that permission so if the user status is denied we have to request for permission again so we can choose whether to ask for the permission or to continue with the permission that was already granted so what now what i have to do is to just check whether the microphone equal to equal to permission status dot is granted dot granted okay if it is granted then we have to move further with our operation that it is already granted so now we can use that permission okay so if the user is granted the permission so we can use that permission and then move to the further step so if what happen if user has denied the operation that that user does not want to give the access of its microphone so we will check whether the permission status dot is denied if the user has denied the permission so we will show the scaffold messenger dot off show snack bar so we will show the snack bar to the user saying that why we need this permission so inside the content we will use type text and then this permission we will give the description of the permission so if user has denied the permission so we will show the scaffold of why we need the permission by showing why we need the permission and if the user has permanently denied for the micro for the permission so what we will do it will check permission status dot permanently denied so if user has permanently denied that he does not want to give the permission to you so what you will do you will just open the app settings to allow for the permission so let's revise what we need we have did right now so first when the user clicks on this list time we will request for the permission if the if the permission was already granted so it will come inside the this if body and if the permission was not or previously granted so it will ask for the permission and when the user granted that permission it will come inside this body that is granted body and if the user when the popup is shown for the asking the permission and the user denied it so it will come inside the scaffold messenger and show the snack bar so when the user has choose the prompt that he does not want to give the permission to you so after this when the user taps on this mic permission it will open the app settings to allow for the permission so let's see how it's work so when i click on my permission so it will first show me the prompt for the permission so let's click it so it is asking for the permission so when i click on i do not provide the permission then it will show me the uh then it will take me to the settings of my app so here i can use this to provide the permission so when i again click on this so it will again show me the uh permission and when i do not allow this so it will show me the permission is recommended that is this denied and when i again click on this it will take it will again ask me for the permission and when i don't allow this then it will show me and then it will take me to the setting of the because android knows that user does not want to allow the permission but the app is asking permission again and again so it will make sure that the permission is permanently denied so when i click on my permission it will and now it will take me to the settings page because yeah android knows that user does not want to uh provide the permission to that app but app is again and again asking for the permission so it will just it will come inside the status of permanently denied so come back so now when i click on this my permission what happen it will take me to the settings of my app so in this way you can ask for the permission so let's see again for the camera permission so come inside the on tap of the list tile i will come inside the on tap of the camera permission and then again i will request for the permission so the request will provide me the permission status so i will hold this variable though this request inside permission status and then i will call the variable as camera status equal to await and permission permission dot camera dot request so basically the request will provide me the status of the permission i need to add a sync here so it will provide the status of the request so if the status is granted that is camera is granted so if camera status equal to equal to permission permission status dot granted so we have already so the user has already provided the permission to the app so we need to perform the operation here using that permission okay so if the user has denied for the permission permission status dot denied then we will show the scaffold for the same so we will show the show scaffold messenger dot off context dot show snack bar and then inside this we will use const snack bar and provide the content you need to provide camera permission okay so so if the user has permanently denied it camera status equals to permission dot permanently denied so inside this we will open the app settings so i have to remove this dot html here and now we are ready so in the previous permission i have denied two times and then the android knows that user does not want to allow for the permission but the app requesting again and again so it came inside the permanent denied category so in this camera permission i will allow for the permission and then i will show the snack bar same scaffold so inside this granted scaffold messenger dot of context dot so show snack bar inside this i will call it snack bar and then content and permission grand date so now when i click on this camera it will show me the prompt for the permission and when i click on allow using this while using the app so it will give that the permission granted so in this way you can ask for the permission inside android application so now uh you have aroused a question that what happens when i need to ask permission at us all permission that i need at the same time for this you have to pass all the permission inside the list so here i want to access for the camera microphone and storage so i have passed all this permission inside the list that is this is the list and then i have called the request method so if this will return the map of our statuses permission and statuses so the map contain the permission which we need to ask and the status of that permission using this we we can proceed to the further so you have now understand how can how we can ask for permission all permission at the same time so again i will tell you so pass all the permission inside the list and then call the request method and this request method will return the map of the permission and the statuses of that permission so using this you can ask using this you can check whether the request whether the permission is granted or then you can move to the further or whether the permission is denied so let's check this so when i click all permission it will ask for the all permission so now so because the mic permission is already denied so it does not ask for me ask me for the mic permission so you can see that you see this you can see here permission camera granted permission microphone phone permanently denied permission speech permission permanently denied and the permission storage granted so in this way you can implement a permission handler inside your flutter application or ask for the permission so thanks for watching
Info
Channel: Be Developers
Views: 20,485
Rating: undefined out of 5
Keywords: flutter permission handler, flutter permission handler example, flutter permission handler ios, flutter permission handler location, flutter permission handler location always, flutter permission handler android 11, Flutter, flutter tutorial, flutter tutorial for beginners, flutter permission handler storage, flutter permission handler camera, flutter permission handler open settings, flutter permission handler not working ios
Id: K7kw0T8k2cg
Channel Id: undefined
Length: 14min 51sec (891 seconds)
Published: Thu Apr 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.