|
|
|
@ -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<MobileChangeUsernameView> createState() => _MobileChangeUsernameViewState();
|
|
|
|
|
State<MobileChangeUsernameView> createState() =>
|
|
|
|
|
_MobileChangeUsernameViewState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
|
|
|
|
|
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<User>().username;
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
@ -44,16 +48,14 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
|
|
|
|
|
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<MobileChangeUsernameView> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
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<MobileChangeUsernameView> {
|
|
|
|
|
),
|
|
|
|
|
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<User>(context, listen: false).token,
|
|
|
|
|
infoManager);
|
|
|
|
|
if (res) {
|
|
|
|
|
Provider.of<User>(context, listen: false)
|
|
|
|
|
.username = controllerTextUsername.text;
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
@ -112,4 +130,4 @@ class _MobileChangeUsernameViewState extends State<MobileChangeUsernameView> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|