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.
188 lines
6.2 KiB
Dart
188 lines
6.2 KiB
Dart
|
3 years ago
|
import 'package:easy_localization/easy_localization.dart';
|
||
|
|
import 'package:flutter/foundation.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter/services.dart';
|
||
|
|
import 'package:flutter_svg/svg.dart';
|
||
|
|
import 'package:hmg_nurses/classes/colors.dart';
|
||
|
|
import 'package:hmg_nurses/classes/utils.dart';
|
||
|
|
import 'package:hmg_nurses/generated/locale_keys.g.dart';
|
||
|
|
import 'package:local_auth/local_auth.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> {
|
||
|
|
final LocalAuthentication localAuth = LocalAuthentication();
|
||
|
|
List<BiometricType> _availableBioMetricType = [];
|
||
|
|
|
||
|
|
int selectedFlag = 0;
|
||
|
|
bool isNeedVerifyWithFaceIDAndBiometrics = false;
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
_getAvailableBiometrics();
|
||
|
|
super.initState();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
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: ListView(
|
||
|
|
padding: const EdgeInsets.all(21),
|
||
|
|
physics: const BouncingScrollPhysics(),
|
||
|
|
children: [
|
||
|
|
Text(
|
||
|
|
LocaleKeys.pleaseVerifyForBio.tr(),
|
||
|
|
style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w600),
|
||
|
|
),
|
||
|
|
if (isNeedVerifyWithFaceIDAndBiometrics) Text(LocaleKeys.pleaseVerifyForBio.tr()),
|
||
|
|
GridView(
|
||
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, crossAxisSpacing: 13, mainAxisSpacing: 9),
|
||
|
|
physics: const NeverScrollableScrollPhysics(),
|
||
|
|
padding: const EdgeInsets.only(top: 9),
|
||
|
|
shrinkWrap: true,
|
||
|
|
children: [
|
||
|
|
if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(3),
|
||
|
|
if (!isNeedVerifyWithFaceIDAndBiometrics) getButton(4),
|
||
|
|
getButton(2),
|
||
|
|
getButton(1),
|
||
|
|
],
|
||
|
|
)
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<void> _getAvailableBiometrics() async {
|
||
|
|
try {
|
||
|
|
_availableBioMetricType = await localAuth.getAvailableBiometrics();
|
||
|
|
} on PlatformException catch (e) {
|
||
|
|
// AppToast.showErrorToast(message: e.message);
|
||
|
|
if (kDebugMode) {
|
||
|
|
print(e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (mounted) setState(() {});
|
||
|
|
}
|
||
|
|
|
||
|
|
Future<bool> loginWithFaceIDAndBiometrics() async {
|
||
|
|
bool authenticated = false;
|
||
|
|
try {
|
||
|
|
authenticated = await localAuth.authenticate(
|
||
|
|
localizedReason: 'Scan your fingerprint to authenticate',
|
||
|
|
);
|
||
|
|
} on PlatformException catch (e) {
|
||
|
|
if (kDebugMode) {
|
||
|
|
print(e);
|
||
|
|
}
|
||
|
|
Utils.hideLoading(context);
|
||
|
|
Utils.showToast("Please enable your Touch or Face ID");
|
||
|
|
}
|
||
|
|
return authenticated;
|
||
|
|
}
|
||
|
|
|
||
|
|
Widget _loginOptionButton(String title, String icon, int flag, int? loginIndex) {
|
||
|
|
bool isDisable = ((flag == 3 && !checkBiometricIsAvailable(BiometricType.face)) || (flag == 4 && !checkBiometricIsAvailable(BiometricType.fingerprint)));
|
||
|
|
return InkWell(
|
||
|
|
onTap: isDisable
|
||
|
|
? null
|
||
|
|
: () async {
|
||
|
|
if (flag == 0) {
|
||
|
|
setState(() {
|
||
|
|
// isMoreOption = true;
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
if (flag == 3 || flag == 4) {
|
||
|
|
bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics();
|
||
|
|
if (!authenticateWithFaceAndTouchID) {
|
||
|
|
return;
|
||
|
|
} else {
|
||
|
|
isNeedVerifyWithFaceIDAndBiometrics = true;
|
||
|
|
selectedFlag = flag;
|
||
|
|
setState(() {
|
||
|
|
return;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (isNeedVerifyWithFaceIDAndBiometrics) {
|
||
|
|
// performApiCall(_title, _icon, selectedFlag, _flag);
|
||
|
|
|
||
|
|
} else {
|
||
|
|
// performApiCall(_title, _icon, _flag, _flag);
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
child: Container(
|
||
|
|
padding: const EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 28),
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
borderRadius: BorderRadius.circular(15),
|
||
|
|
color: isDisable ? Colors.grey.withOpacity(0.3) : Colors.white,
|
||
|
|
border: Border.all(color: MyColors.lightGreyEFColor, width: 1),
|
||
|
|
),
|
||
|
|
child: Column(
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
|
children: <Widget>[
|
||
|
|
SvgPicture.asset(
|
||
|
|
icon,
|
||
|
|
height: 38,
|
||
|
|
width: 38,
|
||
|
|
color: isDisable ? MyColors.darkTextColor.withOpacity(0.7) : null,
|
||
|
|
),
|
||
|
|
Text(
|
||
|
|
title,
|
||
|
|
style: const TextStyle(fontWeight: FontWeight.w600),
|
||
|
|
)
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Widget getButton(int flag) {
|
||
|
|
switch (flag) {
|
||
|
|
case 1:
|
||
|
|
return _loginOptionButton(LocaleKeys.verifyThroughSMS.tr(), 'assets/images/login/verify_sms.svg', flag, null);
|
||
|
|
case 2:
|
||
|
|
return _loginOptionButton(LocaleKeys.verifyThroughWhatsapp.tr(), 'assets/images/login/verify_whatsapp.svg', flag, null);
|
||
|
|
case 3:
|
||
|
|
return _loginOptionButton(LocaleKeys.verifyThroughFace.tr(), 'assets/images/login/verify_face.svg', flag, BiometricType.face.index);
|
||
|
|
case 4:
|
||
|
|
return _loginOptionButton(LocaleKeys.verifyThroughFingerprint.tr(), 'assets/images/login/verify_thumb.svg', flag, BiometricType.fingerprint.index);
|
||
|
|
default:
|
||
|
|
return const SizedBox();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool checkBiometricIsAvailable(BiometricType biometricType) {
|
||
|
|
bool isAvailable = false;
|
||
|
|
for (int i = 0; i < _availableBioMetricType.length; i++) {
|
||
|
|
if (biometricType == _availableBioMetricType[i]) {
|
||
|
|
isAvailable = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return isAvailable;
|
||
|
|
}
|
||
|
|
}
|