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

441 lines
17 KiB
Dart

import 'dart:async';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/models/clinic_model.dart';
import 'package:doctor_app_flutter/models/profile_req_Model.dart';
import 'package:doctor_app_flutter/widgets/auth/show_timer_text.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();
Helpers helpers = Helpers();
class VerifyAccount extends StatefulWidget {
VerifyAccount({this.changeLoadingStata});
final Function changeLoadingStata;
@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;
AuthProvider authProv;
bool _isInit = true;
var model;
@override
void initState() {
super.initState();
_loggedUserFuture = getSharedPref();
}
Future<void> getSharedPref() async {
sharedPref.getObj('loggedUser').then((userInfo) {
_loggedUser = userInfo;
});
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_isInit) {
authProv = Provider.of<AuthProvider>(context);
final routeArgs = ModalRoute.of(context).settings.arguments as Map;
model = routeArgs['model'];
}
_isInit = false;
}
@override
Widget build(BuildContext context) {
authProv = Provider.of<AuthProvider>(context);
final focusD1 = FocusNode();
final focusD2 = FocusNode();
final focusD3 = FocusNode();
final focusD4 = FocusNode();
return FutureBuilder(
future: Future.wait([_loggedUserFuture]),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return DrAppCircularProgressIndeicator();
default:
if (snapshot.hasError) {
DrAppToastMsg.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(
textInputAction: TextInputAction.next,
style: buildTextStyle(),
autofocus: true,
maxLength: 1,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit1'] = val;
},
validator: validateCodeDigit,
onFieldSubmitted: (_) {
FocusScope.of(context)
.requestFocus(focusD2);
},
onChanged: (val) {
if (val.length == 1) {
FocusScope.of(context)
.requestFocus(focusD2);
}
},
),
),
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
focusNode: focusD2,
textInputAction: TextInputAction.next,
maxLength: 1,
textAlign: TextAlign.center,
style: buildTextStyle(),
keyboardType: TextInputType.number,
decoration:
buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit2'] =
val;
},
onFieldSubmitted: (_) {
FocusScope.of(context)
.requestFocus(focusD3);
},
onChanged: (val) {
if (val.length == 1) {
FocusScope.of(context)
.requestFocus(focusD3);
}
},
validator: validateCodeDigit),
),
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
focusNode: focusD3,
textInputAction: TextInputAction.next,
maxLength: 1,
textAlign: TextAlign.center,
style: buildTextStyle(),
keyboardType: TextInputType.number,
decoration:
buildInputDecoration(context),
onSaved: (val) {
verifyAccountFormValue['digit3'] =
val;
},
onFieldSubmitted: (_) {
FocusScope.of(context)
.requestFocus(focusD4);
},
onChanged: (val) {
if (val.length == 1) {
FocusScope.of(context)
.requestFocus(focusD4);
}
},
validator: validateCodeDigit)),
Container(
width: SizeConfig.realScreenWidth * 0.20,
child: TextFormField(
focusNode: focusD4,
maxLength: 1,
textAlign: TextAlign.center,
style: buildTextStyle(),
keyboardType: TextInputType.number,
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, widget.changeLoadingStata);
// Navigator.of(context).pushNamed(HOME);
},
elevation: 0.0,
child: Container(
width: double.infinity,
height: 50,
child: Center(
child: Text(
'Verfiy'.toUpperCase(),
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),
ShowTimerText(model: model),
buildSizedBox(10),
])));
}
}
});
}
/*
*@author: Elham Rababah
*@Date:19/4/2020
*@param:
*@return:
*@desc: change the style for the input field
*/
TextStyle buildTextStyle() {
return TextStyle(
fontSize: SizeConfig.textMultiplier * 3,
);
}
String validateCodeDigit(value) {
if (value.isEmpty) {
return 'Please enter your Password';
}
return null;
}
/*
*@author: Elham Rababah
*@Date:28/4/2020
*@param: context
*@return:InputDecoration
*@desc: buildInputDecoration
*/
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),
));
}
/*
*@author: Elham Rababah
*@Date:28/4/2020
*@param:
*@return: RichText
*@desc: buildText
*/
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, Function changeLoadingStata) async {
if (verifyAccountForm.currentState.validate()) {
changeLoadingStata(true);
verifyAccountForm.currentState.save();
final activationCode = verifyAccountFormValue['digit1'] +
verifyAccountFormValue['digit2'] +
verifyAccountFormValue['digit3'] +
verifyAccountFormValue['digit4'];
print(activationCode);
int projectID = await sharedPref.getInt(PROJECT_ID);
Map model = {
"activationCode": activationCode,
"DoctorID": _loggedUser['DoctorID'],
"LogInTokenID": _loggedUser['LogInTokenID'],
"ProjectID": projectID,
"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
};
changeLoadingStata(true);
authProv.memberCheckActivationCodeNew(model).then((res) {
// changeLoadingStata(false);
if (res['MessageStatus'] == 1) {
sharedPref.setString(TOKEN, res['AuthenticationTokenID']);
if (res['List_DoctorProfile'] != null) {
loginProcessCompleted(
res['List_DoctorProfile'][0], changeLoadingStata);
} else {
_asyncSimpleDialog(context, res['List_DoctorsClinic'], 'ClinicName',
'Please Select Clinic')
.then((clinicInfo) {
ClinicModel clinic = ClinicModel.fromJson(clinicInfo);
print(clinicInfo);
getDocProfiles(clinic, changeLoadingStata);
});
}
} else {
changeLoadingStata(false);
helpers.showErrorToast(res['ErrorEndUserMessage']);
}
}).catchError((err) {
changeLoadingStata(false);
print('$err');
helpers.showErrorToast();
});
} else {
// changeLoadingStata(false);
}
}
/*
*@author: Elham Rababah
*@Date:17/5/2020
*@param: Map<String, dynamic> profile, Function changeLoadingStata
*@return:
*@desc: loginProcessCompleted
*/
loginProcessCompleted(
Map<String, dynamic> profile, Function changeLoadingStata) {
changeLoadingStata(false);
sharedPref.setObj(DOCTOR_PROFILE, profile);
Navigator.of(context).pushNamed(HOME);
}
Future<dynamic> _asyncSimpleDialog(
BuildContext context, List list, String txtKey,
[String text = '']) async {
return await showDialog<dynamic>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return SimpleDialog(
title: Text(text),
children: list.map((value) {
return SimpleDialogOption(
onPressed: () {
Navigator.pop(context,
value); //here passing the index to be return on item selection
},
child: Text(value[txtKey]), //item value
);
}).toList(),
);
});
}
/*
*@author: Elham Rababah
*@Date:17/5/2020
*@param: ClinicModel clinicInfo, Function changeLoadingStata
*@return:
*@desc: getDocProfiles
*/
getDocProfiles(ClinicModel clinicInfo, Function changeLoadingStata) {
ProfileReqModel docInfo = new ProfileReqModel(
doctorID: clinicInfo.doctorID,
clinicID: clinicInfo.clinicID,
license: true,
projectID: clinicInfo.projectID,
tokenID: '',
languageID: 2);
authProv.getDocProfiles(docInfo).then((res) {
if (res['MessageStatus'] == 1) {
print("DoctorProfileList ${res['DoctorProfileList'][0]}");
loginProcessCompleted(res['DoctorProfileList'][0], changeLoadingStata);
} else {
changeLoadingStata(false);
helpers.showErrorToast(res['ErrorEndUserMessage']);
}
}).catchError((err) {
print('$err');
changeLoadingStata(false);
print('$err');
helpers.showErrorToast();
});
}
}