in this video we will see how to add biometric and facial authentication and you will be surprised by how easy it is so first add the local o package and now for its iOS setup we will add this keyst string pair inside the info. P list and for Android in main activity. KT file change the flutter activity to flutter fragment activity as said in the documentation and also make sure to copy this import and replace it over here and add this user permission of use biometric in Android manifest.xml file and that is all for the
setup now in order to get started first we will create some variables like o support state and then inside the init State we will initialize the o to local authentication then add o do is device supported to check if the device supports biometric authentication or not then call the then method which give us the is supported bullion now we'll call set State and set the supported state to is supported now for the UI inside the column we will check if supported state is true then return a text vet with a text of this device is
supported or else return a text wiget with a text this device is not supported then add an elevated button with an onpress equal to gate available biometric this method will return all the available biometric sensors on the device then add a child and pass a text widget now let's create this gate available biometric method in it add o. gate available Biometrics which returns a list of biometric type and show the results inside a variable then let's print it to see it inside the console then make sure to check that if the mounted is false then
return from here or else we can call the set State this mounted value represents the state in the widget tree and it may throw an error if we call set State unless the mounted is true and with this we good to run the application but before that let's set up our emulator uh in the emulator open the settings then open security in it we have the pixel imprint click on it and enter any password you want now let's click on ADD fingerprint now to act activate the fingerprint sensor just click on this more icon and
navigate to fingerprint and here we have 10 fingerprints choose any one you want then just click on this touch sensor and it will register the fingerprint then click done now install the application and once install open up the console now when we click on this button we see the list of biometric sensors available which are of type we and strong Now for iOS inside the features in the face ID just click enrolled and then how to restart the application and the face ID should be enrolled and when we click on this button we should see
the biometric type of face now we are all set to authenticate the user using this sensors so let's create an elevated button with an onpress of authenticate and a child of text below here let's create the authenticate method in it add try catch block to catch all the platform exception and in it we will simply print those errors in the tri block create authenticate Pion and assign it to await all do authenticate in it add a localized reason and pass whatever reason you want then add options equal to authentication options in which set the sticky
o to true and by doing so the plug-in does not return failure if the app is put to Background by the system then set biometric only to true this will allow only biometric authentication not password pin code or patterns are allowed and at last let's print this authenticate variable and that's all this simp method will do both biometric and facial authentication now let's install the application to see it click on authenticate button and it opens the native authentication element where we can see a reason which we have specified now select the finger with which you
have registered and click on the touch sensor and we are authenticated now if we select any other finger which we have not registered and try to authenticate we will get an error as not recognized and similarly on iOS when we click on authenticate we get a popup and then under the features inside the face ID just click on matching face and we are authenticated as you can see here and lastly if we set the biometric only to false and H restart the application you will see that when we click on authenticate we see a Ed
pin button in the bottom through which we can authenticate using a PIN code and that's all you need to know about biometric authentication and hey if you're interested in getting one tips and tricks two resources and one stepbystep guide every every Saturday in your inbox then do subscribe to our one to1 newsletter links in the description [Music]