Skip to main content

google_apple_sign_in 1.0.0 copy "google_apple_sign_in: ^1.0.0" to clipboard
google_apple_sign_in: ^1.0.0 copied to clipboard

Sign in with Google and Apple behind one interface. Returns the id token and nonce your backend or Firebase needs, and follows App Store guideline 4.8.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:google_apple_sign_in/google_apple_sign_in.dart';

/// Fill these in (see the README setup section), or run with the fake:
/// `flutter run --dart-define=FAKE=true`.
const config = SocialSignInConfig(
  googleClientId: '', // iOS OAuth client id
  googleServerClientId: '', // Web OAuth client id
  appleSignIn: false, // true once the capability is on
);

void main() {
  const fake = bool.fromEnvironment('FAKE');
  final SocialSignIn signIn = fake ? FakeSocialSignIn() : PlatformSocialSignIn(config);
  runApp(MaterialApp(home: SignInPage(signIn: signIn)));
}

class SignInPage extends StatefulWidget {
  const SignInPage({super.key, required this.signIn});

  final SocialSignIn signIn;

  @override
  State<SignInPage> createState() => _SignInPageState();
}

class _SignInPageState extends State<SignInPage> {
  String _status = 'Signed out';

  Future<void> _go(SocialProvider p) async {
    try {
      final c = await widget.signIn.signIn(p);
      setState(() => _status = 'Signed in with ${p.name} as ${c.email ?? c.displayName ?? 'unknown'}\n'
          'id token: ${c.idToken.substring(0, c.idToken.length.clamp(0, 24))}…');
    } on SocialSignInCancelled {
      setState(() => _status = 'Cancelled');
    } on SocialSignInFailure catch (e) {
      setState(() => _status = 'Failed: ${e.message}');
    }
  }

  @override
  Widget build(BuildContext context) {
    final providers = widget.signIn.providers;
    return Scaffold(
      appBar: AppBar(title: const Text('google_apple_sign_in')),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            if (providers.isEmpty) const Text('No provider configured. Fill in SocialSignInConfig in main.dart.'),
            for (final p in providers)
              Padding(
                padding: const EdgeInsets.only(bottom: 12),
                child: FilledButton(
                  onPressed: () => _go(p),
                  child: Text(p == SocialProvider.google ? 'Continue with Google' : 'Sign in with Apple'),
                ),
              ),
            const SizedBox(height: 24),
            Text(_status),
            TextButton(
              onPressed: () async {
                await widget.signIn.signOut();
                setState(() => _status = 'Signed out');
              },
              child: const Text('Sign out'),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publishercoderqh.com

Weekly Downloads

Sign in with Google and Apple behind one interface. Returns the id token and nonce your backend or Firebase needs, and follows App Store guideline 4.8.

Homepage
Repository (GitHub)
View/report issues

Topics

#authentication #google-sign-in #apple-sign-in #login #firebase

License

MIT (license)

Dependencies

crypto, flutter, google_sign_in, sign_in_with_apple

More

Packages that depend on google_apple_sign_in