create method card and remove future builder from verification method widget
parent
a3caf023e2
commit
3ca4ac3632
@ -0,0 +1,242 @@
|
||||
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> {
|
||||
|
||||
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)},
|
||||
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,
|
||||
)
|
||||
],
|
||||
),
|
||||
)));
|
||||
};
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue