|
|
|
|
@ -5,6 +5,8 @@ import 'package:car_customer_app/api/user_api_client.dart';
|
|
|
|
|
import 'package:car_customer_app/classes/utils.dart';
|
|
|
|
|
import 'package:car_customer_app/config/constants.dart';
|
|
|
|
|
import 'package:car_customer_app/config/routes.dart';
|
|
|
|
|
import 'package:car_customer_app/models/user/login_password.dart';
|
|
|
|
|
import 'package:car_customer_app/models/user/register_user.dart';
|
|
|
|
|
import 'package:car_customer_app/models/user/user.dart';
|
|
|
|
|
import 'package:car_customer_app/utils/navigator.dart';
|
|
|
|
|
import 'package:car_customer_app/utils/utils.dart';
|
|
|
|
|
@ -20,7 +22,64 @@ import 'package:car_customer_app/widgets/txt_field.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
|
|
|
|
|
|
class LoginVerificationPage extends StatelessWidget {
|
|
|
|
|
class LoginVerificationPage extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
State<LoginVerificationPage> createState() => _LoginVerificationPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LoginVerificationPageState extends State<LoginVerificationPage> {
|
|
|
|
|
String userToken = "";
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
// TODO: implement initState
|
|
|
|
|
super.initState();
|
|
|
|
|
performApiCall();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
performApiCall() async {
|
|
|
|
|
String userName = await SharedPrefManager.getPhoneOrEmail();
|
|
|
|
|
String password = await SharedPrefManager.getUserPassword();
|
|
|
|
|
if (userName.isNotEmpty && userName.isNotEmpty) {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response = await UserApiClent().login_V1(userName, password);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
LoginPassword user = LoginPassword.fromJson(jsonDecode(response.body));
|
|
|
|
|
if (user.messageStatus == 1) {
|
|
|
|
|
userToken = user.data!.userToken ?? "";
|
|
|
|
|
// navigateWithName(context, AppRoutes.loginMethodSelection, arguments: user.data!.userToken);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(user.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtp(BuildContext context, String userToken) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response = await UserApiClent().login_V2_OTP(userToken, "1");
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
LoginPassword user = LoginPassword.fromJson(jsonDecode(response.body));
|
|
|
|
|
if (user.messageStatus == 1) {
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response2 = await UserApiClent().login_V2_OTPVerify(user.data!.userToken ?? "", code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
RegisterUser verifiedUser = RegisterUser.fromJson(jsonDecode(response2.body));
|
|
|
|
|
if (verifiedUser.messageStatus == 1) {
|
|
|
|
|
User user = User.fromJson(jsonDecode(response2.body));
|
|
|
|
|
navigateReplaceWithName(context, AppRoutes.dashboard);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(verifiedUser.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(user.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
@ -32,14 +91,13 @@ class LoginVerificationPage extends StatelessWidget {
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
"Verify Account".toText24(),
|
|
|
|
|
|
|
|
|
|
mFlex(2),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowImageButton(
|
|
|
|
|
onClick: () {
|
|
|
|
|
performBasicOtp(context);
|
|
|
|
|
performBasicOtp(context, userToken);
|
|
|
|
|
},
|
|
|
|
|
title: 'Finger Print',
|
|
|
|
|
icon: icons + "ic_fingerprint.png",
|
|
|
|
|
@ -49,7 +107,7 @@ class LoginVerificationPage extends StatelessWidget {
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowImageButton(
|
|
|
|
|
onClick: () {
|
|
|
|
|
performBasicOtp(context);
|
|
|
|
|
performBasicOtp(context, userToken);
|
|
|
|
|
},
|
|
|
|
|
title: 'Face Recognition',
|
|
|
|
|
icon: icons + "ic_face_id.png",
|
|
|
|
|
@ -57,13 +115,13 @@ class LoginVerificationPage extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
40.height,
|
|
|
|
|
40.height,
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowImageButton(
|
|
|
|
|
onClick: () {
|
|
|
|
|
performBasicOtp(context);
|
|
|
|
|
performBasicOtp(context, userToken);
|
|
|
|
|
},
|
|
|
|
|
title: 'With SMS',
|
|
|
|
|
icon: icons + "ic_sms.png",
|
|
|
|
|
@ -73,7 +131,7 @@ class LoginVerificationPage extends StatelessWidget {
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowImageButton(
|
|
|
|
|
onClick: () {
|
|
|
|
|
performBasicOtp(context);
|
|
|
|
|
performBasicOtp(context, userToken);
|
|
|
|
|
},
|
|
|
|
|
title: 'With Whatsapp',
|
|
|
|
|
icon: icons + "ic_whatsapp.png",
|
|
|
|
|
@ -88,32 +146,32 @@ class LoginVerificationPage extends StatelessWidget {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performBasicOtp(BuildContext context) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
String userToken=await SharedPrefManager.getUserToken();
|
|
|
|
|
Response response = await UserApiClent().login_V2_OTP(userToken, "1");
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
String userToken = jsonDecode(response.body)["token"];
|
|
|
|
|
showMDialog(context, child: OtpDialog(
|
|
|
|
|
onClick: (String code) async {
|
|
|
|
|
pop(context);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
Response response2 = await UserApiClent().login_V2_OTPVerify(userToken, code);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (response2.statusCode == 200) {
|
|
|
|
|
User user = User.fromMap(jsonDecode(response2.body));
|
|
|
|
|
SharedPrefManager.setUserToken(user.accessToken ?? "");
|
|
|
|
|
SharedPrefManager.setUserId(user.userInfo!.userId ?? "");
|
|
|
|
|
navigateWithName(context, AppRoutes.dashboard);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("Something went wrong");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
String res = jsonDecode(response.body)["errors"][0] ?? "";
|
|
|
|
|
Utils.showToast(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Future<void> performBasicOtp(BuildContext context) async {
|
|
|
|
|
// Utils.showLoading(context);
|
|
|
|
|
// String userToken=await SharedPrefManager.getUserToken();
|
|
|
|
|
// Response response = await UserApiClent().login_V2_OTP(userToken, "1");
|
|
|
|
|
// Utils.hideLoading(context);
|
|
|
|
|
// if (response.statusCode == 200) {
|
|
|
|
|
// String userToken = jsonDecode(response.body)["token"];
|
|
|
|
|
// showMDialog(context, child: OtpDialog(
|
|
|
|
|
// onClick: (String code) async {
|
|
|
|
|
// pop(context);
|
|
|
|
|
// Utils.showLoading(context);
|
|
|
|
|
// Response response2 = await UserApiClent().login_V2_OTPVerify(userToken, code);
|
|
|
|
|
// Utils.hideLoading(context);
|
|
|
|
|
// if (response2.statusCode == 200) {
|
|
|
|
|
// User user = User.fromJson(jsonDecode(response2.body));
|
|
|
|
|
// SharedPrefManager.setUserToken(user.data!.accessToken ?? "");
|
|
|
|
|
// SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? "");
|
|
|
|
|
// navigateWithName(context, AppRoutes.dashboard);
|
|
|
|
|
// } else {
|
|
|
|
|
// Utils.showToast("Something went wrong");
|
|
|
|
|
// }
|
|
|
|
|
// },
|
|
|
|
|
// ));
|
|
|
|
|
// } else {
|
|
|
|
|
// String res = jsonDecode(response.body)["errors"][0] ?? "";
|
|
|
|
|
// Utils.showToast(res);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|