fix sms error and some design issue

auth_refactor
Elham Rababah 5 years ago
parent e0be4ec1be
commit 0d8684481d

@ -23,6 +23,7 @@ import 'package:doctor_app_flutter/models/doctor/clinic_model.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart'; import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:doctor_app_flutter/root_page.dart';
import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/helpers.dart';
@ -77,6 +78,7 @@ class AuthenticationViewModel extends BaseViewModel {
getDoctorProfile(); getDoctorProfile();
} }
/// select Device IMEI
Future selectDeviceImei(imei) async { Future selectDeviceImei(imei) async {
setState(ViewState.Busy); setState(ViewState.Busy);
await _authService.selectDeviceImei(imei); await _authService.selectDeviceImei(imei);
@ -87,6 +89,7 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
/// Insert Device IMEI
Future insertDeviceImei() async { Future insertDeviceImei() async {
var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); var loggedIn = await sharedPref.getObj(LOGGED_IN_USER);
var user = await sharedPref.getObj(LAST_LOGIN_USER); var user = await sharedPref.getObj(LAST_LOGIN_USER);
@ -125,6 +128,8 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
/// first step login
Future login(UserModel userInfo) async { Future login(UserModel userInfo) async {
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
await _authService.login(userInfo); await _authService.login(userInfo);
@ -141,6 +146,7 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// send activation code for for msg methods
Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async { Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async {
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel activationCodeModel =
@ -162,6 +168,7 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
/// send activation code for silent login
Future sendActivationCodeForDoctorApp({AuthMethodTypes authMethodType, String password }) async { Future sendActivationCodeForDoctorApp({AuthMethodTypes authMethodType, String password }) async {
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
int projectID = await sharedPref.getInt(PROJECT_ID); int projectID = await sharedPref.getInt(PROJECT_ID);
@ -180,6 +187,8 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
/// check activation
Future checkActivationCodeForDoctorApp({String activationCode}) async { Future checkActivationCodeForDoctorApp({String activationCode}) async {
setState(ViewState.BusyLocal); setState(ViewState.BusyLocal);
CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = CheckActivationCodeRequestModel checkActivationCodeForDoctorApp =
@ -204,7 +213,7 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// get list of Hospitals
Future getHospitalsList(memberID) async { Future getHospitalsList(memberID) async {
GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel();
getHospitalsRequestModel.memberID = memberID; getHospitalsRequestModel.memberID = memberID;
@ -216,6 +225,8 @@ class AuthenticationViewModel extends BaseViewModel {
setState(ViewState.Idle); setState(ViewState.Idle);
} }
/// get type name based on id.
getType(type, context) { getType(type, context) {
switch (type) { switch (type) {
case 1: case 1:
@ -242,7 +253,8 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { /// add some logic in case of send activation code is success
setDataAfterSendActivationSuccess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) {
print("VerificationCode : " + print("VerificationCode : " +
sendActivationCodeForDoctorAppResponseModel.verificationCode); sendActivationCodeForDoctorAppResponseModel.verificationCode);
sharedPref.setString(VIDA_AUTH_TOKEN_ID, sharedPref.setString(VIDA_AUTH_TOKEN_ID,
@ -257,6 +269,7 @@ class AuthenticationViewModel extends BaseViewModel {
sharedPref.setObj(key, value); sharedPref.setObj(key, value);
} }
/// ask user to add his biometric
showIOSAuthMessages() async { showIOSAuthMessages() async {
const iosStrings = const IOSAuthMessages( const iosStrings = const IOSAuthMessages(
cancelButton: 'cancel', cancelButton: 'cancel',
@ -275,10 +288,12 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// add profile to base view model super class
localSetDoctorProfile(DoctorProfileModel profile) { localSetDoctorProfile(DoctorProfileModel profile) {
super.setDoctorProfile(profile); super.setDoctorProfile(profile);
} }
/// get doctor profile based on clinic model
Future getDoctorProfileBasedOnClinic(ClinicModel clinicInfo) async { Future getDoctorProfileBasedOnClinic(ClinicModel clinicInfo) async {
ProfileReqModel docInfo = new ProfileReqModel( ProfileReqModel docInfo = new ProfileReqModel(
doctorID: clinicInfo.doctorID, doctorID: clinicInfo.doctorID,
@ -297,6 +312,7 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// add some logic in case of check activation code is success
onCheckActivationCodeSuccess() async { onCheckActivationCodeSuccess() async {
sharedPref.setString( sharedPref.setString(
TOKEN, TOKEN,
@ -317,6 +333,7 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// check specific biometric if it available or not
Future <bool> checkIfBiometricAvailable(BiometricType biometricType) async { Future <bool> checkIfBiometricAvailable(BiometricType biometricType) async {
bool isAvailable = false; bool isAvailable = false;
await _getAvailableBiometrics(); await _getAvailableBiometrics();
@ -328,6 +345,7 @@ class AuthenticationViewModel extends BaseViewModel {
return isAvailable; return isAvailable;
} }
/// get all available biometric on the device for local Auth service
Future<void> _getAvailableBiometrics() async { Future<void> _getAvailableBiometrics() async {
try { try {
_availableBiometrics = await auth.getAvailableBiometrics(); _availableBiometrics = await auth.getAvailableBiometrics();
@ -336,7 +354,7 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// call firebase service to check if the user already login in before or not
getDeviceInfoFromFirebase() async { getDeviceInfoFromFirebase() async {
_firebaseMessaging.setAutoInitEnabled(true); _firebaseMessaging.setAutoInitEnabled(true);
if (Platform.isIOS) { if (Platform.isIOS) {
@ -367,7 +385,7 @@ class AuthenticationViewModel extends BaseViewModel {
}); });
} }
/// determine the status of the app
APP_STATUS get status { APP_STATUS get status {
if (state == ViewState.Busy) { if (state == ViewState.Busy) {
return APP_STATUS.LOADING; return APP_STATUS.LOADING;
@ -382,7 +400,7 @@ class AuthenticationViewModel extends BaseViewModel {
} }
} }
/// logout function
logout() async { logout() async {
DEVICE_TOKEN = ""; DEVICE_TOKEN = "";
String lang = await sharedPref.getString(APP_Language); String lang = await sharedPref.getString(APP_Language);
@ -392,7 +410,7 @@ class AuthenticationViewModel extends BaseViewModel {
Navigator.pushAndRemoveUntil( Navigator.pushAndRemoveUntil(
AppGlobal.CONTEX, AppGlobal.CONTEX,
FadePage( FadePage(
page: LoginScreen(), page: RootPage(),
), ),
(r) => false); (r) => false);
} }

@ -1,5 +1,6 @@
import 'dart:io' show Platform; import 'dart:io' show Platform;
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart';
@ -20,10 +21,12 @@ import 'package:provider/provider.dart';
import '../../config/size_config.dart'; import '../../config/size_config.dart';
import '../../landing_page.dart'; import '../../landing_page.dart';
import '../../root_page.dart';
import '../../routes.dart'; import '../../routes.dart';
import '../../util/dr_app_shared_pref.dart'; import '../../util/dr_app_shared_pref.dart';
import '../../util/helpers.dart'; import '../../util/helpers.dart';
import '../../widgets/auth/verification_methods_list.dart'; import '../../widgets/auth/verification_methods_list.dart';
import 'login_screen.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
Helpers helpers = Helpers(); Helpers helpers = Helpers();
@ -53,6 +56,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
return AppScaffold( return AppScaffold(
isShowAppBar: false, isShowAppBar: false,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
// baseViewModel: model, // baseViewModel: model,
body: SingleChildScrollView( body: SingleChildScrollView(
child: Center( child: Center(
@ -336,7 +340,13 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
.useAnotherAccount, .useAnotherAccount,
color: Colors.red[700], color: Colors.red[700],
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed(LOGIN); projectsProvider.isLogin = true;
Navigator.pushAndRemoveUntil(
AppGlobal.CONTEX,
FadePage(
page: RootPage(),
),
(r) => false);
}, },
), ),
@ -360,7 +370,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
Helpers.showErrorToast(authenticationViewModel.error); Helpers.showErrorToast(authenticationViewModel.error);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
} else { } else {
authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeForDoctorAppRes); authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeForDoctorAppRes);
sharedPref.setString(PASSWORD, widget.password); sharedPref.setString(PASSWORD, widget.password);
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
this.startSMSService(authMethodType); this.startSMSService(authMethodType);
@ -382,7 +392,7 @@ class _VerificationMethodsScreenState extends State<VerificationMethodsScreen> {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
Helpers.showErrorToast(authenticationViewModel.error); Helpers.showErrorToast(authenticationViewModel.error);
} else { } else {
authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeVerificationScreenRes); authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeVerificationScreenRes);
if (authMethodType == AuthMethodTypes.SMS || if (authMethodType == AuthMethodTypes.SMS ||
authMethodType == AuthMethodTypes.WhatsApp) { authMethodType == AuthMethodTypes.WhatsApp) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);

@ -6,11 +6,12 @@ class MethodTypeCard extends StatelessWidget {
Key key, Key key,
this.assetPath, this.assetPath,
this.onTap, this.onTap,
this.label, this.label, this.height = 20,
}) : super(key: key); }) : super(key: key);
final String assetPath; final String assetPath;
final Function onTap; final Function onTap;
final String label; final String label;
final double height;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -38,7 +39,7 @@ class MethodTypeCard extends StatelessWidget {
], ],
), ),
SizedBox( SizedBox(
height: 20, height:height ,
), ),
AppText( AppText(
label, label,

@ -309,12 +309,14 @@ class SMSOTP {
} }
} }
checkValue() { checkValue() async {
if (verifyAccountForm.currentState.validate()) { if (verifyAccountForm.currentState.validate()) {
onSuccess(digit1.text.toString() + onSuccess(digit1.text.toString() +
digit2.text.toString() + digit2.text.toString() +
digit3.text.toString() + digit3.text.toString() +
digit4.text.toString()); digit4.text.toString());
this.isClosed = true;
} }
} }
@ -341,7 +343,9 @@ class SMSOTP {
Future.delayed(Duration(seconds: 1), () { Future.delayed(Duration(seconds: 1), () {
if (this.remainingTime > 0) { if (this.remainingTime > 0) {
if (isClosed == false) startTimer(setState); if (isClosed == false) {
startTimer(setState);
}
} else { } else {
Navigator.pop(context); Navigator.pop(context);
} }

@ -81,6 +81,7 @@ class _VerificationMethodsListState extends State<VerificationMethodsList> {
assetPath: 'assets/images/login/more_icon.png', assetPath: 'assets/images/login/more_icon.png',
onTap: widget.onShowMore, onTap: widget.onShowMore,
label: TranslationBase.of(context).moreVerification, label: TranslationBase.of(context).moreVerification,
height: 0,
); );
} }
} }

Loading…
Cancel
Save