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_bloc.dart';
|
||||||
import '../blocs/auth/auth_event.dart';
|
import '../blocs/auth/auth_event.dart';
|
||||||
import '../blocs/auth/auth_state.dart';
|
import '../blocs/auth/auth_state.dart';
|
||||||
|
import 'package:sign_in_button/sign_in_button.dart';
|
||||||
|
|
||||||
/// Login page widget for user authentication.
|
/// Login page widget for user authentication.
|
||||||
///
|
///
|
||||||
/// This page provides a user interface for signing in with email and password,
|
/// 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.
|
/// as well as options for social sign-in (Google, Apple) and password reset.
|
||||||
/// It integrates with the AuthBloc to handle authentication state management.
|
/// It integrates with the AuthBloc to handle authentication state management.
|
||||||
@@ -20,13 +21,13 @@ class LoginPage extends StatefulWidget {
|
|||||||
class _LoginPageState extends State<LoginPage> {
|
class _LoginPageState extends State<LoginPage> {
|
||||||
/// Form key for validation
|
/// Form key for validation
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
/// Controller for email input field
|
/// Controller for email input field
|
||||||
final _emailController = TextEditingController();
|
final _emailController = TextEditingController();
|
||||||
|
|
||||||
/// Controller for password input field
|
/// Controller for password input field
|
||||||
final _passwordController = TextEditingController();
|
final _passwordController = TextEditingController();
|
||||||
|
|
||||||
/// Whether the password field should hide its content
|
/// Whether the password field should hide its content
|
||||||
bool _obscurePassword = true;
|
bool _obscurePassword = true;
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validates email input.
|
/// Validates email input.
|
||||||
///
|
///
|
||||||
/// Returns an error message if the email is invalid or empty,
|
/// Returns an error message if the email is invalid or empty,
|
||||||
/// null if the email is valid.
|
/// null if the email is valid.
|
||||||
String? _validateEmail(String? value) {
|
String? _validateEmail(String? value) {
|
||||||
@@ -53,7 +54,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validates password input.
|
/// Validates password input.
|
||||||
///
|
///
|
||||||
/// Returns an error message if the password is empty,
|
/// Returns an error message if the password is empty,
|
||||||
/// null if the password is valid.
|
/// null if the password is valid.
|
||||||
String? _validatePassword(String? value) {
|
String? _validatePassword(String? value) {
|
||||||
@@ -64,7 +65,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the login process.
|
/// Handles the login process.
|
||||||
///
|
///
|
||||||
/// Validates the form and dispatches a sign-in event to the AuthBloc
|
/// Validates the form and dispatches a sign-in event to the AuthBloc
|
||||||
/// if all fields are valid.
|
/// if all fields are valid.
|
||||||
void _login(BuildContext context) {
|
void _login(BuildContext context) {
|
||||||
@@ -73,11 +74,11 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.read<AuthBloc>().add(
|
context.read<AuthBloc>().add(
|
||||||
AuthSignInRequested(
|
AuthSignInRequested(
|
||||||
email: _emailController.text.trim(),
|
email: _emailController.text.trim(),
|
||||||
password: _passwordController.text,
|
password: _passwordController.text,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -187,13 +188,25 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: isLoading ? null : () => _login(context),
|
onPressed: isLoading ? null : () => _login(context),
|
||||||
style: ElevatedButton.styleFrom(
|
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(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: isLoading
|
child: isLoading
|
||||||
? const CircularProgressIndicator(
|
? CircularProgressIndicator(
|
||||||
color: Colors.white,
|
color:
|
||||||
|
Theme.of(context).brightness ==
|
||||||
|
Brightness.dark
|
||||||
|
? Colors.black
|
||||||
|
: Colors.white,
|
||||||
)
|
)
|
||||||
: const Text(
|
: const Text(
|
||||||
'Se connecter',
|
'Se connecter',
|
||||||
@@ -236,104 +249,25 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// Social login buttons
|
SignInButton(
|
||||||
Row(
|
Buttons.google,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
onPressed: () {
|
||||||
children: [
|
context.read<AuthBloc>().add(
|
||||||
// Google
|
AuthGoogleSignInRequested(),
|
||||||
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'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
|
||||||
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
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
geoclue:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -944,6 +952,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.1"
|
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:
|
sign_in_with_apple:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ dependencies:
|
|||||||
firebase_storage: ^13.0.3
|
firebase_storage: ^13.0.3
|
||||||
url_launcher: ^6.3.2
|
url_launcher: ^6.3.2
|
||||||
sign_in_with_apple: ^7.0.1
|
sign_in_with_apple: ^7.0.1
|
||||||
|
sign_in_button: ^4.0.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: ^0.13.1
|
flutter_launcher_icons: ^0.13.1
|
||||||
|
|||||||
Reference in New Issue
Block a user