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 { MainAxisAlignment spaceBetweenMethods = MainAxisAlignment.spaceBetween; Future _loggedUserFuture; var _loggedUser; @override void initState() { super.initState(); _loggedUserFuture = getSharedPref(); } Future getSharedPref() async { sharedPref.getObj('loggedUser').then((userInfo) { _loggedUser = userInfo; }); } @override Widget build(BuildContext context) { AuthProvider authProv = Provider.of(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.90, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Please choose one of the Following option to verify", style: TextStyle( fontSize: 3.5 * SizeConfig.textMultiplier, ), ), SizedBox( height: 40, ), Container( width: SizeConfig.realScreenWidth * 80, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: spaceBetweenMethods, children: [ buildVerificationMethod( context, 'assets/images/verification_fingerprint_icon.png', 'Fingerprint', () {}), buildVerificationMethod( context, 'assets/images/verification_faceid_icon.png', 'Face ID', () {}), ], ), SizedBox( height: 40, ), Row( mainAxisAlignment: spaceBetweenMethods, children: [ buildVerificationMethod( context, 'assets/images/verification_whatsapp_icon.png', 'WhatsApp', () { sendActivationCodeByOtpNotificationType( 2, authProv); }), buildVerificationMethod( context, 'assets/images/verification_sms_icon.png', 'SMS', () { sendActivationCodeByOtpNotificationType( 1, authProv); }), ], ) ], ), ), SizedBox( height: SizeConfig.heightMultiplier * 2, ) ], ), ); } } }); } InkWell buildVerificationMethod(context, url, dec, Function fun) { return 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: [ Container( margin: EdgeInsetsDirectional.only( top: SizeConfig.heightMultiplier * 0.5), child: Image.asset( url, height: SizeConfig.heightMultiplier * 10, 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": _loggedUser['MobileNumber'],//785228065, "IPAdress": "11.11.11.11", "LanguageID": 2, "ProjectID": 15, //TODO : this should become daynamci "ZipCode": _loggedUser['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 } } }