Social Login
Loading preview
Starting the Flutter app
A Flutter social login screen with Google, Apple, and email sign-in buttons and an or-divider.
import 'package:flutter/material.dart';
class SocialLogin extends StatelessWidget {
/// Called with 'google', 'apple' or 'email' when a provider is chosen.
final ValueChanged<String>? onProviderSelected;
/// Called by 'Create a new account'.
final VoidCallback? onCreateAccount;
/// Each callback is optional. Without one, the demo shows a SnackBar.
const SocialLogin({super.key, this.onProviderSelected, this.onCreateAccount});
void _select(BuildContext context, String provider) {
final callback = onProviderSelected;
if (callback != null) {
callback(provider);
} else {
_showDemo(context, 'Continuing with $provider (demo)');
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Spacer(),
Icon(Icons.workspaces_rounded, size: 64, color: scheme.primary),
const SizedBox(height: 20),
Text('Sign in to Nimbus',
textAlign: TextAlign.center,
style: theme.textTheme.headlineSmall
?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 8),
Text('Choose how you want to continue',
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium
?.copyWith(color: scheme.onSurfaceVariant)),
const SizedBox(height: 36),
_SocialButton(
icon: Icons.g_mobiledata_rounded,
label: 'Continue with Google',
onTap: () => _select(context, 'google'),
),
const SizedBox(height: 12),
_SocialButton(
icon: Icons.apple,
label: 'Continue with Apple',
onTap: () => _select(context, 'apple'),
),
const SizedBox(height: 12),
_SocialButton(
icon: Icons.mail_outline,
label: 'Continue with Email',
onTap: () => _select(context, 'email'),
),
const SizedBox(height: 28),
Row(
children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text('or',
style: TextStyle(color: scheme.onSurfaceVariant)),
),
const Expanded(child: Divider()),
],
),
const SizedBox(height: 20),
OutlinedButton(
onPressed: onCreateAccount ??
() => _showDemo(context, 'Account creation goes here (demo)'),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14)),
child: const Text('Create a new account'),
),
const Spacer(),
Text(
'By continuing you agree to our Terms and Privacy Policy.',
textAlign: TextAlign.center,
style: theme.textTheme.bodySmall
?.copyWith(color: scheme.onSurfaceVariant),
),
],
),
),
),
);
}
}
class _SocialButton extends StatelessWidget {
final IconData icon;
final String label;
final VoidCallback onTap;
const _SocialButton({required this.icon, required this.label, required this.onTap});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return OutlinedButton(
onPressed: onTap,
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
side: BorderSide(color: scheme.outlineVariant),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 26),
const SizedBox(width: 12),
Text(label, style: const TextStyle(fontSize: 15)),
],
),
);
}
}
void _showDemo(BuildContext context, String message) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(message)));
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
SocialLogin is layout only, with no OAuth in it. _SocialButton wraps an OutlinedButton around an icon and label. All three call onProviderSelected with ‘google’, ‘apple’ or ‘email’, and ‘Create a new account’ calls onCreateAccount, with a demo SnackBar when either is omitted. Google is represented by Icons.g_mobiledata_rounded, a stand-in glyph and not the brand mark.
Adapting it
- Start sign-in from
onProviderSelected, using google_sign_in and sign_in_with_apple or your auth provider’s SDK. - Replace the
iconfield with an image parameter so you can use official logos, as Google and Apple both publish branding rules. - Make
SocialLoginstateful and add a busy flag, because OAuth takes seconds and double taps are easy.