Feat: done features change password and change number

This commit is contained in:
orangdeso 2025-05-13 23:04:02 +07:00
parent d9e479d162
commit 9e29e29a6b
2 changed files with 193 additions and 72 deletions

View File

@ -0,0 +1,105 @@
import 'package:e_porter/_core/component/appbar/appbar_component.dart';
import 'package:e_porter/_core/component/button/button_fill.dart';
import 'package:e_porter/_core/component/card/custome_shadow_cotainner.dart';
import 'package:e_porter/_core/component/text/custom_text.dart';
import 'package:e_porter/_core/constants/colors.dart';
import 'package:e_porter/_core/validators/validators.dart';
import 'package:e_porter/presentation/controllers/profil_controller.dart';
import 'package:e_porter/presentation/screens/auth/component/Input_form.dart';
import 'package:e_porter/presentation/screens/auth/component/Input_password.dart';
import 'package:e_porter/presentation/screens/profile/component/header_information.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class ChangeNumberScreen extends StatefulWidget {
const ChangeNumberScreen({super.key});
@override
State<ChangeNumberScreen> createState() => _ChangeNumberScreenState();
}
class _ChangeNumberScreenState extends State<ChangeNumberScreen> {
final _authController = Get.find<ProfilController>();
final _formKey = GlobalKey<FormState>();
final _oldPassword = TextEditingController();
final _phoneNumber = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: GrayColors.gray50,
appBar: DefaultAppbarComponent(
title: 'Ganti Nomor Telepon',
textColor: Colors.white,
backgroundColors: PrimaryColors.primary800,
onTab: () {
Get.back();
},
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.h),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
HeaderInformation(
title:
'Apakah anda yakin ingin mengganti nomor telepon akun?. Silahkan masukkan password lama anda sebagai verifikasi dan nomor telepon baru anda',
),
SizedBox(height: 32.h),
CustomText.textPadding8('Password Lama'),
SizedBox(height: 16.h),
InputPassword(
controller: _oldPassword,
hintText: '••••••••••',
svgIconPath: 'assets/icons/ic_padlock.svg',
validator: Validators.validatorPassword,
),
SizedBox(height: 20.h),
CustomText.textPadding8('Nomor Telepon'),
SizedBox(height: 16.h),
InputForm(
controller: _phoneNumber,
hintText: '0821xx',
svgIconPath: 'assets/icons/ic_phone.svg',
validator: Validators.validatorPhone,
textInputType: TextInputType.number,
),
],
),
),
),
),
),
bottomNavigationBar: Obx(
() {
return CustomeShadowCotainner(
child: _authController.isChangingPhone.value
? Center(
child: CircularProgressIndicator(color: PrimaryColors.primary800),
)
: ButtonFill(
text: 'Simpan',
textColor: Colors.white,
onTap: () async {
if (!_formKey.currentState!.validate()) return;
final result = await _authController.changePhone(
oldPassword: _oldPassword.text.trim(),
newPhone: _phoneNumber.text.trim(),
);
if (result) {
_oldPassword.clear();
_phoneNumber.clear();
}
},
),
);
},
),
);
}
}

View File

@ -1,9 +1,11 @@
import 'package:e_porter/_core/component/appbar/appbar_component.dart'; import 'package:e_porter/_core/component/appbar/appbar_component.dart';
import 'package:e_porter/_core/component/button/button_fill.dart'; import 'package:e_porter/_core/component/button/button_fill.dart';
import 'package:e_porter/_core/component/card/custome_shadow_cotainner.dart'; import 'package:e_porter/_core/component/card/custome_shadow_cotainner.dart';
import 'package:e_porter/_core/component/text/custom_text.dart';
import 'package:e_porter/_core/constants/colors.dart'; import 'package:e_porter/_core/constants/colors.dart';
import 'package:e_porter/_core/constants/typography.dart'; import 'package:e_porter/_core/utils/snackbar/snackbar_helper.dart';
import 'package:e_porter/_core/validators/validators.dart'; import 'package:e_porter/_core/validators/validators.dart';
import 'package:e_porter/presentation/controllers/profil_controller.dart';
import 'package:e_porter/presentation/screens/auth/component/Input_password.dart'; import 'package:e_porter/presentation/screens/auth/component/Input_password.dart';
import 'package:e_porter/presentation/screens/profile/component/header_information.dart'; import 'package:e_porter/presentation/screens/profile/component/header_information.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -18,6 +20,7 @@ class ChangePasswordScreen extends StatefulWidget {
} }
class _ChangePasswordScreenState extends State<ChangePasswordScreen> { class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
final _authController = Get.find<ProfilController>();
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
final _oldPassword = TextEditingController(); final _oldPassword = TextEditingController();
final _newPassword = TextEditingController(); final _newPassword = TextEditingController();
@ -26,81 +29,94 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: GrayColors.gray50, backgroundColor: GrayColors.gray50,
appBar: DefaultAppbarComponent( appBar: DefaultAppbarComponent(
title: 'Ganti Kata Sandi', title: 'Ganti Kata Sandi',
textColor: Colors.white, textColor: Colors.white,
backgroundColors: PrimaryColors.primary800, backgroundColors: PrimaryColors.primary800,
onTab: () { onTab: () {
Get.back(); Get.back();
}, },
), ),
body: SafeArea( body: SafeArea(
child: Padding( child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.h), padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 20.h),
child: SingleChildScrollView( child: SingleChildScrollView(
child: Form( child: Form(
key: _formKey, key: _formKey,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
HeaderInformation( HeaderInformation(
title: title:
'Apakah anda yakin ingin mengganti kata sandi? Silahkan masukkan kata sandi lama anda dan kata sandi baru anda', 'Apakah anda yakin ingin mengganti kata sandi? Silahkan masukkan kata sandi lama anda dan kata sandi baru anda',
), ),
SizedBox(height: 32.h), SizedBox(height: 32.h),
textTitle(title: 'Password Lama'), CustomText.textPadding8('Password Lama'),
SizedBox(height: 16.h), SizedBox(height: 16.h),
InputPassword( InputPassword(
controller: _oldPassword, controller: _oldPassword,
hintText: '••••••••••', hintText: '••••••••••',
svgIconPath: 'assets/icons/ic_padlock.svg', svgIconPath: 'assets/icons/ic_padlock.svg',
validator: Validators.validatorPassword, validator: Validators.validatorPassword,
), ),
SizedBox(height: 20.h), SizedBox(height: 20.h),
textTitle(title: 'Password Baru'), CustomText.textPadding8('Password Baru'),
SizedBox(height: 16.h), SizedBox(height: 16.h),
InputPassword( InputPassword(
controller: _newPassword, controller: _newPassword,
hintText: '••••••••••', hintText: '••••••••••',
svgIconPath: 'assets/icons/ic_padlock.svg', svgIconPath: 'assets/icons/ic_padlock.svg',
validator: Validators.validatorPassword, validator: Validators.validatorPassword,
), ),
SizedBox(height: 20.h), SizedBox(height: 20.h),
textTitle(title: 'Konfirmasi Password'), CustomText.textPadding8('Konfirmasi Password'),
SizedBox(height: 16.h), SizedBox(height: 16.h),
InputPassword( InputPassword(
controller: _confirmPassword, controller: _confirmPassword,
hintText: '••••••••••', hintText: '••••••••••',
svgIconPath: 'assets/icons/ic_padlock.svg', svgIconPath: 'assets/icons/ic_padlock.svg',
validator: Validators.validatorPassword, validator: Validators.validatorPassword,
), ),
], ],
),
), ),
), ),
), ),
), ),
), bottomNavigationBar: Obx(
bottomNavigationBar: CustomeShadowCotainner( () {
child: ButtonFill( return CustomeShadowCotainner(
text: 'Simpan', child: _authController.isChangingPassword.value
textColor: Colors.white, ? Padding(
onTap: () { padding: EdgeInsets.symmetric(vertical: 16.h),
if (_formKey.currentState!.validate()) {} child: Center(child: CircularProgressIndicator()),
}, )
), : ButtonFill(
), text: 'Simpan',
); textColor: Colors.white,
} onTap: () async {
if (!_formKey.currentState!.validate()) return;
if (_newPassword.text != _confirmPassword.text) {
SnackbarHelper.showError("Error", "Password baru dan konfirmasi tidak sama.");
return;
}
Widget textTitle({required String title}) { final success = await _authController.changePassword(
return Padding( oldPassword: _oldPassword.text,
padding: EdgeInsets.symmetric(horizontal: 8.w), newPassword: _newPassword.text,
child: TypographyStyles.body( );
title,
color: GrayColors.gray800, if (success) {
fontWeight: FontWeight.w500, _oldPassword.clear();
), _newPassword.clear();
); _confirmPassword.clear();
FocusScope.of(context).unfocus();
}
},
),
);
},
));
} }
} }