add username change + add consts in profile pages

profile
remrem 1 year ago
parent 73dfc4e76f
commit 94b5470cb5

@ -1,25 +1,29 @@
import 'package:provider/provider.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
class MobileChangeUsernameView extends StatefulWidget { class MobileChangeUsernameView extends StatefulWidget {
const MobileChangeUsernameView({super.key}); const MobileChangeUsernameView({super.key});
@override @override
State<MobileChangeUsernameView> createState() => _MobileChangeUsernameViewState(); State<MobileChangeUsernameView> createState() =>
_MobileChangeUsernameViewState();
} }
class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> { class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerTextUsername = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final InfoMessage infoManager = InfoMessage();
String oldUsername = "Ancien pseudo"; final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
String userUsername = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,9 +48,7 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son pseudo", "Changer son pseudo",
@ -75,7 +77,7 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
), ),
), ),
Text( Text(
oldUsername, // Utilisez votre ancien pseudo ici userUsername, // Utilisez votre ancien pseudo ici
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -91,17 +93,33 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
), ),
child: Column( child: Column(
children: [ children: [
RoundTextField( RoundTextField(
hitText: "Nouveau pseudo", hitText: "Nouveau pseudo",
icon: "assets/img/user_text.svg", icon: "assets/img/user_text.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerTextUsername,
), ),
SizedBox(height: media.width * 0.07), SizedBox(height: media.width * 0.07),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(height: media.width * 0.02),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
bool res = await api.modifyUserInfo(
'username',
controllerTextUsername.text,
Provider.of<User>(context, listen: false).token,
infoManager);
if (res) {
Provider.of<User>(context, listen: false)
.username = controllerTextUsername.text;
}
setState(() {});
}),
], ],
), ),
), ),

@ -1,5 +1,7 @@
import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:animated_toggle_switch/animated_toggle_switch.dart'; import 'package:animated_toggle_switch/animated_toggle_switch.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/setting_row.dart'; import 'package:smartfit_app_mobile/common_widget/setting_row.dart';
@ -48,6 +50,8 @@ class _MobileProfileView extends State<MobileProfileView> {
]; ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String username = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: TColor.white, backgroundColor: TColor.white,
@ -106,7 +110,7 @@ class _MobileProfileView extends State<MobileProfileView> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
"Benjelloun Othmane", username,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
@ -214,21 +218,23 @@ class _MobileProfileView extends State<MobileProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeUsernameView(), builder: (context) =>
const ChangeUsernameView(),
), ),
); );
} else if (iObj["tag"] == "2") { } else if (iObj["tag"] == "2") {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangePasswordView(), builder: (context) =>
const ChangePasswordView(),
), ),
); );
} else { } else {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeEmailView(), builder: (context) => const ChangeEmailView(),
), ),
); );
} }
@ -388,14 +394,15 @@ class _MobileProfileView extends State<MobileProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => PrivacyPolicyView(), builder: (context) =>
const PrivacyPolicyView(),
), ),
); );
} else if (iObj["tag"] == "5") { } else if (iObj["tag"] == "5") {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ContactUsView(), builder: (context) => const ContactUsView(),
), ),
); );
} else { } else {

@ -1,9 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:smartfit_app_mobile/modele/user.dart';
import 'package:provider/provider.dart';
import 'package:smartfit_app_mobile/common/colo_extension.dart'; import 'package:smartfit_app_mobile/common/colo_extension.dart';
import 'package:smartfit_app_mobile/common_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/button/round_button.dart';
import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart'; import 'package:smartfit_app_mobile/common_widget/text_field/round_text_field.dart';
import 'package:smartfit_app_mobile/modele/api/api_wrapper.dart';
import 'package:smartfit_app_mobile/modele/utile/info_message.dart';
class WebChangeUsernameView extends StatefulWidget { class WebChangeUsernameView extends StatefulWidget {
const WebChangeUsernameView({super.key}); const WebChangeUsernameView({super.key});
@ -13,13 +15,14 @@ class WebChangeUsernameView extends StatefulWidget {
} }
class _WebChangeUsernameViewState extends State<WebChangeUsernameView> { class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
final TextEditingController controllerTextEmail = TextEditingController(); final TextEditingController controllerTextUsername = TextEditingController();
final TextEditingController controllerTextPassword = TextEditingController(); final InfoMessage infoManager = InfoMessage();
String oldUsername = "Ancien pseudo"; final ApiWrapper api = ApiWrapper();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var media = MediaQuery.of(context).size; var media = MediaQuery.of(context).size;
String userUsername = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -44,9 +47,7 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
height: 15, height: 15,
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
), ),
title: Text( title: Text(
"Changer son pseudo", "Changer son pseudo",
@ -75,7 +76,7 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
), ),
), ),
Text( Text(
oldUsername, // Utilisez votre ancien pseudo ici userUsername,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 16, fontSize: 16,
@ -91,17 +92,35 @@ class _WebChangeUsernameViewState extends State<WebChangeUsernameView> {
), ),
child: Column( child: Column(
children: [ children: [
RoundTextField( RoundTextField(
hitText: "Nouveau pseudo", hitText: "Nouveau pseudo",
icon: "assets/img/user_text.svg", icon: "assets/img/user_text.svg",
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
controller: controllerTextEmail, controller: controllerTextUsername,
), ),
SizedBox(
height: media.width * 0.01,
),
Visibility(
visible: infoManager.isVisible,
child: Text(infoManager.message,
style:
TextStyle(color: infoManager.messageColor))),
SizedBox(height: media.width * 0.04), SizedBox(height: media.width * 0.04),
RoundButton( RoundButton(
title: "Confirmer", title: "Confirmer",
onPressed: () {}), onPressed: () async {
bool res = await api.modifyUserInfo(
'username',
controllerTextUsername.text,
Provider.of<User>(context, listen: false).token,
infoManager);
if (res) {
Provider.of<User>(context, listen: false)
.username = controllerTextUsername.text;
}
setState(() {});
}),
], ],
), ),
), ),

@ -50,7 +50,7 @@ class _WebProfileView extends State<WebProfileView> {
]; ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String _username = context.watch<User>().username; String username = context.watch<User>().username;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -110,7 +110,7 @@ class _WebProfileView extends State<WebProfileView> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
_username, username,
style: TextStyle( style: TextStyle(
color: TColor.black, color: TColor.black,
fontSize: 14, fontSize: 14,
@ -234,7 +234,7 @@ class _WebProfileView extends State<WebProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeEmailView(), builder: (context) => const ChangeEmailView(),
), ),
); );
} }
@ -402,7 +402,7 @@ class _WebProfileView extends State<WebProfileView> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ContactUsView(), builder: (context) => const ContactUsView(),
), ),
); );
} else { } else {

Loading…
Cancel
Save