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.
439 lines
22 KiB
Dart
439 lines
22 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hexcolor/hexcolor.dart';
|
|
import 'package:hmg_nurses/classes/colors.dart';
|
|
import 'package:hmg_nurses/classes/date-utils.dart';
|
|
import 'package:hmg_nurses/classes/enums.dart';
|
|
import 'package:hmg_nurses/extensions/int_extensions.dart';
|
|
import 'package:hmg_nurses/extensions/string_extensions.dart';
|
|
import 'package:hmg_nurses/extensions/util_extensions.dart';
|
|
import 'package:hmg_nurses/extensions/widget_extensions.dart';
|
|
import 'package:hmg_nurses/generated/locale_keys.g.dart';
|
|
import 'package:hmg_nurses/main.dart';
|
|
import 'package:hmg_nurses/provider/login_provider_model.dart';
|
|
import 'package:hmg_nurses/ui/login/login_vm.dart';
|
|
import 'package:hmg_nurses/ui/login/widgets/verification_method_card.dart';
|
|
import 'package:hmg_nurses/widgets/button/default_button.dart';
|
|
import 'package:local_auth/local_auth.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:sizer/sizer.dart';
|
|
|
|
// WhatsApp 2
|
|
// SMS 1
|
|
// Face ID 3
|
|
// Finger Print 4
|
|
|
|
class LoginMethodsPage extends StatefulWidget {
|
|
const LoginMethodsPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
LoginMethodsPageState createState() => LoginMethodsPageState();
|
|
}
|
|
|
|
class LoginMethodsPageState extends State<LoginMethodsPage> {
|
|
bool isMoreOption = false;
|
|
bool onlySMSBox = false;
|
|
late LoginViewModel loginViewModel;
|
|
LoginType? loginType;
|
|
AuthMethodTypes? selectedAuthType;
|
|
late LoginProviderModel loginProviderModel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (loginType == null) {
|
|
loginType = ModalRoute.of(context)!.settings.arguments as LoginType;
|
|
}
|
|
loginViewModel = context.read<LoginViewModel>();
|
|
loginProviderModel = context.read<LoginProviderModel>();
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
// actions: [Center(child: "Employee Digital ID".toText12(color: MyColors.textMixColor, isUnderLine: true).onPress(() {})), 21.width],
|
|
),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
padding: const EdgeInsets.all(21),
|
|
child: Column(
|
|
children: [
|
|
if (loginType == LoginType.SILENT_LOGIN && appState.lastLoginImeiDate != null)
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
LocaleKeys.welcomeBack.tr().toText12(),
|
|
(appState.lastLoginImeiDate!.titleDescription! + " " + appState.lastLoginImeiDate!.doctorName!).toText20(isBold: true),
|
|
heightSpacer3per(),
|
|
LocaleKeys.wouldYouLikeToLoginWithCurrentUsername.tr().toText14(),
|
|
heightSpacer3per(),
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
|
border: Border.all(color: HexColor('#707070'), width: 0.1),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
LocaleKeys.lastLoginDetails.tr().toText13(),
|
|
SizedBox(
|
|
width: 55.w,
|
|
child: Row(
|
|
children: [
|
|
"${LocaleKeys.verificationType.tr()} : ".toText11(),
|
|
loginViewModel.getType(appState.lastLoginImeiDate!.logInTypeID ?? 1).toText11(isBold: true),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
(appState.lastLoginImeiDate!.editedOn != null
|
|
? AppDateUtils.getDayMonthYearDateFormatted(AppDateUtils.convertStringToDate(appState.lastLoginImeiDate!.editedOn ?? ""), isMonthShort: true)
|
|
: appState.lastLoginImeiDate!.createdOn != null
|
|
? AppDateUtils.getDayMonthYearDateFormatted(AppDateUtils.convertStringToDate(appState.lastLoginImeiDate!.createdOn ?? ""), isMonthShort: true)
|
|
: '--')
|
|
.toText11(isBold: true),
|
|
heightSpacer06per(),
|
|
(appState.lastLoginImeiDate!.editedOn != null
|
|
? AppDateUtils.getHour(AppDateUtils.convertStringToDate(appState.lastLoginImeiDate!.editedOn ?? ""))
|
|
: appState.lastLoginImeiDate!.createdOn != null
|
|
? AppDateUtils.getHour(AppDateUtils.convertStringToDate(appState.lastLoginImeiDate!.createdOn ?? ""))
|
|
: '--')
|
|
.toText10()
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
heightSpacer3per(),
|
|
LocaleKeys.pleaseVerify.tr().toText14().paddingOnly(left: 1.w),
|
|
heightSpacer2per(),
|
|
],
|
|
),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
if (loginType == LoginType.FROM_LOGIN || loginType == LoginType.REGISTER_NEW_BIO)
|
|
Column(
|
|
children: [
|
|
LocaleKeys.pleaseVerifyForBio.tr().toText14(),
|
|
21.height,
|
|
],
|
|
),
|
|
if (loginType == LoginType.FROM_LOGIN || loginType == LoginType.SILENT_LOGIN)
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.faceID,
|
|
isBioAvailable: loginProviderModel.isFaceBioAvailable,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) async {
|
|
// loginViewModel.startSMSService(authMethodType, context: context);
|
|
// appState.setMemberBeforeLogin
|
|
bool isAuthenticated = await loginProviderModel.loginWithFaceIDAndBiometrics();
|
|
if (isAuthenticated) {
|
|
appState.lastLoginTyp = loginProviderModel.getLoginMethodId(AuthMethodTypes.faceID);
|
|
if (loginType == LoginType.FROM_LOGIN) {
|
|
setState(() {
|
|
loginType = LoginType.REGISTER_NEW_BIO;
|
|
selectedAuthType = AuthMethodTypes.faceID;
|
|
});
|
|
} else if (loginType == LoginType.SILENT_LOGIN) {
|
|
if (appState.lastLoginImeiDate!.logInTypeID == loginProviderModel.getLoginMethodId(AuthMethodTypes.faceID)) {
|
|
loginProviderModel.sendActivationCode(
|
|
appState.memberBeforeLogin!,
|
|
appState.projectID,
|
|
loginProviderModel.getLoginMethodId(AuthMethodTypes.sms),
|
|
true,
|
|
);
|
|
} else {
|
|
setState(() {
|
|
loginType = LoginType.REGISTER_NEW_BIO;
|
|
selectedAuthType = AuthMethodTypes.faceID;
|
|
});
|
|
}
|
|
}
|
|
} else {
|
|
print("Authentaction Failded");
|
|
}
|
|
},
|
|
),
|
|
),
|
|
21.width,
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.fingerPrint,
|
|
isBioAvailable: loginProviderModel.isFingerBioAvailable,
|
|
onShowMore: () async {
|
|
bool isAuthenticated = await loginProviderModel.loginWithFaceIDAndBiometrics();
|
|
if (isAuthenticated) {
|
|
if (loginType == LoginType.FROM_LOGIN) {
|
|
appState.lastLoginTyp = loginProviderModel.getLoginMethodId(AuthMethodTypes.fingerPrint);
|
|
loginType = LoginType.REGISTER_NEW_BIO;
|
|
selectedAuthType = AuthMethodTypes.fingerPrint;
|
|
setState(() {});
|
|
}
|
|
} else {
|
|
print("Authentaction Failded");
|
|
}
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
21.height,
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.sms,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
// loginViewModel.startSMSService(authMethodType, context: context);
|
|
if (selectedAuthType == null) {
|
|
appState.lastLoginTyp = loginProviderModel.getLoginMethodId(AuthMethodTypes.sms);
|
|
} else if (selectedAuthType == AuthMethodTypes.faceID || selectedAuthType == AuthMethodTypes.fingerPrint) {
|
|
appState.lastLoginTyp = loginProviderModel.getLoginMethodId(selectedAuthType!);
|
|
}
|
|
loginProviderModel.sendActivationCode(
|
|
appState.memberBeforeLogin!,
|
|
appState.projectID,
|
|
loginProviderModel.getLoginMethodId(AuthMethodTypes.sms),
|
|
false,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
21.width,
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.whatsApp,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
// loginViewModel.startSMSService(authMethodType, context: context);
|
|
if (selectedAuthType == null) {
|
|
appState.lastLoginTyp = loginProviderModel.getLoginMethodId(AuthMethodTypes.whatsApp);
|
|
} else if (selectedAuthType == AuthMethodTypes.faceID || selectedAuthType == AuthMethodTypes.fingerPrint) {
|
|
appState.lastLoginTyp = loginProviderModel.getLoginMethodId(selectedAuthType!);
|
|
}
|
|
loginProviderModel.sendActivationCode(
|
|
appState.memberBeforeLogin!,
|
|
appState.projectID,
|
|
loginProviderModel.getLoginMethodId(AuthMethodTypes.whatsApp),
|
|
false,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
// actions: [Center(child: "Employee Digital ID".toText12(color: MyColors.textMixColor, isUnderLine: true).onPress(() {})), 21.width],
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Center(
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
heightSpacer1per(),
|
|
if (loginViewModel.isFromLogin)
|
|
InkWell(
|
|
onTap: () {
|
|
// loginViewModel.setUnverified(false, isFromLogin: false);
|
|
// loginViewModel.setAppStatus(APPSTATUS.unAuthenticated);
|
|
},
|
|
child: const Icon(
|
|
Icons.arrow_back_ios,
|
|
color: MyColors.darkTextColor,
|
|
),
|
|
),
|
|
Column(
|
|
children: <Widget>[
|
|
heightSpacer1per(),
|
|
isMoreOption == false
|
|
? Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
LocaleKeys.welcomeBack.tr().toText12(),
|
|
"Dr Amal Ahmed".toText20(isBold: true),
|
|
heightSpacer3per(),
|
|
LocaleKeys.wouldYouLikeToLoginWithCurrentUsername.tr().toText14(),
|
|
heightSpacer3per(),
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
|
border: Border.all(color: HexColor('#707070'), width: 0.1),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
LocaleKeys.lastLoginDetails.tr().toText13(),
|
|
SizedBox(
|
|
width: 55.w,
|
|
child: Row(
|
|
children: [
|
|
"${LocaleKeys.verificationType.tr()} : ".toText11(),
|
|
"${loginViewModel.getType(1)}".toText11(isBold: true),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: ["12 NOV, 2022".toText11(isBold: true), heightSpacer06per(), "09:56 AM".toText10()],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
heightSpacer3per(),
|
|
LocaleKeys.pleaseVerify.tr().toText14().paddingOnly(left: 1.w),
|
|
heightSpacer2per(),
|
|
],
|
|
)
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
LocaleKeys.pleaseVerifyForBio.tr().toText14().paddingAll(10),
|
|
],
|
|
),
|
|
isMoreOption == false
|
|
? Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
|
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: SelectedAuthMethodTypesService.getMethodsTypeService(1),
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
loginViewModel.startSMSService(authMethodType, context: context);
|
|
},
|
|
),
|
|
),
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.moreOptions,
|
|
onShowMore: () {
|
|
setState(() {
|
|
isMoreOption = true;
|
|
});
|
|
},
|
|
))
|
|
]),
|
|
])
|
|
: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
|
|
onlySMSBox == false
|
|
? Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.fingerPrint,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
loginViewModel.startSMSService(authMethodType, context: context);
|
|
},
|
|
)),
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.faceID,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
loginViewModel.startSMSService(authMethodType, context: context);
|
|
},
|
|
))
|
|
],
|
|
)
|
|
: const SizedBox(),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.sms,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
loginViewModel.startSMSService(authMethodType, context: context);
|
|
},
|
|
)),
|
|
Expanded(
|
|
child: VerificationMethodsList(
|
|
authMethodType: AuthMethodTypes.whatsApp,
|
|
authenticateUser: (AuthMethodTypes authMethodType, isActive) {
|
|
loginViewModel.startSMSService(authMethodType, context: context);
|
|
},
|
|
))
|
|
],
|
|
),
|
|
]),
|
|
|
|
// )
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
bottomSheet: !isMoreOption
|
|
? null
|
|
: Container(
|
|
height: 10.h,
|
|
color: MyColors.backgroundColor,
|
|
width: double.infinity,
|
|
child: Center(
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 4.w),
|
|
child: DefaultButton(LocaleKeys.useAnotherAccount.tr(), () {}, colors: const [MyColors.redColor, MyColors.redColor]),
|
|
),
|
|
heightSpacer3per(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|