How to request permission in flutter | Ask permission in flutter | Permission_Handler

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys in this video we will understand how to ask user permission and check the status of the permission this application can access camera and take a photo also it can read the call logs and make a phone call in the later part of the series we will see how to access camera and take photos and also how to make a phone call and read call logs for this video we will understand how the permission works now to use permissions in flutter flutter provides a very good package called as permission handler that we can use to check for the permissions and request for the permissions to use permission handler the first thing we need to do is install it go to your pub spec email and and the dependencies include the package permission handler and save the file the visual code will automatically install the dependency for you or the package for you using flutter pubget after the permission handler is installed you have to import the package where you want to use it using this line import permission handler the third thing is very important and it can make a lot of difference that is to include the permissions that you want to request or use inside the android manifest.xml this file can be found in here can be found here android app main android manifest here include all the permissions that you want to use if you are not sure what permissions you want to use you can check out this website permission here you will find all the permissions for the android with the name and whichever permission you want to use at this constant now at this point we have successfully set up the permission handler now we just have to use it and ask for the permission before we start let me tell you that i have created an icon button and on the click of an icon button we are calling this method on camera check permission now to check the status of the permission permission handler provides us with a permission class and it has some constants sms speech reminder phone etc and to check for any of the status select the constant for example if you want to check for the microphone select microphone and then there is a status the status will return the current status of the permission there are five states to every permission the first is is granted if your application has access to the permission then is granted is returned if the permission is denied then is denied is written if this is the status is denied you can again request for the permission the third is is permanently denied if this is the status of the permission you cannot request for the permission again you have to manually go to the application settings and turn it on the fourth is is restricted this is returned when there are some security locks on your phone or a parental controls on your phone and because of that you cannot use that permission the fifth is is undetermined this status is returned when the permission has never been asked that means if you run the application for the first time then is undetermined if used let us check the status of the camera status and microphone status see both have undermined status because we have never asked for this permissions before uh we have revealed the application again so this is the first time i'm running the application so we have undetermined status if i deny it and right again status is is denied that means the user has denied the permission we can now provide the access and check again it is granted now that we know how to ask or how to check for the permission status let us move forward to how can we ask for the permission or request the permission to do that use the same syntax permission then for what you want to ask let's say microphone select the microphone and call request this request will return the permission status these are the five permission statuses that we just saw it will return any of them permission status and then you can check if it was granted if it was denied and then handle the logic accordingly you it is not compulsory to check the permission at the permission status you can just ask for the permission and check the status at another time like this here we have just requested the permission and we are checking the permission status here so it is not compulsory to check the status at the same time so for the camera settings uh for for opening a camera we are checking if we have a camera permission on the microphone permission if we do not have granted permission we are requesting it again and if we have granted permissions we are opening the camera otherwise we are displaying a toast that please provide a permission otherwise you would not be able to use for the phone we are using the second syntax that is we are checking the status while we are calling the request because we just saw that request returns the permission status so we are doing it here so the first way is just request the permission and check the status at another time the second is check the status while you are requesting the permission the one thing to notice is that this request and the status is granted they all are using futures so and you should know how to handle the futures we are we have enclosed all these functions inside the async so that we can handle the futures the third way to ask for the permission is using an array by using an array you can request the permissions at the all at the same time you don't have to write permission dot camera dot request permission dot camera dot microphone not require request or permission permission.sms.request you can just create an array of all the permissions you want to request and then call request this request will return the map of the permission and the permission status and to use the status this map use the syntax the map then the provide the permission you want to check the status for for example camera and check if it was granted or not if the both are granted camera and microphone open the camera otherwise show a toast that provides permission otherwise you will not be able to use so by this tutorial we just wanted to learn how we can use permission handler and check for the permission status and also how can we request for the permission in the next video we will learn how to open camera and take a photo and how can we use call logs and also make a phone call so do not forget to subscribe if you have any doubts regarding this whole tutorial a permission thing how to ask a permission or if you have any doubts regarding permissions write it down in the comment section and i will respond to you as soon as possible if you have any suggestions also write it down in the comment section if you like this video do not forget to subscribe and share it with your friends and thank you and have a nice day
Info
Channel: shiva burade
Views: 23,866
Rating: undefined out of 5
Keywords: how to ask permission in flutter, how to request permission in flutter, how to check permission status flutter, how to use permissions in flutter, how to use permission handler, Permission_Handler package of the week
Id: AoMVol8ZpaA
Channel Id: undefined
Length: 10min 8sec (608 seconds)
Published: Fri Oct 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.