diff --git a/lib/view/profile/mobile/mobile_change_username.dart b/lib/view/profile/mobile/mobile_change_username.dart index 66f2abb..3aa1367 100644 --- a/lib/view/profile/mobile/mobile_change_username.dart +++ b/lib/view/profile/mobile/mobile_change_username.dart @@ -1,25 +1,29 @@ +import 'package:provider/provider.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_widget/button/round_button.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 { const MobileChangeUsernameView({super.key}); @override - State createState() => _MobileChangeUsernameViewState(); + State createState() => + _MobileChangeUsernameViewState(); } class _MobileChangeUsernameViewState extends State { - final TextEditingController controllerTextEmail = TextEditingController(); - final TextEditingController controllerTextPassword = TextEditingController(); - String oldUsername = "Ancien pseudo"; + final TextEditingController controllerTextUsername = TextEditingController(); + final InfoMessage infoManager = InfoMessage(); + final ApiWrapper api = ApiWrapper(); @override Widget build(BuildContext context) { var media = MediaQuery.of(context).size; + String userUsername = context.watch().username; return Scaffold( appBar: AppBar( @@ -44,16 +48,14 @@ class _MobileChangeUsernameViewState extends State { height: 15, fit: BoxFit.contain, ), - ), - ), - title: Text( + title: Text( "Changer son pseudo", style: TextStyle( color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), ), - ), + ), backgroundColor: TColor.white, body: Column( children: [ @@ -75,7 +77,7 @@ class _MobileChangeUsernameViewState extends State { ), ), Text( - oldUsername, // Utilisez votre ancien pseudo ici + userUsername, // Utilisez votre ancien pseudo ici style: TextStyle( color: TColor.black, fontSize: 16, @@ -91,17 +93,33 @@ class _MobileChangeUsernameViewState extends State { ), child: Column( children: [ - RoundTextField( hitText: "Nouveau pseudo", icon: "assets/img/user_text.svg", keyboardType: TextInputType.text, - controller: controllerTextEmail, + controller: controllerTextUsername, ), 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( - title: "Confirmer", - onPressed: () {}), + title: "Confirmer", + onPressed: () async { + bool res = await api.modifyUserInfo( + 'username', + controllerTextUsername.text, + Provider.of(context, listen: false).token, + infoManager); + if (res) { + Provider.of(context, listen: false) + .username = controllerTextUsername.text; + } + setState(() {}); + }), ], ), ), @@ -112,4 +130,4 @@ class _MobileChangeUsernameViewState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/view/profile/mobile/mobile_profile_view.dart b/lib/view/profile/mobile/mobile_profile_view.dart index b60212f..97dbbf9 100644 --- a/lib/view/profile/mobile/mobile_profile_view.dart +++ b/lib/view/profile/mobile/mobile_profile_view.dart @@ -1,5 +1,7 @@ +import 'package:smartfit_app_mobile/modele/user.dart'; import 'package:flutter/material.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_widget/button/round_button.dart'; import 'package:smartfit_app_mobile/common_widget/setting_row.dart'; @@ -48,6 +50,8 @@ class _MobileProfileView extends State { ]; @override Widget build(BuildContext context) { + String username = context.watch().username; + return Scaffold( appBar: AppBar( backgroundColor: TColor.white, @@ -106,7 +110,7 @@ class _MobileProfileView extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "Benjelloun Othmane", + username, style: TextStyle( color: TColor.black, fontSize: 14, @@ -214,21 +218,23 @@ class _MobileProfileView extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => ChangeUsernameView(), + builder: (context) => + const ChangeUsernameView(), ), ); } else if (iObj["tag"] == "2") { Navigator.push( context, MaterialPageRoute( - builder: (context) => ChangePasswordView(), + builder: (context) => + const ChangePasswordView(), ), ); } else { Navigator.push( context, MaterialPageRoute( - builder: (context) => ChangeEmailView(), + builder: (context) => const ChangeEmailView(), ), ); } @@ -388,14 +394,15 @@ class _MobileProfileView extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => PrivacyPolicyView(), + builder: (context) => + const PrivacyPolicyView(), ), ); } else if (iObj["tag"] == "5") { Navigator.push( context, MaterialPageRoute( - builder: (context) => ContactUsView(), + builder: (context) => const ContactUsView(), ), ); } else { diff --git a/lib/view/profile/web/web_change_username.dart b/lib/view/profile/web/web_change_username.dart index 53f99ce..f00c301 100644 --- a/lib/view/profile/web/web_change_username.dart +++ b/lib/view/profile/web/web_change_username.dart @@ -1,9 +1,11 @@ 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_widget/button/round_button.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 { const WebChangeUsernameView({super.key}); @@ -13,13 +15,14 @@ class WebChangeUsernameView extends StatefulWidget { } class _WebChangeUsernameViewState extends State { - final TextEditingController controllerTextEmail = TextEditingController(); - final TextEditingController controllerTextPassword = TextEditingController(); - String oldUsername = "Ancien pseudo"; + final TextEditingController controllerTextUsername = TextEditingController(); + final InfoMessage infoManager = InfoMessage(); + final ApiWrapper api = ApiWrapper(); @override Widget build(BuildContext context) { var media = MediaQuery.of(context).size; + String userUsername = context.watch().username; return Scaffold( appBar: AppBar( @@ -44,16 +47,14 @@ class _WebChangeUsernameViewState extends State { height: 15, fit: BoxFit.contain, ), - ), - ), - title: Text( + title: Text( "Changer son pseudo", style: TextStyle( color: TColor.black, fontSize: 16, fontWeight: FontWeight.w700), ), - ), + ), backgroundColor: TColor.white, body: Column( children: [ @@ -75,7 +76,7 @@ class _WebChangeUsernameViewState extends State { ), ), Text( - oldUsername, // Utilisez votre ancien pseudo ici + userUsername, style: TextStyle( color: TColor.black, fontSize: 16, @@ -91,17 +92,35 @@ class _WebChangeUsernameViewState extends State { ), child: Column( children: [ - RoundTextField( hitText: "Nouveau pseudo", icon: "assets/img/user_text.svg", 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), RoundButton( - title: "Confirmer", - onPressed: () {}), + title: "Confirmer", + onPressed: () async { + bool res = await api.modifyUserInfo( + 'username', + controllerTextUsername.text, + Provider.of(context, listen: false).token, + infoManager); + if (res) { + Provider.of(context, listen: false) + .username = controllerTextUsername.text; + } + setState(() {}); + }), ], ), ), @@ -112,4 +131,4 @@ class _WebChangeUsernameViewState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/view/profile/web/web_profile_view.dart b/lib/view/profile/web/web_profile_view.dart index 23b2ca2..9b11d17 100644 --- a/lib/view/profile/web/web_profile_view.dart +++ b/lib/view/profile/web/web_profile_view.dart @@ -50,7 +50,7 @@ class _WebProfileView extends State { ]; @override Widget build(BuildContext context) { - String _username = context.watch().username; + String username = context.watch().username; return Scaffold( appBar: AppBar( @@ -110,7 +110,7 @@ class _WebProfileView extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - _username, + username, style: TextStyle( color: TColor.black, fontSize: 14, @@ -234,7 +234,7 @@ class _WebProfileView extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => ChangeEmailView(), + builder: (context) => const ChangeEmailView(), ), ); } @@ -402,7 +402,7 @@ class _WebProfileView extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => ContactUsView(), + builder: (context) => const ContactUsView(), ), ); } else {