撸一个Flutter Apple Id 登陆插件

前言

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

下载方式

pub方式:github

dependencies:
  sign_in_apple: ^0.0.1
复制代码

github:bash

github.com/JerryFans/s…app

效果如图:async

Usage

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

由于系统按钮使用platform view 实现ui

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

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

CallBack回调:code

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,
)
复制代码
相关文章
相关标签/搜索