• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

撸一个Flutter Apple Id 登录插件

开发技术 开发技术 3周前 (05-12) 23次浏览

Flutter Apple Sign In相关插件pub搜了一下还是蛮多的,但是还是忍不住要再撸一个,顺便可以再熟悉下flutter plugin和 platform view 的用法(调用系统的苹果登录按钮需要用到),这个自定义button widget,调用方法拿回调则不用,区别只是在于UI。另外Plugin层是基于Swift调用Apple Sign In Api实现的,也可以顺便加强下Swift,毕竟一直OC用得较多。

下载方式

pub方式:

dependencies: sign_in_apple: ^0.0.1 复制代码

github:

github.com/JerryFans/s…

效果如图:

Usage

The System Button Style Use Platform View to Show in Flutter.

因为系统按钮使用platform view 实现

Please set io.flutter.embedded_views_preview = true in Info.plist in your project.

请在Info.plist 加入 io.flutter.embedded_views_preview = true, 同时确保项目开启了AppleSignIn 的配置。详情可以下载github上example查看

CallBack回调:

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); }); 复制代码

UI相关:

自定义Widget按钮直接触发plugin按钮事件即可:

GestureDetector( onTap: () { SignInApple.clickAppleSignIn(); }, child: Container( width: 56, height: 56, child: Image.asset( "images/apple_logo.png", width: 56, height: 56, ), ), ), 复制代码

系统ButtonWidget直接显示,组件内部已经实现了事件,点击了会触发上面的回调:

AppleSignInSystemButton( width: 250, height: 50, buttonStyle: AppleSignInSystemButtonStyle.black, ) 复制代码


喜欢 (0)