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/verfiy_account.dart

254 lines
9.8 KiB
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/dr_app_toast_msg.dart';
import '../../util/helpers.dart';
import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
DrAppToastMsg toastMsg = DrAppToastMsg();
Helpers helpers = Helpers();
class VerifyAccount extends StatefulWidget {
@override
_VerifyAccountState createState() => _VerifyAccountState();
}
class _VerifyAccountState extends State<VerifyAccount> {
final verifyAccountForm = GlobalKey<FormState>();
Map verifyAccountFormValue = {
'digit1': null,
'digit2': null,
'digit3': null,
'digit4': null,
};
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) {
toastMsg.showErrorToast('Error: ${snapshot.error}');
return Text('Error: ${snapshot.error}');
} else {
return Form(
key: verifyAccountForm,
child: Container(
width: SizeConfig.realScreenWidth * 0.90,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
buildSizedBox(30),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
decoration:
buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit1'] =
val;
},
validator: validateCodeDigit,
)),
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
decoration:
buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit2'] =
val;
},
validator: validateCodeDigit)),
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
decoration:
buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit3'] =
val;
},
validator: validateCodeDigit)),
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
decoration:
buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit4'] =
val;
},
validator: validateCodeDigit))
],
),
// buildSizedBox(40),
buildSizedBox(20),
buildText(),
// buildSizedBox(10.0),
// Text()
buildSizedBox(40),
// buildSizedBox(),
RaisedButton(
onPressed: () {
verifyAccount(authProv);
// Navigator.of(context).pushNamed(HOME);
},
elevation: 0.0,
child: Container(
width: double.infinity,
height: 50,
child: Center(
child: Text(
'Verfiy'.toUpperCase(),
// textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize:
3 * SizeConfig.textMultiplier),
),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(
width: 0.5,
color: Hexcolor('#CCCCCC'))),
),
buildSizedBox(20),
Center(
child: Text(
"Resend in 4.20",
style: TextStyle(
fontSize: 3.0 * SizeConfig.textMultiplier,
),
),
),
buildSizedBox(10),
])));
}
}
});
}
String validateCodeDigit(value) {
if (value.isEmpty) {
return 'Please enter your Password';
}
return null;
}
InputDecoration buildInputDecoration(BuildContext context) {
return InputDecoration(
// ts/images/password_icon.png
contentPadding: EdgeInsets.only(top: 30, bottom: 30),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
borderSide: BorderSide(color: Colors.black),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Theme.of(context).primaryColor),
));
}
RichText buildText() {
var text = RichText(
text: new TextSpan(
style: new TextStyle(
fontSize: 3.0 * SizeConfig.textMultiplier, color: Colors.black),
children: <TextSpan>[
new TextSpan(text: 'You will receive a '),
new TextSpan(
text: 'Login Code ',
style: TextStyle(fontWeight: FontWeight.w700)),
new TextSpan(text: 'By SMS, Please enter the code')
]));
return text;
}
SizedBox buildSizedBox([double height = 20]) {
return SizedBox(
height: height,
);
}
/*
*@author: Elham Rababah
*@Date:15/4/2020
*@param: authProv
*@return:
*@desc: verify Account func call sendActivationCodeByOtpNotificationType service
*/
verifyAccount(AuthProvider authProv) {
if (verifyAccountForm.currentState.validate()) {
verifyAccountForm.currentState.save();
final activationCode = verifyAccountFormValue['digit1'] +
verifyAccountFormValue['digit2'] +
verifyAccountFormValue['digit3'] +
verifyAccountFormValue['digit4'];
print(activationCode);
Map model = {
"activationCode": activationCode,
"DoctorID": _loggedUser['List_MemberInformation'][0]['MemberID'],
"LogInTokenID": _loggedUser['LogInTokenID'],
"ProjectID": 15,
"LanguageID": 2,
"stamp": "2020-02-26T14:48:27.221Z",
"IPAdress": "11.11.11.11",
"VersionID": 1.2,
"Channel": 9,
"TokenID": "",
"SessionID": "i1UJwCTSqt",
"IsLoginForDoctorApp": true,
"IsSilentLogIN": false
};
authProv.sendActivationCodeByOtpNotificationType(model).then((res) {
// Navigator.of(context).pushNamed(VERIFY_ACCOUNT);
if (res['MessageStatus'] == 1) {
Navigator.of(context).pushNamed(VERIFY_ACCOUNT);
} else {
helpers.showErrorToast(res['ErrorEndUserMessage']);
}
}).catchError((err) {
print('$err');
helpers.showErrorToast();
});
}
}
}