do some refactor and change the code to view model
parent
7dbd4c9cc6
commit
fd9f93a936
@ -1,113 +0,0 @@
|
||||
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:hexcolor/hexcolor.dart';
|
||||
|
||||
import '../../config/size_config.dart';
|
||||
import '../../lookups/auth_lookup.dart';
|
||||
//TODO Elham delete this widget
|
||||
class AuthHeader extends StatelessWidget {
|
||||
var userType;
|
||||
AuthHeader(this.userType);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var screen = Container(
|
||||
margin: SizeConfig.isMobile
|
||||
? null
|
||||
: EdgeInsetsDirectional.fromSTEB(SizeConfig.realScreenWidth * 0.30,
|
||||
SizeConfig.realScreenWidth * 0.1, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: SizeConfig.isMobile
|
||||
? <Widget>[
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
buildWelText(context),
|
||||
buildDrSulText(context),
|
||||
]
|
||||
: <Widget>[
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
buildWelText(context),
|
||||
buildDrSulText(context),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
buildDrAppContainer(context)
|
||||
],
|
||||
));
|
||||
return screen;
|
||||
}
|
||||
|
||||
|
||||
Container buildDrAppContainer(BuildContext context) {
|
||||
if (userType == loginType.changePassword ||
|
||||
userType == loginType.verifyPassword ||
|
||||
userType == loginType.verificationMethods) {
|
||||
return Container();
|
||||
}
|
||||
return Container(
|
||||
child: Text(
|
||||
"Doctor App",
|
||||
style: TextStyle(
|
||||
fontSize:
|
||||
SizeConfig.isMobile ? 16 : SizeConfig.realScreenWidth * 0.030,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: HexColor('#B8382C')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Text buildDrSulText(BuildContext context) {
|
||||
if (userType == loginType.changePassword ||
|
||||
userType == loginType.verifyPassword ||
|
||||
userType == loginType.verificationMethods) {
|
||||
return Text('');
|
||||
}
|
||||
return Text(
|
||||
TranslationBase.of(context).drSulaimanAlHabib,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize:
|
||||
SizeConfig.isMobile ? 24 : SizeConfig.realScreenWidth * 0.029,
|
||||
fontFamily: 'Poppins'),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildWelText(BuildContext context) {
|
||||
String text = TranslationBase.of(context).welcomeTo;
|
||||
if (userType == loginType.unknownUser) {
|
||||
text = TranslationBase.of(context).welcomeBackTo;
|
||||
}
|
||||
if (userType == loginType.changePassword ||
|
||||
userType == loginType.verifyPassword ||
|
||||
userType == loginType.verificationMethods) {
|
||||
return Text('');
|
||||
}
|
||||
return AppText(
|
||||
text,
|
||||
// style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,244 +0,0 @@
|
||||
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
||||
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MethodCard extends StatefulWidget {
|
||||
final AuthMethodTypes authMethodType;
|
||||
final Function ( AuthMethodTypes type, bool isActive) authenticateUser;
|
||||
final Function onShowMore;
|
||||
|
||||
const MethodCard({Key key, this.authMethodType, this.authenticateUser, this.onShowMore}) : super(key: key);
|
||||
|
||||
@override
|
||||
_MethodCardState createState() => _MethodCardState();
|
||||
}
|
||||
|
||||
class _MethodCardState extends State<MethodCard> {
|
||||
|
||||
//TODO Elham change it to list Enum
|
||||
var _availableBiometrics;
|
||||
|
||||
final LocalAuthentication auth = LocalAuthentication();
|
||||
ProjectViewModel projectsProvider;
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_getAvailableBiometrics();
|
||||
}
|
||||
|
||||
|
||||
bool checkIfBiometricAvailable(BiometricType biometricType) {
|
||||
bool isAvailable = false;
|
||||
if (_availableBiometrics != null) {
|
||||
for (var i = 0; i < _availableBiometrics.length; i++) {
|
||||
if (biometricType == _availableBiometrics[i]) isAvailable = true;
|
||||
}
|
||||
}
|
||||
return isAvailable;
|
||||
}
|
||||
|
||||
Future<void> _getAvailableBiometrics() async {
|
||||
var availableBiometrics;
|
||||
try {
|
||||
availableBiometrics = await auth.getAvailableBiometrics();
|
||||
} on PlatformException catch (e) {
|
||||
print(e);
|
||||
}
|
||||
if (!mounted) return;
|
||||
|
||||
setState(() {
|
||||
_availableBiometrics = availableBiometrics;
|
||||
});
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
projectsProvider = Provider.of<ProjectViewModel>(context);
|
||||
|
||||
switch (widget.authMethodType) {
|
||||
case AuthMethodTypes.WhatsApp:
|
||||
return InkWell(
|
||||
onTap: () => {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)},
|
||||
//TODO Elham change it to widget
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/verify-whtsapp.png',
|
||||
height: 60,
|
||||
width: 60,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
AppText(
|
||||
TranslationBase.of(context).verifyWhatsApp,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
],
|
||||
),
|
||||
)));
|
||||
break;
|
||||
case AuthMethodTypes.SMS:
|
||||
return InkWell(
|
||||
onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)},
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/images/verify-sms.png',
|
||||
height: 60,
|
||||
width: 60,
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
AppText(
|
||||
TranslationBase.of(context).verifySMS,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
],
|
||||
),
|
||||
)));
|
||||
break;
|
||||
case AuthMethodTypes.Fingerprint:
|
||||
return InkWell(
|
||||
onTap: () => {
|
||||
if (checkIfBiometricAvailable(BiometricType.fingerprint))
|
||||
{widget.authenticateUser(AuthMethodTypes.Fingerprint, true)}
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/images/verification_fingerprint_icon.png',
|
||||
height: 60,
|
||||
width: 60,
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
AppText(
|
||||
TranslationBase.of(context).verifyFingerprint,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
],
|
||||
),
|
||||
)));
|
||||
break;
|
||||
case AuthMethodTypes.FaceID:
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (checkIfBiometricAvailable(BiometricType.face)) {
|
||||
widget.authenticateUser(AuthMethodTypes.FaceID, true);
|
||||
}
|
||||
},
|
||||
child:
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
margin: EdgeInsets.all(10),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/images/verification_faceid_icon.png',
|
||||
height: 60,
|
||||
width: 60,
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
AppText(
|
||||
TranslationBase.of(context).verifyFaceID,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
],
|
||||
),
|
||||
)));
|
||||
break;
|
||||
|
||||
default:
|
||||
return InkWell(
|
||||
onTap: widget.onShowMore,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/images/login/more_icon.png',
|
||||
height: 60,
|
||||
width: 60,
|
||||
),
|
||||
projectsProvider.isArabic
|
||||
? SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
: SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
AppText(
|
||||
TranslationBase.of(context).moreVerification,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
],
|
||||
),
|
||||
)));
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MethodTypeCard extends StatelessWidget {
|
||||
const MethodTypeCard({
|
||||
Key key,
|
||||
this.assetPath,
|
||||
this.onTap,
|
||||
this.label,
|
||||
}) : super(key: key);
|
||||
final String assetPath;
|
||||
final Function onTap;
|
||||
final String label;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: [
|
||||
Image.asset(
|
||||
assetPath,
|
||||
height: 60,
|
||||
width: 60,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
AppText(
|
||||
label,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
import 'package:doctor_app_flutter/core/enum/auth_method_types.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
||||
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||
import 'package:doctor_app_flutter/widgets/auth/method_type_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class VerificationMethodsList extends StatefulWidget {
|
||||
final AuthMethodTypes authMethodType;
|
||||
final Function(AuthMethodTypes type, bool isActive) authenticateUser;
|
||||
final Function onShowMore;
|
||||
final AuthenticationViewModel model;
|
||||
|
||||
const VerificationMethodsList(
|
||||
{Key key,
|
||||
this.authMethodType,
|
||||
this.authenticateUser,
|
||||
this.onShowMore,
|
||||
this.model})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_VerificationMethodsListState createState() =>
|
||||
_VerificationMethodsListState();
|
||||
}
|
||||
|
||||
class _VerificationMethodsListState extends State<VerificationMethodsList> {
|
||||
final LocalAuthentication auth = LocalAuthentication();
|
||||
ProjectViewModel projectsProvider;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
projectsProvider = Provider.of<ProjectViewModel>(context);
|
||||
|
||||
switch (widget.authMethodType) {
|
||||
case AuthMethodTypes.WhatsApp:
|
||||
return MethodTypeCard(
|
||||
assetPath: 'assets/images/verify-whtsapp.png',
|
||||
onTap: () =>
|
||||
{widget.authenticateUser(AuthMethodTypes.WhatsApp, true)},
|
||||
label: TranslationBase.of(context).verifyWhatsApp,
|
||||
);
|
||||
break;
|
||||
case AuthMethodTypes.SMS:
|
||||
return MethodTypeCard(
|
||||
assetPath: "assets/images/verify-sms.png",
|
||||
onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)},
|
||||
label: TranslationBase.of(context).verifySMS,
|
||||
);
|
||||
break;
|
||||
case AuthMethodTypes.Fingerprint:
|
||||
return MethodTypeCard(
|
||||
assetPath: 'assets/images/verification_fingerprint_icon.png',
|
||||
onTap: () async {
|
||||
if (await widget.model
|
||||
.checkIfBiometricAvailable(BiometricType.fingerprint)) {
|
||||
|
||||
widget.authenticateUser(AuthMethodTypes.Fingerprint, true);
|
||||
}
|
||||
},
|
||||
label: TranslationBase.of(context).verifyFingerprint,
|
||||
);
|
||||
break;
|
||||
case AuthMethodTypes.FaceID:
|
||||
return MethodTypeCard(
|
||||
assetPath: 'assets/images/verification_faceid_icon.png',
|
||||
onTap: () async {
|
||||
if (await widget.model
|
||||
.checkIfBiometricAvailable(BiometricType.face)) {
|
||||
widget.authenticateUser(AuthMethodTypes.FaceID, true);
|
||||
}
|
||||
},
|
||||
label: TranslationBase.of(context).verifyFaceID,
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
return MethodTypeCard(
|
||||
assetPath: 'assets/images/login/more_icon.png',
|
||||
onTap: widget.onShowMore,
|
||||
label: TranslationBase.of(context).moreVerification,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue