generateSocialAuthButton static method

String generateSocialAuthButton()

Implementation

static String generateSocialAuthButton() {
  return '''
import 'package:flutter/material.dart';

enum SocialAuthProvider { google, apple, facebook, github }

class SocialAuthButton extends StatelessWidget {
final SocialAuthProvider provider;
final VoidCallback? onPressed; // Make onPressed nullable
final bool isLoading;
final double height;

const SocialAuthButton({
  Key? key,
  required this.provider,
  required this.onPressed, // Still required but can be null
  this.isLoading = false,
  this.height = 56,
}) : super(key: key);

String get _buttonText {
  switch (provider) {
    case SocialAuthProvider.google:
      return 'Continue with Google';
    case SocialAuthProvider.apple:
      return 'Continue with Apple';
    case SocialAuthProvider.facebook:
      return 'Continue with Facebook';
    case SocialAuthProvider.github:
      return 'Continue with GitHub';
  }
}

IconData get _icon {
  switch (provider) {
    case SocialAuthProvider.google:
      return Icons.g_mobiledata;
    case SocialAuthProvider.apple:
      return Icons.apple;
    case SocialAuthProvider.facebook:
      return Icons.facebook;
    case SocialAuthProvider.github:
      return Icons.code;
  }
}

Color get _backgroundColor {
  switch (provider) {
    case SocialAuthProvider.google:
      return Colors.white;
    case SocialAuthProvider.apple:
      return Colors.black;
    case SocialAuthProvider.facebook:
      return const Color(0xFF1877F2);
    case SocialAuthProvider.github:
      return const Color(0xFF24292E);
  }
}

Color get _textColor {
  switch (provider) {
    case SocialAuthProvider.google:
      return Colors.black87;
    default:
      return Colors.white;
  }
}

@override
Widget build(BuildContext context) {
  return SizedBox(
    width: double.infinity,
    height: height,
    child: ElevatedButton(
      onPressed: isLoading ? null : onPressed, // This now works with nullable
      style: ElevatedButton.styleFrom(
        backgroundColor: _backgroundColor,
        foregroundColor: _textColor,
        elevation: provider == SocialAuthProvider.google ? 1 : 0,
        shadowColor: Colors.black12,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16),
          side: provider == SocialAuthProvider.google
              ? const BorderSide(color: Color(0xFFE0E0E0))
              : BorderSide.none,
        ),
        padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
      ),
      child: isLoading
          ? SizedBox(
              height: 24,
              width: 24,
              child: CircularProgressIndicator(
                strokeWidth: 2.5,
                valueColor: AlwaysStoppedAnimation<Color>(_textColor),
              ),
            )
          : Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Icon(_icon, size: 24),
                const SizedBox(width: 12),
                Text(
                  _buttonText,
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                    color: _textColor,
                  ),
                ),
              ],
            ),
    ),
  );
}
}
''';
}