remove useless input editSettings
This commit is contained in:
parent
3bb85a198a
commit
b156cd084b
@ -208,7 +208,7 @@ class _EditProfileState extends State<EditProfile>
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Add or Update a event"),
|
title: Text("Update profile"),
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
import 'package:covas_mobile/classes/MyDrawer.dart';
|
import 'package:covas_mobile/classes/MyDrawer.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import '../classes/events.dart';
|
import '../classes/events.dart';
|
||||||
import '../classes/MyDrawer.dart';
|
import '../classes/MyDrawer.dart';
|
||||||
import '../main.dart';
|
|
||||||
|
|
||||||
import '../classes/alert.dart';
|
import '../classes/alert.dart';
|
||||||
import '../classes/eventAdded.dart';
|
import '../classes/eventAdded.dart';
|
||||||
|
|
||||||
import '../variable/globals.dart' as globals;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
}
|
}
|
||||||
@ -43,164 +38,9 @@ class _EditProfileState extends State<EditSettings>
|
|||||||
with ShowAlertDialog, ShowEventDialog {
|
with ShowAlertDialog, ShowEventDialog {
|
||||||
TextEditingController inputUserName = TextEditingController();
|
TextEditingController inputUserName = TextEditingController();
|
||||||
|
|
||||||
TextEditingController inputName = TextEditingController();
|
|
||||||
|
|
||||||
TextEditingController inputFirstName = TextEditingController();
|
|
||||||
TextEditingController inputEmail = TextEditingController();
|
|
||||||
TextEditingController inputBirth = TextEditingController();
|
|
||||||
TextEditingController inputPassword = TextEditingController();
|
|
||||||
TextEditingController inputPasswordConfirmed = TextEditingController();
|
|
||||||
|
|
||||||
onTapFunctionDatePicker({required BuildContext context}) async {
|
|
||||||
DateTime initialDate = DateTime.parse(formatDate(inputBirth.text));
|
|
||||||
|
|
||||||
DateTime? pickedDate = await showDatePicker(
|
|
||||||
context: context,
|
|
||||||
firstDate: DateTime(1900),
|
|
||||||
initialDate: initialDate,
|
|
||||||
lastDate: DateTime(2104));
|
|
||||||
if (pickedDate == null) return;
|
|
||||||
inputBirth.text = DateFormat("dd/MM/yyyy").format(pickedDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
convertNulltoEmptyString(var check) {
|
|
||||||
if (check == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return check;
|
|
||||||
}
|
|
||||||
|
|
||||||
convertNulltoArray(List<String> check) {
|
|
||||||
if (check == null) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return check;
|
|
||||||
}
|
|
||||||
|
|
||||||
String formatDate(String date) {
|
|
||||||
var splitedDate = date.split("/");
|
|
||||||
|
|
||||||
var day = splitedDate[0];
|
|
||||||
var month = splitedDate[1];
|
|
||||||
var year = splitedDate[2];
|
|
||||||
|
|
||||||
return "${year}-${month}-${day}";
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _updateProfile(BuildContext context) async {
|
|
||||||
var username = inputUserName.text;
|
|
||||||
var firstName = inputFirstName.text;
|
|
||||||
var name = inputName.text;
|
|
||||||
var email = inputEmail.text;
|
|
||||||
var password = inputPassword.text;
|
|
||||||
var confirmedPassword = inputPasswordConfirmed.text;
|
|
||||||
var birth = DateTime.parse(formatDate(inputBirth.text));
|
|
||||||
|
|
||||||
if ((password.isNotEmpty) && (confirmedPassword.isNotEmpty)) {
|
|
||||||
if (password != confirmedPassword) {
|
|
||||||
showAlertDialog(context, "Erreur", "Mot de passe different");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var urlPut = Uri.parse("${globals.api}/users/me");
|
|
||||||
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
|
||||||
if (accessToken.isNotEmpty) {
|
|
||||||
var responsePut = await http.put(urlPut,
|
|
||||||
headers: {
|
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
|
||||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
|
||||||
HttpHeaders.contentTypeHeader: 'application/json'
|
|
||||||
},
|
|
||||||
body: jsonEncode({
|
|
||||||
'name': name,
|
|
||||||
'username': username,
|
|
||||||
'firstName': firstName,
|
|
||||||
'password': password,
|
|
||||||
'email': email,
|
|
||||||
'roles': '',
|
|
||||||
'birth': birth.toString()
|
|
||||||
}));
|
|
||||||
print(responsePut.statusCode);
|
|
||||||
if (responsePut.statusCode == 200) {
|
|
||||||
showEventDialog(context, "Votre utilisateur a été modifié");
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context, MaterialPageRoute(builder: (_) => EditSettings()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final errorMessages = {
|
|
||||||
400: "Requête mal construite",
|
|
||||||
406: "Mot de passe incorrect",
|
|
||||||
404: "Utilisateur inconnu",
|
|
||||||
403: "Utilisateur désactivé",
|
|
||||||
410: "Token invalide",
|
|
||||||
500: "Problème interne du serveur",
|
|
||||||
};
|
|
||||||
|
|
||||||
final text = errorMessages[responsePut.statusCode] ??
|
|
||||||
"Problème d'authentification inconnu";
|
|
||||||
showAlertDialog(context, "Erreur serveur", text);
|
|
||||||
} else {
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _getInfoProfile() async {
|
|
||||||
var urlGet = Uri.parse("${globals.api}/users/me");
|
|
||||||
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
||||||
var accessToken = prefs.getString("access_token") ?? "";
|
|
||||||
if (accessToken.isNotEmpty) {
|
|
||||||
var responseGet = await http.get(urlGet, headers: {
|
|
||||||
HttpHeaders.cookieHeader: 'access_token=${accessToken}',
|
|
||||||
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
|
||||||
HttpHeaders.contentTypeHeader: 'application/json'
|
|
||||||
});
|
|
||||||
print(responseGet.statusCode);
|
|
||||||
if (responseGet.statusCode == 200) {
|
|
||||||
var body = json.decode(utf8.decode(responseGet.bodyBytes));
|
|
||||||
setState(() {
|
|
||||||
inputName.text = body["name"];
|
|
||||||
inputFirstName.text = body["firstName"];
|
|
||||||
inputUserName.text = body["username"];
|
|
||||||
inputEmail.text = body["email"];
|
|
||||||
inputBirth.text =
|
|
||||||
DateFormat("dd/MM/yyyy").format(DateTime.parse(body["birth"]));
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final errorMessages = {
|
|
||||||
400: "Requête mal construite",
|
|
||||||
406: "Mot de passe incorrect",
|
|
||||||
404: "Utilisateur inconnu",
|
|
||||||
403: "Utilisateur désactivé",
|
|
||||||
410: "Token invalide",
|
|
||||||
500: "Problème interne du serveur",
|
|
||||||
};
|
|
||||||
|
|
||||||
final text = errorMessages[responseGet.statusCode] ??
|
|
||||||
"Problème d'authentification inconnu";
|
|
||||||
showAlertDialog(context, "Erreur serveur", text);
|
|
||||||
} else {
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context, MaterialPageRoute(builder: (_) => LoginDemo()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_getInfoProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
|
||||||
String? _validateField(String? value) {
|
|
||||||
return value!.isEmpty ? 'Champ requis' : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -208,13 +48,12 @@ class _EditProfileState extends State<EditSettings>
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Add or Update a event"),
|
title: Text("Settings"),
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
),
|
),
|
||||||
drawer: MyDrawer(),
|
drawer: MyDrawer(),
|
||||||
body: Form(
|
body: Form(
|
||||||
key: _formKey,
|
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -224,92 +63,12 @@ class _EditProfileState extends State<EditSettings>
|
|||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: inputUserName,
|
controller: inputUserName,
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
labelText: 'Pseudo',
|
labelText: 'Pseudo',
|
||||||
hintText: 'Modifier le pseudo'),
|
hintText: 'Modifier le pseudo'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputPassword,
|
|
||||||
obscureText: true,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Mot de passe',
|
|
||||||
hintText: 'Entrez le mot de passe'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputPasswordConfirmed,
|
|
||||||
obscureText: true,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Confirmez le mot de passe',
|
|
||||||
hintText: 'Confirmez le mot de passe'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputName,
|
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Nom',
|
|
||||||
hintText: 'Modifier le nom'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputFirstName,
|
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Prénom',
|
|
||||||
hintText: 'Modifier le prénom'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputEmail,
|
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Email',
|
|
||||||
hintText: 'Modifier l\'adresse mail'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
||||||
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: inputBirth,
|
|
||||||
readOnly: true,
|
|
||||||
validator: (value) => _validateField(value),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Date de naissance',
|
|
||||||
hintText: 'Cliquez ici pour selectionner une date'),
|
|
||||||
onTap: () => onTapFunctionDatePicker(context: context)),
|
|
||||||
),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 30,
|
height: 30,
|
||||||
),
|
),
|
||||||
@ -320,13 +79,9 @@ class _EditProfileState extends State<EditSettings>
|
|||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
borderRadius: BorderRadius.circular(20)),
|
borderRadius: BorderRadius.circular(20)),
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {},
|
||||||
if (_formKey.currentState!.validate()) {
|
|
||||||
_updateProfile(context);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Text(
|
child: Text(
|
||||||
'Modifier le profil',
|
'Mettre à jour les paramètres',
|
||||||
style: TextStyle(color: Colors.white, fontSize: 25),
|
style: TextStyle(color: Colors.white, fontSize: 25),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user