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.
136 lines
4.7 KiB
Dart
136 lines
4.7 KiB
Dart
|
|
import 'dart:convert';
|
|
|
|
import 'package:car_customer_app/api/shared_prefrence.dart';
|
|
import 'package:car_customer_app/api/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/string_extensions.dart';
|
|
import 'package:car_customer_app/models/user/change_password.dart';
|
|
import 'package:car_customer_app/models/user/email_verify.dart';
|
|
import 'package:car_customer_app/models/user/email_verify_otp.dart';
|
|
import 'package:car_customer_app/utils/navigator.dart';
|
|
import 'package:car_customer_app/utils/utils.dart';
|
|
import 'package:car_customer_app/widgets/app_bar.dart';
|
|
import 'package:car_customer_app/extensions/int_extensions.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:flutter/material.dart';
|
|
|
|
|
|
|
|
class EditAccountPage extends StatefulWidget {
|
|
@override
|
|
State<EditAccountPage> createState() => _EditAccountPageState();
|
|
}
|
|
|
|
class _EditAccountPageState extends State<EditAccountPage> {
|
|
String userID = "";
|
|
String email = '';
|
|
//bool isVerified = true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: appBar(title: "Edit Account"),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
padding: EdgeInsets.all(20),
|
|
child: Column(
|
|
children: [
|
|
ListTile(
|
|
leading: Icon(Icons.lock, color: Colors.blue,),
|
|
title: "Change Password".toText12(),
|
|
onTap: () {
|
|
navigateWithName(context, AppRoutes.changePasswordPage);
|
|
},
|
|
),
|
|
15.height,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Icon(Icons.phone_android_sharp, color: Colors.blue,),
|
|
"Change Mobile".toText12(),
|
|
"Verify".toText12(),
|
|
RaisedButton(
|
|
onPressed: (){
|
|
navigateWithName(context, AppRoutes.changeMobilePage);
|
|
},
|
|
child: Text("Change",
|
|
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,),
|
|
"Change Email".toText12(),
|
|
InkWell(
|
|
child:((AppState().getUser.data!.userInfo!.isEmailVerified??false)?"Verified" :"Verify").toText12(),
|
|
onTap:
|
|
(AppState().getUser.data!.userInfo!.isEmailVerified??false) ?
|
|
null
|
|
:(){
|
|
verifyEmail(context);
|
|
},
|
|
),
|
|
RaisedButton(
|
|
onPressed: (){
|
|
navigateWithName(context, AppRoutes.changeEmailPage);
|
|
},
|
|
child: Text("Change",
|
|
style: TextStyle(fontSize: 14,
|
|
fontWeight: FontWeight.w600,),),color:Colors.blue,
|
|
textColor: Colors.white,
|
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 8)
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
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("Email is verified successfully");
|
|
pop(context);
|
|
|
|
} else {
|
|
Utils.showToast(otpCompare.message ?? "");
|
|
}
|
|
},
|
|
));
|
|
} else {
|
|
Utils.showToast(otpRequest.message ?? "");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|