Introduction
Sign-in with Apple is an alternative to many apps and websites’ existing Google and Facebook sign-in options. Apple’s version safeguards your privacy and even allows you to conceal your email address.
In this article, I’ll demonstrate how to set up and use Apple Sign In with Flutter.
Step 1:
It should be noted that it can only be implemented on iOS and Macs with xCode (Software to develop ios apps). We can use Google Login on Android.
dependencies: apple_sign_in: ^0.1.0
You can use the command line to install packages:
flutter pub get
Alternatively, your editor, such as Android Studio or Visual Studio Code, may support flutter pub get.
Step 2:
Xcode configuration
Open the Flutter project in Xcode by right-clicking on the project and selecting Flutter > Open ios module in Xcode.
Go to the project settings in Xcode and select Signing & Capabilities.
Click on the Capability to open a dialogue box where we can search for Sign in with Apple and click on the result.
Step 3:
The Most Important Step (Coding)
1. To utilize its features, import “apple_sign_in.dart“.
import 'package:apple_sign_in/apple_sign_in.dart';
2. Initialize the Functionality in Scaffold’s initState()
if(Platform.isIOS){ AppleSignIn.onCredentialRevoked.listen((_) { print("Credentials"); }); }
3. Put the Apple Sign-in button that is designated specifically for this operation.
AppleSignInButton( style: ButtonStyle.white, type: ButtonType.continueButton, onPressed: appleLogIn, );
4. Create the appleLogIn() method to implement the sign-in feature.
if(await AppleSignIn.isAvailable()) { //Verify whether Apple SignIn is compatible with the device. }else{ print('Apple SignIn is not available for your device'); }
If available, we can make a login request.
if(await AppleSignIn.isAvailable()) { final AuthorizationResult result = await AppleSignIn.performRequests([ AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName]) ]); }
Handle the outcome in accordance with your needs.
if(await AppleSignIn.isAvailable()) { final AuthorizationResult result = await AppleSignIn.performRequests([ AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName]) ]); switch (result.status) { case AuthorizationStatus.authorized: print(result.credential);//all necessary qualifications case AuthorizationStatus.error: print("Sign in failed: ${result.error}"); break; case AuthorizationStatus.cancelled: print('User cancelled'); break; } }
If you want to do anything, you can send the credentials to your backend.
Step 4:
Launching the app
Conclusion
The “Apple Sign-In With Flutter Tutorial” is now finished. I hope this article has provided you with some useful information.