From 7cac50c8dee834354970bbc39a321e175bf40f1c Mon Sep 17 00:00:00 2001 From: Enzo Date: Mon, 13 Nov 2023 10:54:13 +0100 Subject: [PATCH] msg d'erreur pour login/createUser --- lib/Modele/Api/request_api.dart | 2 +- lib/View/login/login_view.dart | 34 +++++++++++++++++++++++++-------- lib/View/login/signup_view.dart | 24 +++++++++++++++++++---- lib/common/colo_extension.dart | 6 +++--- lib/main.dart | 3 --- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/lib/Modele/Api/request_api.dart b/lib/Modele/Api/request_api.dart index ba546ff..9ec2fee 100644 --- a/lib/Modele/Api/request_api.dart +++ b/lib/Modele/Api/request_api.dart @@ -93,7 +93,7 @@ class RequestApi extends IDataStrategy { return const Tuple2(false, "UNAUTHORIZED"); } if (response.statusCode == 404) { - return const Tuple2(false, "Not found"); + return const Tuple2(false, "Not found the email"); } return const Tuple2(false, "Fail"); } diff --git a/lib/View/login/login_view.dart b/lib/View/login/login_view.dart index 78f8cf5..5696e8d 100644 --- a/lib/View/login/login_view.dart +++ b/lib/View/login/login_view.dart @@ -20,7 +20,9 @@ class LoginView extends StatefulWidget { } class _LoginViewState extends State { - bool isCheck = false; + bool _obscureText = true; + String _msgError = ""; + bool _errorLogin = false; IDataStrategy api = RequestApi(); final controllerTextEmail = TextEditingController(); @@ -48,6 +50,13 @@ class _LoginViewState extends State { print(context.read()); } + // Toggles the password show status + void _toggle() { + setState(() { + _obscureText = !_obscureText; + }); + } + @override Widget build(BuildContext context) { var media = MediaQuery.of(context).size; @@ -91,9 +100,9 @@ class _LoginViewState extends State { controller: controllerTextPassword, hitText: "Mot de passe", icon: "assets/img/lock.svg", - obscureText: true, + obscureText: _obscureText, rigtIcon: TextButton( - onPressed: () {}, + onPressed: _toggle, child: Container( alignment: Alignment.center, width: 20, @@ -117,6 +126,10 @@ class _LoginViewState extends State { ), ], ), + Visibility( + visible: _errorLogin, + child: Text("Error - $_msgError", + style: TextStyle(color: TColor.red))), const Spacer(), RoundButton( title: "Se connecter", @@ -128,9 +141,12 @@ class _LoginViewState extends State { Tuple2 infoUser = await getUserInfo(result.item2); if (infoUser.item1 == false) { - print( - "Erreur - Impossible de récupéré les données de l'utilisateur"); - // Afficher pop-up + //print("Erreur - Impossible de récupéré les données de l'utilisateur"); + setState(() { + _msgError = + "Impossible de récupéré les données de l'utilisateur - {$infoUser.item2}"; + _errorLogin = true; + }); } else { fillUser(context, infoUser.item2, result.item2); @@ -140,8 +156,10 @@ class _LoginViewState extends State { builder: (context) => const TestPage())); } } else { - print("Connection refuser"); - //Afficher une pop-up + setState(() { + _msgError = "Connexion refuser - ${result.item2}"; + _errorLogin = true; + }); } }), SizedBox( diff --git a/lib/View/login/signup_view.dart b/lib/View/login/signup_view.dart index 6a90aea..0628621 100644 --- a/lib/View/login/signup_view.dart +++ b/lib/View/login/signup_view.dart @@ -18,7 +18,10 @@ class SignUpView extends StatefulWidget { } class _SignUpViewState extends State { + bool _obscureText = true; + bool _errorCreateUser = false; bool isCheck = false; + String _msgError = ""; IDataStrategy api = RequestApi(); final controllerTextEmail = TextEditingController(); @@ -32,6 +35,13 @@ class _SignUpViewState extends State { controllerTextUsername.text); } + // Toggles the password show status + void _toggle() { + setState(() { + _obscureText = !_obscureText; + }); + } + @override Widget build(BuildContext context) { var media = MediaQuery.of(context).size; @@ -77,10 +87,10 @@ class _SignUpViewState extends State { RoundTextField( hitText: "Mot de passe", icon: "assets/img/lock.svg", - obscureText: true, + obscureText: _obscureText, controller: controllerTextPassword, rigtIcon: TextButton( - onPressed: () {}, + onPressed: _toggle, child: Container( alignment: Alignment.center, width: 20, @@ -118,6 +128,10 @@ class _SignUpViewState extends State { ) ], ), + Visibility( + visible: _errorCreateUser, + child: Text("Error - $_msgError", + style: TextStyle(color: TColor.red))), SizedBox( height: media.width * 0.4, ), @@ -131,8 +145,10 @@ class _SignUpViewState extends State { MaterialPageRoute( builder: (context) => const LoginView())); } else { - print("Création de compte Impossible"); - print(result.item2); + setState(() { + _errorCreateUser = true; + _msgError = result.item2; + }); } }), SizedBox( diff --git a/lib/common/colo_extension.dart b/lib/common/colo_extension.dart index c1f31bf..aeb52ae 100644 --- a/lib/common/colo_extension.dart +++ b/lib/common/colo_extension.dart @@ -7,12 +7,12 @@ class TColor { static Color get secondaryColor1 => Color(0xff6131AD); static Color get secondaryColor2 => Color(0xffD4B9FF); - static List get primaryG => [ primaryColor2, primaryColor1 ]; + static List get primaryG => [primaryColor2, primaryColor1]; static List get secondaryG => [secondaryColor2, secondaryColor1]; static Color get black => const Color(0xff1D1617); static Color get gray => const Color(0xff786F72); static Color get white => Colors.white; static Color get lightGray => const Color(0xffF7F8F8); - -} \ No newline at end of file + static Color get red => const Color.fromARGB(255, 255, 0, 0); +} diff --git a/lib/main.dart b/lib/main.dart index ff58d38..2aad57e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smartfit_app_mobile/Modele/user.dart'; -import 'package:smartfit_app_mobile/View/login/login_view.dart'; import 'package:smartfit_app_mobile/View/login/signup_view.dart'; -import 'package:smartfit_app_mobile/View/on_boarding/started_view.dart'; -import 'package:smartfit_app_mobile/View/page_test.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart'; void main() {