You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
6.1 KiB
Dart
162 lines
6.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:car_customer_app/api/client/user_api_client.dart';
|
|
import 'package:car_customer_app/classes/app_state.dart';
|
|
import 'package:car_customer_app/classes/utils.dart';
|
|
import 'package:car_customer_app/config/routes.dart';
|
|
import 'package:car_customer_app/extensions/int_extensions.dart';
|
|
import 'package:car_customer_app/extensions/string_extensions.dart';
|
|
import 'package:car_customer_app/generated/locale_keys.g.dart';
|
|
import 'package:car_customer_app/models/m_response.dart';
|
|
import 'package:car_customer_app/models/user/verify_email.dart';
|
|
import 'package:car_customer_app/models/user/verify_email_otp.dart';
|
|
import 'package:car_customer_app/utils/navigator.dart';
|
|
import 'package:car_customer_app/widgets/app_bar.dart';
|
|
import 'package:car_customer_app/widgets/dialog/dialogs.dart';
|
|
import 'package:car_customer_app/widgets/dialog/message_dialog.dart';
|
|
import 'package:car_customer_app/widgets/dialog/otp_dialog.dart';
|
|
import 'package:easy_localization/src/public_ext.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
class EditAccountPage extends StatefulWidget {
|
|
@override
|
|
State<EditAccountPage> createState() => _EditAccountPageState();
|
|
}
|
|
|
|
class _EditAccountPageState extends State<EditAccountPage> {
|
|
String userID = "";
|
|
String email = '';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: appBar(title: LocaleKeys.editAccount.tr(),),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
padding: EdgeInsets.all(40),
|
|
child: Column(
|
|
children: [
|
|
20.height,
|
|
ListTile(
|
|
leading: SvgPicture.asset("assets/images/ic_lock.svg"),
|
|
title: LocaleKeys.changePassword.tr().toText12(),
|
|
onTap: () {
|
|
navigateWithName(context, AppRoutes.changePassword);
|
|
},
|
|
),
|
|
15.height,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
SvgPicture.asset("assets/images/ic_mobile.svg"),
|
|
LocaleKeys.changeMobile.tr().toText12(),
|
|
LocaleKeys.verify.tr().toText12(),
|
|
RaisedButton(
|
|
onPressed: () {
|
|
navigateWithName(context, AppRoutes.changeMobilePage);
|
|
},
|
|
child: Text(
|
|
LocaleKeys.change.tr(),
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
color: Colors.blue,
|
|
textColor: Colors.white,
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 8))
|
|
],
|
|
),
|
|
20.height,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Icon(
|
|
Icons.email,
|
|
color: Colors.blue,
|
|
),
|
|
LocaleKeys.changeEmail.tr().toText12(),
|
|
InkWell(
|
|
child: ((AppState().getUser.data!.userInfo!.isEmailVerified ?? false) ? LocaleKeys.verified.tr() : LocaleKeys.verify.tr()).toText12(),
|
|
onTap: (AppState().getUser.data!.userInfo!.isEmailVerified ?? false)
|
|
? null
|
|
: () {
|
|
verifyEmail(context);
|
|
},
|
|
),
|
|
RaisedButton(
|
|
onPressed: () {
|
|
navigateWithName(context, AppRoutes.changeEmailPage);
|
|
},
|
|
child: Text(
|
|
LocaleKeys.change.tr(),
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
color: Colors.blue,
|
|
textColor: Colors.white,
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 8))
|
|
],
|
|
)
|
|
|
|
// ListTile(
|
|
// leading: SvgPicture.asset("assets/images/ic_mobile.svg"),
|
|
// title: "Change Mobile".toText12(),
|
|
// onTap: () {
|
|
// navigateWithName(context, AppRoutes.changeMobilePage);
|
|
// },
|
|
// ),
|
|
// ListTile(
|
|
// leading: Icon(Icons.email_outlined, color: Colors.blue,),
|
|
// title: "Change Email".toText12(),
|
|
// onTap: () {
|
|
// navigateWithName(context, AppRoutes.changeEmailPage);
|
|
// },
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> verifyEmail(BuildContext context) async {
|
|
Utils.showLoading(context);
|
|
VerifyEmail otpRequest = await UserApiClent().EmailVerify(email, userID);
|
|
Utils.hideLoading(context);
|
|
if (otpRequest.messageStatus == 1) {
|
|
showMDialog(context, child: OtpDialog(
|
|
onClick: (String code) async {
|
|
pop(context);
|
|
Utils.showLoading(context);
|
|
MResponse otpCompare = await UserApiClent().EmailVerifyOTPVerify(otpRequest.data!.userToken ?? "", code);
|
|
Utils.hideLoading(context);
|
|
if (otpCompare.messageStatus == 1) {
|
|
AppState().getUser.data!.userInfo!.isEmailVerified = true;
|
|
setState(() {});
|
|
Utils.showToast(LocaleKeys.emailVerified.tr());
|
|
//("Email is verified successfully");
|
|
// Navigator.of(context).pushNamedAndRemoveUntil(AppRoutes.dashboard, (Route<dynamic> route) => false);
|
|
// showMDialog(
|
|
// context,
|
|
// child: MessageDialog(
|
|
// title: "Email is Verified",
|
|
// onClick: () {
|
|
// Navigator.of(context).pushNamedAndRemoveUntil(AppRoutes.dashboard, (Route<dynamic> route) => false);
|
|
// },
|
|
// ),
|
|
// );
|
|
} else {
|
|
Utils.showToast(otpCompare.message ?? "");
|
|
}
|
|
},
|
|
));
|
|
} else {
|
|
Utils.showToast(otpRequest.message ?? "");
|
|
}
|
|
}
|
|
}
|