From 560e3663b65b6416fda0b034364e60f5919282f9 Mon Sep 17 00:00:00 2001 From: devmirza121 Date: Sun, 6 Feb 2022 12:32:45 +0300 Subject: [PATCH] API's Modifications --- lib/api/api_client.dart | 2 +- lib/api/shared_prefrence.dart | 22 ++- lib/api/user_api_client.dart | 19 +-- lib/models/user/login_password.dart | 53 ++++++++ lib/models/user/user.dart | 66 +++++++-- lib/pages/dashboard/dashboard_page.dart | 24 +++- lib/pages/user/complete_profile_page.dart | 8 +- .../user/login_method_selection_page.dart | 24 ++-- lib/pages/user/login_verification_page.dart | 128 +++++++++++++----- lib/pages/user/login_verify_account_page.dart | 4 +- lib/pages/user/login_with_password_page.dart | 19 ++- lib/pages/user/register_page.dart | 2 + lib/utils/navigator.dart | 5 + lib/widgets/txt_field.dart | 10 +- 14 files changed, 294 insertions(+), 92 deletions(-) create mode 100644 lib/models/user/login_password.dart diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index aa7bbc2..4bbed19 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -107,7 +107,7 @@ class ApiClient { var queryString = new Uri(queryParameters: queryParameters).query; url = url + '?' + queryString; } - var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 15)); + var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 100)); if (!kReleaseMode) { print("Url:$url"); diff --git a/lib/api/shared_prefrence.dart b/lib/api/shared_prefrence.dart index cad63d1..77b3953 100644 --- a/lib/api/shared_prefrence.dart +++ b/lib/api/shared_prefrence.dart @@ -5,8 +5,8 @@ import 'package:shared_preferences/shared_preferences.dart'; class SharedPrefManager { static String USER_ID = "user.id"; static String USER_TOKEN = "user.token"; - - + static String USER_NAME = "user.name"; + static String PASSWORD = "user.password"; static Future _prefs = SharedPreferences.getInstance(); @@ -30,5 +30,23 @@ class SharedPrefManager { return prefs.getString(USER_TOKEN) ?? ""; } + static setPhoneOrEmail(String cookie) async { + final prefs = await SharedPreferences.getInstance(); + prefs.setString(USER_NAME, cookie) ?? "NA"; + } + + static Future getPhoneOrEmail() async { + SharedPreferences prefs = await _prefs; + return prefs.getString(USER_NAME) ?? ""; + } + + static setUserPassword(String cookie) async { + final prefs = await SharedPreferences.getInstance(); + prefs.setString(PASSWORD, cookie) ?? "NA"; + } + static Future getUserPassword() async { + SharedPreferences prefs = await _prefs; + return prefs.getString(PASSWORD) ?? ""; + } } diff --git a/lib/api/user_api_client.dart b/lib/api/user_api_client.dart index a6d4d68..8164fca 100644 --- a/lib/api/user_api_client.dart +++ b/lib/api/user_api_client.dart @@ -16,7 +16,7 @@ class UserApiClent { factory UserApiClent() => _instance; - Future basicOtp(String phoneNo,{int otpType=1}) async { + Future basicOtp(String phoneNo, {int otpType = 1}) async { var postParams = {"countryID": 1, "userMobileNo": phoneNo, "otpType": otpType, "userRole": 4}; return await ApiClient().postJsonForObject((json) => BasicOtp.fromJson(json), ApiConsts.BasicOTP, postParams); } @@ -30,16 +30,8 @@ class UserApiClent { return await ApiClient().postJsonForObject((json) => RegisterUser.fromJson(json), ApiConsts.BasicVerify, postParams); } - Future basicComplete(String userId, String firstName, String lastName,String email,String password) async { - var postParams = { - "userID": userId, - "firstName": firstName, - "lastName": lastName, - "email": email, - "companyName": "string", - "isEmailVerified": true, - "password": password - }; + Future basicComplete(String userId, String firstName, String lastName, String email, String password) async { + var postParams = {"userID": userId, "firstName": firstName, "lastName": lastName, "email": email, "companyName": "string", "isEmailVerified": true, "password": password}; return await ApiClient().postJsonForObject((json) => RegisterUser.fromJson(json), ApiConsts.BasicComplete, postParams); } @@ -61,10 +53,7 @@ class UserApiClent { } Future login_V2_OTPVerify(String userToken, String otp) async { - var postParams = { - "userToken": userToken, - "userOTP": otp - }; + var postParams = {"userToken": userToken, "userOTP": otp}; return await ApiClient().postJsonForResponse(ApiConsts.Login_V2_OTPVerify, postParams); } } diff --git a/lib/models/user/login_password.dart b/lib/models/user/login_password.dart new file mode 100644 index 0000000..616e860 --- /dev/null +++ b/lib/models/user/login_password.dart @@ -0,0 +1,53 @@ +// To parse this JSON data, do +// +// final loginPassword = loginPasswordFromJson(jsonString); + +import 'dart:convert'; + +LoginPassword loginPasswordFromJson(String str) => LoginPassword.fromJson(json.decode(str)); + +String loginPasswordToJson(LoginPassword data) => json.encode(data.toJson()); + +class LoginPassword { + LoginPassword({ + this.totalItemsCount, + this.data, + this.messageStatus, + this.message, + }); + + dynamic totalItemsCount; + Data? data; + int? messageStatus; + String? message; + + factory LoginPassword.fromJson(Map json) => LoginPassword( + totalItemsCount: json["totalItemsCount"], + data: json["data"] == null ? null : Data.fromJson(json["data"]), + messageStatus: json["messageStatus"] == null ? null : json["messageStatus"], + message: json["message"] == null ? null : json["message"], + ); + + Map toJson() => { + "totalItemsCount": totalItemsCount, + "data": data == null ? null : data!.toJson(), + "messageStatus": messageStatus == null ? null : messageStatus, + "message": message == null ? null : message, + }; +} + +class Data { + Data({ + this.userToken, + }); + + String? userToken; + + factory Data.fromJson(Map json) => Data( + userToken: json["userToken"] == null ? null : json["userToken"], + ); + + Map toJson() => { + "userToken": userToken == null ? null : userToken, + }; +} diff --git a/lib/models/user/user.dart b/lib/models/user/user.dart index aea036b..46ff5b0 100644 --- a/lib/models/user/user.dart +++ b/lib/models/user/user.dart @@ -1,15 +1,43 @@ // To parse this JSON data, do // -// final user = userFromMap(jsonString); +// final user = userFromJson(jsonString); import 'dart:convert'; -User userFromMap(String str) => User.fromMap(json.decode(str)); +User userFromJson(String str) => User.fromJson(json.decode(str)); -String userToMap(User data) => json.encode(data.toMap()); +String userToJson(User data) => json.encode(data.toJson()); class User { User({ + this.totalItemsCount, + this.data, + this.messageStatus, + this.message, + }); + + dynamic totalItemsCount; + Data? data; + int? messageStatus; + String? message; + + factory User.fromJson(Map json) => User( + totalItemsCount: json["totalItemsCount"], + data: json["data"] == null ? null : Data.fromJson(json["data"]), + messageStatus: json["messageStatus"] == null ? null : json["messageStatus"], + message: json["message"] == null ? null : json["message"], + ); + + Map toJson() => { + "totalItemsCount": totalItemsCount, + "data": data == null ? null : data!.toJson(), + "messageStatus": messageStatus == null ? null : messageStatus, + "message": message == null ? null : message, + }; +} + +class Data { + Data({ this.accessToken, this.refreshToken, this.expiryDate, @@ -21,18 +49,18 @@ class User { DateTime? expiryDate; UserInfo? userInfo; - factory User.fromMap(Map json) => User( + factory Data.fromJson(Map json) => Data( accessToken: json["accessToken"] == null ? null : json["accessToken"], refreshToken: json["refreshToken"] == null ? null : json["refreshToken"], expiryDate: json["expiryDate"] == null ? null : DateTime.parse(json["expiryDate"]), - userInfo: json["userInfo"] == null ? null : UserInfo.fromMap(json["userInfo"]), + userInfo: json["userInfo"] == null ? null : UserInfo.fromJson(json["userInfo"]), ); - Map toMap() => { + Map toJson() => { "accessToken": accessToken == null ? null : accessToken, "refreshToken": refreshToken == null ? null : refreshToken, "expiryDate": expiryDate == null ? null : expiryDate!.toIso8601String(), - "userInfo": userInfo == null ? null : userInfo!.toMap(), + "userInfo": userInfo == null ? null : userInfo!.toJson(), }; } @@ -52,9 +80,11 @@ class UserInfo { this.isVerified, this.userRoles, this.isCustomer, - this.isProvider, + this.isProviderDealership, + this.isDealershipUser, this.providerId, this.customerId, + this.dealershipId, }); int? id; @@ -63,7 +93,7 @@ class UserInfo { String? lastName; String? mobileNo; String? email; - dynamic? userImageUrl; + dynamic userImageUrl; int? roleId; String? roleName; bool? isEmailVerified; @@ -71,11 +101,13 @@ class UserInfo { bool? isVerified; List? userRoles; bool? isCustomer; - bool? isProvider; - dynamic? providerId; + bool? isProviderDealership; + bool? isDealershipUser; + dynamic providerId; int? customerId; + dynamic dealershipId; - factory UserInfo.fromMap(Map json) => UserInfo( + factory UserInfo.fromJson(Map json) => UserInfo( id: json["id"] == null ? null : json["id"], userId: json["userID"] == null ? null : json["userID"], firstName: json["firstName"] == null ? null : json["firstName"], @@ -90,12 +122,14 @@ class UserInfo { isVerified: json["isVerified"] == null ? null : json["isVerified"], userRoles: json["userRoles"] == null ? null : List.from(json["userRoles"].map((x) => x)), isCustomer: json["isCustomer"] == null ? null : json["isCustomer"], - isProvider: json["isProvider"] == null ? null : json["isProvider"], + isProviderDealership: json["isProviderDealership"] == null ? null : json["isProviderDealership"], + isDealershipUser: json["isDealershipUser"] == null ? null : json["isDealershipUser"], providerId: json["providerID"], customerId: json["customerID"] == null ? null : json["customerID"], + dealershipId: json["dealershipID"], ); - Map toMap() => { + Map toJson() => { "id": id == null ? null : id, "userID": userId == null ? null : userId, "firstName": firstName == null ? null : firstName, @@ -110,8 +144,10 @@ class UserInfo { "isVerified": isVerified == null ? null : isVerified, "userRoles": userRoles == null ? null : List.from(userRoles!.map((x) => x)), "isCustomer": isCustomer == null ? null : isCustomer, - "isProvider": isProvider == null ? null : isProvider, + "isProviderDealership": isProviderDealership == null ? null : isProviderDealership, + "isDealershipUser": isDealershipUser == null ? null : isDealershipUser, "providerID": providerId, "customerID": customerId == null ? null : customerId, + "dealershipID": dealershipId, }; } diff --git a/lib/pages/dashboard/dashboard_page.dart b/lib/pages/dashboard/dashboard_page.dart index 27621ae..91caad2 100644 --- a/lib/pages/dashboard/dashboard_page.dart +++ b/lib/pages/dashboard/dashboard_page.dart @@ -1,3 +1,4 @@ +import 'package:car_customer_app/api/shared_prefrence.dart'; import 'package:car_customer_app/theme/colors.dart'; import 'package:car_customer_app/utils/navigator.dart'; import 'package:car_customer_app/widgets/app_bar.dart'; @@ -7,7 +8,26 @@ import 'package:car_customer_app/extensions/string_extensions.dart'; import 'package:car_customer_app/extensions/widget_extensions.dart'; import 'package:flutter/material.dart'; -class DashboardPage extends StatelessWidget { +class DashboardPage extends StatefulWidget { + @override + State createState() => _DashboardPageState(); +} + +class _DashboardPageState extends State { + String userName = ""; + + @override + void initState() { + // TODO: implement initState + super.initState(); + fetchUsername(); + } + + fetchUsername() async { + userName = await SharedPrefManager.getPhoneOrEmail(); + setState(() {}); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -49,7 +69,7 @@ class DashboardPage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - "User Name".toText24(), + userName.toText24(), "User role or title".toText12(), ], ), diff --git a/lib/pages/user/complete_profile_page.dart b/lib/pages/user/complete_profile_page.dart index 41dfc6f..187d011 100644 --- a/lib/pages/user/complete_profile_page.dart +++ b/lib/pages/user/complete_profile_page.dart @@ -1,5 +1,6 @@ import 'package:car_customer_app/api/user_api_client.dart'; import 'package:car_customer_app/classes/utils.dart'; +import 'package:car_customer_app/config/routes.dart'; import 'package:car_customer_app/models/user/basic_otp.dart'; import 'package:car_customer_app/models/user/register_user.dart'; import 'package:car_customer_app/utils/navigator.dart'; @@ -71,6 +72,8 @@ class _CompleteProfilePageState extends State { 12.height, TxtField( hint: "Create Password", + isPasswordEnabled: true, + maxLines: 1, onChanged: (v) { password = v; }, @@ -78,6 +81,8 @@ class _CompleteProfilePageState extends State { 12.height, TxtField( hint: "Confirm Password", + isPasswordEnabled: true, + maxLines: 1, onChanged: (v) { confirmPassword = v; }, @@ -112,7 +117,8 @@ class _CompleteProfilePageState extends State { Utils.hideLoading(context); if (user.messageStatus == 1) { Utils.showToast(user.message ?? ""); - + pop(context); + navigateReplaceWithName(context, AppRoutes.dashboard,arguments: user); } else { Utils.showToast(user.message ?? ""); } diff --git a/lib/pages/user/login_method_selection_page.dart b/lib/pages/user/login_method_selection_page.dart index 73c87ef..32b2fd1 100644 --- a/lib/pages/user/login_method_selection_page.dart +++ b/lib/pages/user/login_method_selection_page.dart @@ -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'; @@ -96,27 +98,27 @@ class LoginMethodSelectionPage extends StatelessWidget { Utils.showLoading(context); Response response = await UserApiClent().login_V2_OTP(userToken, "1"); Utils.hideLoading(context); - if (response.statusCode == 200) { - String userToken = jsonDecode(response.body)["token"]; + 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(userToken, code); + Response response2 = await UserApiClent().login_V2_OTPVerify(user.data!.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); + RegisterUser verifiedUser = RegisterUser.fromJson(jsonDecode(response2.body)); + if (verifiedUser.messageStatus == 1) { + User user = User.fromJson(jsonDecode(response2.body)); + SharedPrefManager.setUserToken(user.data!.accessToken ?? ""); + SharedPrefManager.setUserId(user.data!.userInfo!.userId ?? ""); + navigateReplaceWithName(context, AppRoutes.dashboard); } else { - Utils.showToast("Something went wrong"); + Utils.showToast(verifiedUser.message??""); } }, )); } else { - String res = jsonDecode(response.body)["errors"][0] ?? ""; - Utils.showToast(res); + Utils.showToast(user.message ?? ""); } } } diff --git a/lib/pages/user/login_verification_page.dart b/lib/pages/user/login_verification_page.dart index 0f81c1b..c602fab 100644 --- a/lib/pages/user/login_verification_page.dart +++ b/lib/pages/user/login_verification_page.dart @@ -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 createState() => _LoginVerificationPageState(); +} + +class _LoginVerificationPageState extends State { + 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 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 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 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); +// } +// } } diff --git a/lib/pages/user/login_verify_account_page.dart b/lib/pages/user/login_verify_account_page.dart index 2241044..a2989f2 100644 --- a/lib/pages/user/login_verify_account_page.dart +++ b/lib/pages/user/login_verify_account_page.dart @@ -34,7 +34,8 @@ class LoginVerifyAccountPage extends StatelessWidget { "Verify Account".toText24(), mFlex(1), TxtField( - hint: "Enter Phone number to verify", + hint: "966501234567", + value: phoneNum, onChanged: (v) { phoneNum = v; }, @@ -126,6 +127,7 @@ class LoginVerifyAccountPage extends StatelessWidget { child: MessageDialog( title: "Phone Number Verified", onClick: () { + pop(context); navigateWithName(context, AppRoutes.completeProfile,arguments: user); }, ), diff --git a/lib/pages/user/login_with_password_page.dart b/lib/pages/user/login_with_password_page.dart index 580598c..4dff569 100644 --- a/lib/pages/user/login_with_password_page.dart +++ b/lib/pages/user/login_with_password_page.dart @@ -1,10 +1,12 @@ 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/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/basic_otp.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/utils/navigator.dart'; import 'package:car_customer_app/utils/utils.dart'; @@ -38,7 +40,8 @@ class LoginWithPassword extends StatelessWidget { "Login".toText24(), mFlex(1), TxtField( - hint: "Enter Phone number to verify", + hint: "966501234567", + value: phoneNum, onChanged: (v) { phoneNum = v; }, @@ -46,6 +49,9 @@ class LoginWithPassword extends StatelessWidget { 12.height, TxtField( hint: "Password", + value: password, + isPasswordEnabled: true, + maxLines: 1, onChanged: (v) { password = v; }, @@ -69,12 +75,13 @@ class LoginWithPassword extends StatelessWidget { Utils.showLoading(context); Response response = await UserApiClent().login_V1(phoneNum, password); Utils.hideLoading(context); - if (response.statusCode == 200) { - String userToken = jsonDecode(response.body)["userToken"]; - navigateWithName(context, AppRoutes.loginMethodSelection, arguments: userToken); + LoginPassword user = LoginPassword.fromJson(jsonDecode(response.body)); + if (user.messageStatus == 1) { + SharedPrefManager.setPhoneOrEmail(phoneNum); + SharedPrefManager.setUserPassword(password); + navigateReplaceWithName(context, AppRoutes.loginMethodSelection, arguments: user.data!.userToken); } else { - String res = jsonDecode(response.body)["errors"][0] ?? ""; - Utils.showToast(res); + Utils.showToast(user.message ?? ""); } } } diff --git a/lib/pages/user/register_page.dart b/lib/pages/user/register_page.dart index a7346c7..1d9c359 100644 --- a/lib/pages/user/register_page.dart +++ b/lib/pages/user/register_page.dart @@ -1,6 +1,7 @@ import 'package:car_customer_app/api/api_client.dart'; import 'package:car_customer_app/api/user_api_client.dart'; import 'package:car_customer_app/classes/utils.dart'; +import 'package:car_customer_app/config/routes.dart'; import 'package:car_customer_app/models/user/basic_otp.dart'; import 'package:car_customer_app/models/user/register_user.dart'; import 'package:car_customer_app/utils/navigator.dart'; @@ -63,6 +64,7 @@ class RegisterPage extends StatelessWidget { Utils.hideLoading(context); if (user.messageStatus == 1) { Utils.showToast(user.message ?? ""); + navigateReplaceWithName(context, AppRoutes.completeProfile,arguments: user); } else { Utils.showToast(user.message ?? ""); } diff --git a/lib/utils/navigator.dart b/lib/utils/navigator.dart index f9855a9..ef3900c 100644 --- a/lib/utils/navigator.dart +++ b/lib/utils/navigator.dart @@ -4,6 +4,11 @@ navigateWithName(BuildContext context, String routeName, {Object? arguments}) { Navigator.pushNamed(context, routeName, arguments: arguments); } + +navigateReplaceWithName(BuildContext context, String routeName, {Object? arguments}) { + Navigator.pushReplacementNamed(context, routeName, arguments: arguments); +} + pop(BuildContext context) { Navigator.of(context).pop(); } diff --git a/lib/widgets/txt_field.dart b/lib/widgets/txt_field.dart index a5c8679..d9b1abf 100644 --- a/lib/widgets/txt_field.dart +++ b/lib/widgets/txt_field.dart @@ -7,7 +7,7 @@ import 'package:sizer/sizer.dart'; class TxtField extends StatelessWidget { TextEditingController controller = new TextEditingController(); - String? title; + String? value; String? hint; String? lable; IconData? prefixData; @@ -21,10 +21,12 @@ class TxtField extends StatelessWidget { int? maxLines; bool isSidePaddingZero; bool isNeedBorder; + bool? isPasswordEnabled; Function(String)? onChanged; + TxtField({ - this.title, + this.value, this.lable, this.hint, this.prefixData, @@ -39,11 +41,12 @@ class TxtField extends StatelessWidget { this.isSidePaddingZero=false, this.isNeedBorder=true, this.onChanged, + this.isPasswordEnabled, }); @override Widget build(BuildContext context) { - controller.text = title ?? ""; + controller.text = value ?? ""; return InkWell( onTap: isNeedClickAll == false ? null @@ -63,6 +66,7 @@ class TxtField extends StatelessWidget { enabled: isNeedClickAll == true ? false : true, maxLines: maxLines, onTap: () {}, + obscureText: isPasswordEnabled??false, onChanged: onChanged, decoration: InputDecoration( labelText: lable,