Modified SignInButton for Google and Apple login options in the login page
This commit is contained in:
@@ -3,9 +3,10 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../blocs/auth/auth_bloc.dart';
|
||||
import '../blocs/auth/auth_event.dart';
|
||||
import '../blocs/auth/auth_state.dart';
|
||||
import 'package:sign_in_button/sign_in_button.dart';
|
||||
|
||||
/// Login page widget for user authentication.
|
||||
///
|
||||
///
|
||||
/// This page provides a user interface for signing in with email and password,
|
||||
/// as well as options for social sign-in (Google, Apple) and password reset.
|
||||
/// It integrates with the AuthBloc to handle authentication state management.
|
||||
@@ -20,13 +21,13 @@ class LoginPage extends StatefulWidget {
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
/// Form key for validation
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
|
||||
/// Controller for email input field
|
||||
final _emailController = TextEditingController();
|
||||
|
||||
|
||||
/// Controller for password input field
|
||||
final _passwordController = TextEditingController();
|
||||
|
||||
|
||||
/// Whether the password field should hide its content
|
||||
bool _obscurePassword = true;
|
||||
|
||||
@@ -38,7 +39,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
|
||||
/// Validates email input.
|
||||
///
|
||||
///
|
||||
/// Returns an error message if the email is invalid or empty,
|
||||
/// null if the email is valid.
|
||||
String? _validateEmail(String? value) {
|
||||
@@ -53,7 +54,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
|
||||
/// Validates password input.
|
||||
///
|
||||
///
|
||||
/// Returns an error message if the password is empty,
|
||||
/// null if the password is valid.
|
||||
String? _validatePassword(String? value) {
|
||||
@@ -64,7 +65,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
|
||||
/// Handles the login process.
|
||||
///
|
||||
///
|
||||
/// Validates the form and dispatches a sign-in event to the AuthBloc
|
||||
/// if all fields are valid.
|
||||
void _login(BuildContext context) {
|
||||
@@ -73,11 +74,11 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
|
||||
context.read<AuthBloc>().add(
|
||||
AuthSignInRequested(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
),
|
||||
);
|
||||
AuthSignInRequested(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -187,13 +188,25 @@ class _LoginPageState extends State<LoginPage> {
|
||||
child: ElevatedButton(
|
||||
onPressed: isLoading ? null : () => _login(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
Theme.of(context).brightness == Brightness.dark
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
foregroundColor:
|
||||
Theme.of(context).brightness == Brightness.dark
|
||||
? Colors.black
|
||||
: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? const CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
? CircularProgressIndicator(
|
||||
color:
|
||||
Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? Colors.black
|
||||
: Colors.white,
|
||||
)
|
||||
: const Text(
|
||||
'Se connecter',
|
||||
@@ -236,104 +249,25 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Social login buttons
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Google
|
||||
Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: isLoading
|
||||
? null
|
||||
: () {
|
||||
context
|
||||
.read<AuthBloc>()
|
||||
.add(AuthGoogleSignInRequested());
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withValues(alpha: 0.3),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 3,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Image.asset(
|
||||
'assets/icons/google.png',
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text('Google'),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(width: 40),
|
||||
|
||||
// Apple
|
||||
Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: isLoading
|
||||
? null
|
||||
: () {
|
||||
context
|
||||
.read<AuthBloc>()
|
||||
.add(AuthAppleSignInRequested());
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withValues(alpha: 0.3),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 3,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade300,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Image.asset(
|
||||
'assets/icons/apple_white.png',
|
||||
width: 24,
|
||||
height: 24,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text('Apple'),
|
||||
],
|
||||
),
|
||||
],
|
||||
SignInButton(
|
||||
Buttons.google,
|
||||
onPressed: () {
|
||||
context.read<AuthBloc>().add(
|
||||
AuthGoogleSignInRequested(),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(height: 40),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
SignInButton(
|
||||
Buttons.apple,
|
||||
onPressed: () {
|
||||
context.read<AuthBloc>().add(
|
||||
AuthAppleSignInRequested(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -344,4 +278,4 @@ class _LoginPageState extends State<LoginPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
pubspec.lock
16
pubspec.lock
@@ -376,6 +376,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
font_awesome_flutter:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: font_awesome_flutter
|
||||
sha256: b9011df3a1fa02993630b8fb83526368cf2206a711259830325bab2f1d2a4eb0
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.12.0"
|
||||
geoclue:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -944,6 +952,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
sign_in_button:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sign_in_button
|
||||
sha256: "7bcd5e3ca5f80578da6a92b8749badf4003cf4dc578b5cb737b9082871354ff8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
sign_in_with_apple:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -56,6 +56,7 @@ dependencies:
|
||||
firebase_storage: ^13.0.3
|
||||
url_launcher: ^6.3.2
|
||||
sign_in_with_apple: ^7.0.1
|
||||
sign_in_button: ^4.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: ^0.13.1
|
||||
|
||||
Reference in New Issue
Block a user