Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The Apple ID signin can be utilized in Flutter through the use of the flutter_signin_button and flutter_apple_sign_in packages. These packages provide easy integration for Apple ID signin by handling the authentication flow and returning the user's information to the app.

To use the Apple ID signin in a Flutter app, the following steps should be taken:

  1. Import the flutter_apple_sign_in and flutter_signin_button packages in the pubspec.yaml file

dependencies: 
 flutter_apple_sign_in: ^0.1.0 
 flutter_signin_button: ^2.0.0

  1. Create a button that will trigger the Apple ID signin flow using the AppleSignInButton() widget provided by the flutter_signin_button package.

import 'package:flutter_signin_button/flutter_signin_button.dart';

class AppleIDSigninButton extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return SignInButton(
     Buttons.Apple,
     onPressed: () {},
   );
 }
}

  1. Trigger the Apple ID signin flow when the button is pressed by importing the apple_sign_in.dart file provided by the flutter_apple_sign_in package and calling the AppleSignIn.performRequests() method.

import 'package:flutter_apple_sign_in/flutter_apple_sign_in.dart';

class AppleIDSigninButton extends StatelessWidget {
 void _performSignIn() async {
   final credential = await AppleSignIn.performRequests([
     AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
   ]);
   print(credential);
 }

 @override
 Widget build(BuildContext context) {
   return SignInButton(
     Buttons.Apple,
     onPressed: _performSignIn,
   );
 }
}

  1. Retrieve the user's information from the credential variable returned by the AppleSignIn.performRequests() method.

import 'package:flutter_apple_sign_in/flutter_apple_sign_in.dart';

class AppleIDSigninButton extends StatelessWidget {
 void _performSignIn() async {
   final credential = await AppleSignIn.performRequests([
     AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
   ]);
   final signInDetails = AppleSignInDetails(
     credential.userIdentifier,
     credential.identityToken,
     credential.authorizationCode,
     credential.email,
     credential.fullName,
   );
   print(signInDetails);
 }

 @override
 Widget build(BuildContext context) {
   return SignInButton(
     Buttons.Apple,
     onPressed: _performSignIn,
   );
 }
}

With these steps, the Apple ID signin can be easily integrated into a Flutter app using the flutter_apple_sign_in and flutter_signin_button packages.