You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 line
1.7KB

  1. import 'package:flutter/material.dart';
  2. import '../../../data/services/auth_service.dart'; // Assurez-vous que le chemin est correct
  3. class LoginScreen extends StatefulWidget {
  4. const LoginScreen({super.key});
  5. @override
  6. State<LoginScreen> createState() => _LoginScreenState();
  7. }
  8. class _LoginScreenState extends State<LoginScreen> {
  9. final AuthService _authService = AuthService();
  10. bool _isLoading = false;
  11. void _handleFacebookLogin() async {
  12. setState(() {
  13. _isLoading = true;
  14. });
  15. final bool success = await _authService.loginWithFacebook();
  16. setState(() {
  17. _isLoading = false;
  18. });
  19. if (success && mounted) {
  20. // Naviguer vers l'écran principal de l'application
  21. // Par exemple :
  22. Navigator.of(context).pushReplacementNamed('/home');
  23. } else if (mounted) {
  24. // Afficher un message d'erreur
  25. ScaffoldMessenger.of(context).showSnackBar(
  26. const SnackBar(content: Text("La connexion a échoué. Veuillez réessayer.")),
  27. );
  28. }
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return Scaffold(
  33. appBar: AppBar(title: const Text("Connexion")),
  34. body: Center(
  35. child: _isLoading
  36. ? const CircularProgressIndicator()
  37. : ElevatedButton.icon(
  38. icon: const Icon(Icons.facebook),
  39. label: const Text("Se connecter avec Facebook"),
  40. onPressed: _handleFacebookLogin,
  41. style: ElevatedButton.styleFrom(
  42. backgroundColor: const Color(0xFF1877F2), // Couleur de Facebook
  43. foregroundColor: Colors.white,
  44. padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
  45. ),
  46. ),
  47. ),
  48. );
  49. }
  50. }