pull/28/head
Lucas Delanier 2 years ago
parent 2c11b6f44a
commit 75c7139442

@ -60,7 +60,7 @@ class MyApp extends StatelessWidget {
// is not restarted.
primarySwatch: Colors.blue,
),
home: LoginScreen());
home: WellcomeScreen());
},
designSize: Size(390, 844),
);

@ -1,14 +1,9 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:justmusic/model/User.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import '../../main.dart';
class UserMapper {
static User? toModel(DocumentSnapshot<Map<String, dynamic>>? snapshot,
static User toModel(DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options) {
if (snapshot == null) {
return null;
}
final data = snapshot.data();
return User(
data?["uid"],

@ -30,11 +30,10 @@ class _LoginScreenState extends State<LoginScreen> {
.login(_userMailTextField.text, _passwordTextField.text);
Navigator.pushNamed(context, '/explanation');
} catch (e) {
print(e);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
e.toString(),
"Erreur: Email ou mot de passe incorrect",
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
@ -71,7 +70,7 @@ class _LoginScreenState extends State<LoginScreen> {
CrossAxisAlignment.center,
children: [
Flexible(
flex: 5,
flex: 4,
child: Padding(
padding: EdgeInsets.only(bottom: 60),
child: Column(
@ -108,10 +107,12 @@ class _LoginScreenState extends State<LoginScreen> {
),
),
Expanded(
flex: 4,
flex: 5,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.end,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
TextFormField(
controller: _userMailTextField,
@ -138,25 +139,24 @@ class _LoginScreenState extends State<LoginScreen> {
strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
contentPadding:
EdgeInsets.only(
top: 0,
bottom: 0,
left: defaultPadding),
prefix: const Padding(
padding: EdgeInsets.only(
left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(
left: 20.0)),
fillColor: bgTextField,
filled: true,
errorStyle: TextStyle(
fontSize: 9, height: 0.3),
focusColor: Color.fromRGBO(
255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color:
strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
borderSide:
BorderSide(width: 1, color: strokeTextField),
borderRadius: BorderRadius.all(Radius.circular(10))),
hintText: 'Email',
hintStyle:
GoogleFonts.plusJakartaSans(color: strokeTextField)),
hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField)),
),
SizedBox(
height: 18,
@ -174,8 +174,6 @@ class _LoginScreenState extends State<LoginScreen> {
return null;
},
cursorColor: primaryColor,
keyboardType:
TextInputType.emailAddress,
style:
GoogleFonts.plusJakartaSans(
color: primaryColor),
@ -190,10 +188,6 @@ class _LoginScreenState extends State<LoginScreen> {
BorderRadius.all(
Radius.circular(
10))),
contentPadding: EdgeInsets.only(
top: 0,
bottom: 0,
left: defaultPadding),
fillColor: bgTextField,
filled: true,
focusColor: Color.fromRGBO(
@ -212,6 +206,9 @@ class _LoginScreenState extends State<LoginScreen> {
hintStyle:
GoogleFonts.plusJakartaSans(
color: strokeTextField),
prefix: const Padding(
padding: EdgeInsets.only(
left: 20.0)),
suffixIcon: Container(
padding: EdgeInsets.only(
right: 10),
@ -240,6 +237,8 @@ class _LoginScreenState extends State<LoginScreen> {
height: 2,
),
)),
errorStyle: TextStyle(
fontSize: 9, height: 0.3),
),
),
Padding(
@ -259,6 +258,46 @@ class _LoginScreenState extends State<LoginScreen> {
child: LoginButton(
callback: handleLogin,
)),
Align(
child: GestureDetector(
onTap: () {
Navigator.pushNamed(
context, '/register');
},
child: Padding(
padding:
EdgeInsets.only(top: 20),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
text:
'Pas encore inscrit?',
style: GoogleFonts
.plusJakartaSans(
color:
Colors.white,
fontWeight:
FontWeight
.w400,
fontSize: 15),
children: <TextSpan>[
TextSpan(
text: " Sinscire",
style: GoogleFonts
.plusJakartaSans(
fontSize:
15,
fontWeight:
FontWeight
.w400,
color:
primaryColor)),
],
),
),
),
),
),
],
),
),
@ -321,38 +360,6 @@ class _LoginScreenState extends State<LoginScreen> {
text: "Login with Google",
onPressed: () {},
),
Padding(
padding:
EdgeInsets.only(top: 20),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
text:
'Pas encore inscrit?',
style: GoogleFonts
.plusJakartaSans(
color:
Colors.white,
fontWeight:
FontWeight
.w400,
fontSize: 13),
children: <TextSpan>[
TextSpan(
text: " Sinscire",
style: GoogleFonts
.plusJakartaSans(
fontSize:
13,
fontWeight:
FontWeight
.w400,
color:
primaryColor)),
],
),
),
)
],
),
))

@ -292,6 +292,34 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
callback: () {},
)),
),
Align(
child: GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/login');
},
child: Padding(
padding: EdgeInsets.only(top: 20),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: 'Tu as déjà un compte?',
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 15),
children: <TextSpan>[
TextSpan(
text: " Connexion",
style: GoogleFonts.plusJakartaSans(
fontSize: 15,
fontWeight: FontWeight.w400,
color: primaryColor)),
],
),
),
),
),
),
],
)),
SizedBox(height: 50.h),

@ -71,12 +71,20 @@ class WellcomeScreen extends StatelessWidget {
SizedBox(
height: defaultPadding,
),
Text(
"Tu as déja un compte? Connexion",
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 15),
GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/login');
},
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Text(
"Tu as déja un compte? Connexion",
style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 15),
),
),
),
],
),

@ -1,4 +1,3 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'package:justmusic/service/AuthService.dart';
@ -25,19 +24,17 @@ class UserViewModel {
}
login(String pseudo, String password) async {
await _authService.login(pseudo, password);
if (firebase_auth.FirebaseAuth.instance.currentUser == null) {
throw Exception("User login failed");
try {
await _authService.login(pseudo, password);
final user = await MyApp.db
.collection("users")
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
.get();
User data = UserMapper.toModel(user, null);
_userCurrent = data;
} catch (e) {
throw Exception("Erreur: Email ou mot de passe incorrect");
}
final user = await MyApp.db
.collection("users")
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
.get();
User? data = UserMapper.toModel(user, null);
if (data == null) {
throw Exception("User login failed");
}
_userCurrent = data;
}
register(String pseudo, String password, String email) async {
@ -47,9 +44,6 @@ class UserViewModel {
.doc(firebase_auth.FirebaseAuth.instance.currentUser?.uid)
.get();
User? data = UserMapper.toModel(user, null);
if (data == null) {
throw Exception("User register failed");
}
_userCurrent = data;
}

Loading…
Cancel
Save