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.
doctor_app_flutter/lib/widgets/auth/verification_methods.dart

217 lines
7.7 KiB
Dart

import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';
import '../../config/size_config.dart';
import '../../providers/auth_provider.dart';
import '../../routes.dart';
import '../../util/dr_app_shared_pref.dart';
import '../../util/helpers.dart';
import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
Helpers helpers = Helpers();
/*
*@author: Elham Rababah
*@Date:4/7/2020
*@param:
*@return:
*@desc: Verification Methods widget
*/
class VerificationMethods extends StatefulWidget {
VerificationMethods({this.changeLoadingStata});
final Function changeLoadingStata;
@override
_VerificationMethodsState createState() => _VerificationMethodsState();
}
class _VerificationMethodsState extends State<VerificationMethods> {
MainAxisAlignment spaceBetweenMethods = MainAxisAlignment.spaceBetween;
Future _loggedUserFuture;
var _loggedUser;
@override
void initState() {
super.initState();
_loggedUserFuture = getSharedPref();
}
Future<void> getSharedPref() async {
sharedPref.getObj('loggedUser').then((userInfo) {
_loggedUser = userInfo;
});
}
@override
Widget build(BuildContext context) {
AuthProvider authProv = Provider.of<AuthProvider>(context);
return FutureBuilder(
future: Future.wait([_loggedUserFuture]),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return DrAppCircularProgressIndeicator();
default:
if (snapshot.hasError) {
helpers.showErrorToast('Error: ${snapshot.error}');
return Text('Error: ${snapshot.error}');
} else {
return Container(
width: SizeConfig.realScreenWidth * 0.80,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Please choose one of the Following option to verify",
style: TextStyle(
fontSize: 3.5 * SizeConfig.textMultiplier,
),
),
SizedBox(
height: 20,
),
Container(
height: SizeConfig.realScreenHeight * 0.6,
child: CustomScrollView(
primary: false,
slivers: <Widget>[
SliverPadding(
padding: const EdgeInsets.all(0),
sliver: SliverGrid.count(
// childAspectRatio: 0.7,
crossAxisSpacing: 0,
mainAxisSpacing: 5,
crossAxisCount: 2,
children: <Widget>[
buildVerificationMethod(
context,
'assets/images/verification_fingerprint_icon.png',
'Fingerprint',
() {}),
buildVerificationMethod(
context,
'assets/images/verification_faceid_icon.png',
'Face ID',
() {}),
buildVerificationMethod(
context,
'assets/images/verification_whatsapp_icon.png',
'WhatsApp', () {
sendActivationCodeByOtpNotificationType(
2, authProv);
}),
buildVerificationMethod(
context,
'assets/images/verification_sms_icon.png',
'SMS', () {
sendActivationCodeByOtpNotificationType(
1, authProv);
}),
],
),
),
],
),
// height: 500,
),
SizedBox(
// height: 20,
)
],
),
);
}
}
});
}
Center buildVerificationMethod(context, url, dec, Function fun) {
return Center(
child: InkWell(
onTap: fun,
child: Container(
// height: SizeConfig.heightMultiplier *2,
height: SizeConfig.heightMultiplier * 19,
width: SizeConfig.widthMultiplier * 37,
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Hexcolor(
'#CCCCCC') // <--- border width here
),
borderRadius: BorderRadius.all(Radius.circular(10))),
child: Column(
children: <Widget>[
Container(
margin: EdgeInsetsDirectional.only(
top: SizeConfig.heightMultiplier * 0.5),
child: Image.asset(
url,
height: SizeConfig.heightMultiplier * 11,
fit: BoxFit.cover,
),
),
SizedBox(
height: 10,
),
Text(
dec,
style: TextStyle(fontSize: SizeConfig.textMultiplier * 2),
)
],
),
),
),
);
}
/*
*@author: Elham Rababah
*@Date:15/4/2020
*@param: oTPSendType
*@return:
*@desc: send Activation Code By Otp Notification Type
*/
sendActivationCodeByOtpNotificationType(oTPSendType, AuthProvider authProv) {
widget.changeLoadingStata(true);
// TODO : build enum for verfication method
if (oTPSendType == 1 || oTPSendType == 2) {
Map model = {
"LogInTokenID": _loggedUser['LogInTokenID'],
"Channel": 9,
"MobileNumber": 785228065, //_loggedUser['MobileNumber'],
"IPAdress": "11.11.11.11",
"LanguageID": 2,
"ProjectID": 15, //TODO : this should become daynamci
"ZipCode": 962, //_loggedUser['ZipCode'],
"UserName": _loggedUser['List_MemberInformation'][0]['MemberID'],
"OTP_SendType": oTPSendType
};
// print('$_loggedUser');
// print(oTPSendType);
authProv.sendActivationCodeByOtpNotificationType(model).then((res) {
// Navigator.of(context).pushNamed(VERIFY_ACCOUNT);
widget.changeLoadingStata(false);
if (res['MessageStatus'] == 1) {
Navigator.of(context).pushNamed(VERIFY_ACCOUNT);
} else {
print(res['ErrorEndUserMessage']);
helpers.showErrorToast(res['ErrorEndUserMessage']);
}
// Navigator.of(context).pushNamed(HOME);
}).catchError((err) {
print('$err');
widget.changeLoadingStata(false);
helpers.showErrorToast();
});
} else {
// TODO route to this page with parameters to inicate we should present 2 option
}
}
}