fAdd phone number support to user authentication events and methods
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:sign_in_button/sign_in_button.dart';
|
||||
import 'package:travel_mate/components/loading/laoding_content.dart';
|
||||
import 'package:travel_mate/components/signup/sign_up_platform_content.dart';
|
||||
import '../blocs/auth/auth_bloc.dart';
|
||||
import '../blocs/auth/auth_event.dart';
|
||||
import '../blocs/auth/auth_state.dart';
|
||||
import '../services/error_service.dart';
|
||||
|
||||
class SignUpPage extends StatefulWidget {
|
||||
const SignUpPage({super.key});
|
||||
@@ -18,10 +22,13 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _confirmPasswordController = TextEditingController();
|
||||
final _phoneNumberController = TextEditingController();
|
||||
|
||||
bool _obscurePassword = true;
|
||||
bool _obscureConfirmPassword = true;
|
||||
|
||||
final _errorService = ErrorService();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nomController.dispose();
|
||||
@@ -76,13 +83,14 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
}
|
||||
|
||||
context.read<AuthBloc>().add(
|
||||
AuthSignUpRequested(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
nom: _nomController.text.trim(),
|
||||
prenom: _prenomController.text.trim(),
|
||||
),
|
||||
);
|
||||
AuthSignUpRequested(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
nom: _nomController.text.trim(),
|
||||
prenom: _prenomController.text.trim(),
|
||||
phoneNumber: _phoneNumberController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -107,11 +115,8 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
);
|
||||
Navigator.pushReplacementNamed(context, '/home');
|
||||
} else if (state is AuthError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
_errorService.showError(
|
||||
message: 'Erreur lors de la création du compte',
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -129,7 +134,10 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
const SizedBox(height: 40),
|
||||
const Text(
|
||||
'Créer un compte',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
@@ -166,6 +174,21 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Champ Numéro de téléphone
|
||||
TextFormField(
|
||||
controller: _phoneNumberController,
|
||||
validator: (value) =>
|
||||
_validateField(value, 'Numéro de téléphone'),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Numéro de téléphone',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
),
|
||||
prefixIcon: Icon(Icons.phone),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Champ Email
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
@@ -227,7 +250,8 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscureConfirmPassword = !_obscureConfirmPassword;
|
||||
_obscureConfirmPassword =
|
||||
!_obscureConfirmPassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -247,8 +271,13 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? const CircularProgressIndicator(color: Colors.white)
|
||||
: const Text('S\'inscrire', style: TextStyle(fontSize: 18)),
|
||||
? const CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
)
|
||||
: const Text(
|
||||
'S\'inscrire',
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
@@ -270,6 +299,86 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Divider
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 1,
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
const Text(
|
||||
'Ou inscrivez-vous avec',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
SignInButton(
|
||||
Buttons.google,
|
||||
onPressed: () async {
|
||||
// Afficher la page de loading
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LoadingContent(
|
||||
onBackgroundTask: () async {
|
||||
// Effectuer la requête vers Google
|
||||
final platformData = await _fetchGoogleSignInData();
|
||||
return platformData;
|
||||
},
|
||||
onComplete: () {
|
||||
// Fermer le loading et naviguer vers SignUpPlatformContent
|
||||
Navigator.pop(context); // Fermer LoadingContent
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SignUpPlatformContent(platform: 'google'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
SignInButton(
|
||||
Buttons.apple,
|
||||
onPressed: () async {
|
||||
// Afficher la page de loading
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LoadingContent(
|
||||
onBackgroundTask: () async {
|
||||
// Effectuer la requête vers Google
|
||||
final platformData = await
|
||||
return platformData;
|
||||
},
|
||||
onComplete: () {
|
||||
// Fermer le loading et naviguer vers SignUpPlatformContent
|
||||
Navigator.pop(context); // Fermer LoadingContent
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SignUpPlatformContent(platform: 'apple'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -280,4 +389,4 @@ class _SignUpPageState extends State<SignUpPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user