preface
The plugin for the Flutter Apple Sign In is quite numerous, but I can’t help but wank one more time to get familiar with the usage of the Flutter plugin and platform View (required by the Apple login button that calls the system). This custom button widget does not call the method callback, the difference is only in the UI. In addition, Plugin layer is based on Swift call Apple Sign In Api implementation, can also incidentally strengthen Swift, after all, OC has been used more.
Download the way
The pub way:
Dependencies: sign_in_apple: ^ 0.0.1Copy the code
github:
Github.com/JerryFans/s…
The effect is as follows:
Usage
The System Button Style Use Platform View to Show in Flutter.
Because system buttons are implemented using platform View
Please set io.flutter.embedded_views_preview = true in Info.plist in your project.
Add IO. Flutter. Embedded_views_preview = true at info.plist and make sure the AppleSignIn configuration is enabled for the project. You can download github example for details
The CallBack callbacks:
SignInApple.handleAppleSignInCallBack(onCompleteWithSignIn: (String name,
String mail,
String userIdentifier,
String authorizationCode,
String identifyToken) async {
print("flutter receiveCode: \n");
print(authorizationCode);
print("flutter receiveToken \n");
print(identifyToken);
setState(() {
_name = name;
_mail = mail;
_userIdentify = userIdentifier;
_authorizationCode = authorizationCode;
});
}, onCompleteWithError: (AppleSignInErrorCode code) async {
var errorMsg = "unknown";
switch (code) {
case AppleSignInErrorCode.canceled:
errorMsg = "user canceled request";
break;
case AppleSignInErrorCode.failed:
errorMsg = "request fail";
break;
case AppleSignInErrorCode.invalidResponse:
errorMsg = "request invalid response";
break;
case AppleSignInErrorCode.notHandled:
errorMsg = "request not handled";
break;
case AppleSignInErrorCode.unknown:
errorMsg = "request fail unknown";
break;
}
print(errorMsg);
});
Copy the code
The UI related:
Custom Widget buttons trigger plugin button events directly:
GestureDetector(
onTap: () {
SignInApple.clickAppleSignIn();
},
child: Container(
width: 56,
height: 56,
child: Image.asset(
"images/apple_logo.png",
width: 56,
height: 56,
),
),
),
Copy the code
The system ButtonWidget directly shows that the component has already implemented an event, and clicking on it triggers the above callback:
AppleSignInSystemButton(
width: 250,
height: 50,
buttonStyle: AppleSignInSystemButtonStyle.black,
)
Copy the code