Skip to content

Instantly share code, notes, and snippets.

View riscait's full-sized avatar

MURAMATSU Ryunosuke riscait

View GitHub Profile
@riscait
riscait / flutter_auth_buttons_apple.dart
Created April 10, 2020 21:38
flutter_auth_buttons パッケージのAppleボタン
final isLightTheme = Theme.of(context).brightness == Brightness.light;
AppleSignInButton(
onPressed: () => presenter.onPressedAppleButton(context),
text: 'Sign in with Apple',
textStyle: TextStyle(
color: isLightTheme ? Colors.white : Colors.black,
fontSize: 19,
),
splashColor: Theme.of(context).accentColor,
style: isLightTheme ? AppleButtonStyle.black : AppleButtonStyle.white,
@riscait
riscait / sign_in_button_builder_apple_button.dart
Last active April 9, 2020 11:23
flutter_signin_button パッケージのAppleボタン
final isLightTheme = Theme.of(context).brightness == Brightness.light;
SignInButtonBuilder(
text: 'Sign in with Apple',
backgroundColor: Colors.white,
icon: Icons.email,
fontSize: 19,
textColor: Colors.black,
// iconColor: Colors.black,
splashColor: Colors.transparent,
// padding: const EdgeInsets.all(0),
@riscait
riscait / sign_in_button_apple_button.dart
Last active April 9, 2020 11:24
flutter_signin_button パッケージのAppleボタン
final isLightTheme = Theme.of(context).brightness == Brightness.light;
SignInButton(
Buttons.Apple,
// mini: true,
text: 'Sign in with Apple',
// padding: const EdgeInsets.all(0),
shape: StadiumBorder(
side: isLightTheme ? const BorderSide(width: 1) : BorderSide.none,
),
onPressed: () => presenter.onPressedAppleButton(context),
dependencies:
flutter:
sdk: flutter
# Sign in with Apple
apple_sign_in: ^0.1.0
# Firebase
firebase_core: ^0.4.4+3
# ユーザー認可
firebase_auth: ^0.15.5+3
/// Sign in with Appleが押された
Future onPressedAppleButton(BuildContext context) async {
// 証明書をリクエストして取得
AuthCredentialWithApple credentialWithApple; // フルネームを使用しない場合は `AuthCredential`でOK
try {
credentialWithApple = await requestAppleIdCredential(); // この後実装
} on Exception catch (e) {
// エラーハンドリング
}
if (credentialWithApple == null) {
/// Apple認可のクレデンシャルを要求し、(取得できた場合は)フルネームも一緒に返却する
Future<AuthCredentialWithApple> requestAppleIdCredential() async {
// apple_sign_inパッケージによるリクエスト実行関数
final authResult = await AppleSignIn.performRequests([
// メールアドレスとフルネーム、取得したいスコープを指定する
// メールアドレスとフルネームどちらも不要な場合は空のListを指定すればOK
const AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
]);
// エラーハンドリング
if (authResult.error != null) {
/// Apple認証で取得したフルネームを保存して使用するためのクラス
class AuthCredentialWithApple {
AuthCredentialWithApple({
@required this.authCredential,
this.givenName,
this.familyName,
});
AuthCredential authCredential;
String givenName;
String familyName;
// Determine if Sign In with Apple is supported on the current device
await AppleSignIn.isAvailable() // => Future<bool>
final isLightTheme = Theme.of(context).brightness == Brightness.light;
AppleSignInButton(
style: isLightTheme ? ButtonStyle.whiteOutline : ButtonStyle.white,
type: ButtonType.signIn,
onPressed: => presenter.onPressedAppleButton(context),
)
final isLightTheme = Theme.of(context).brightness == Brightness.light;
RaisedButton.icon(
// タップした時に色の変化があるが、使用している画像の背景色が透明ではないので、
// 不自然な表現になってしまう。回避策としてタップ時の色変更を透明(なし)にしている
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
elevation: 0,
shape: StadiumBorder(
side: isLightTheme ? const BorderSide(width: 1) : BorderSide.none,
),