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.
307 lines
12 KiB
Dart
307 lines
12 KiB
Dart
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
import 'package:diplomaticquarterapp/config/size_config.dart';
|
|
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
|
|
import 'package:diplomaticquarterapp/core/viewModels/appointment_rate_view_model.dart';
|
|
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
import 'package:diplomaticquarterapp/locator.dart';
|
|
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart';
|
|
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
|
|
import 'package:diplomaticquarterapp/pages/login/login-type.dart';
|
|
import 'package:diplomaticquarterapp/pages/rateAppointment/rate_appointment_doctor.dart';
|
|
import 'package:diplomaticquarterapp/routes.dart';
|
|
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
|
|
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
|
|
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
|
|
import 'package:diplomaticquarterapp/widgets/input/text_field.dart';
|
|
import 'package:diplomaticquarterapp/widgets/mobile-no/mobile_no.dart';
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class Login extends StatefulWidget {
|
|
@override
|
|
_Login createState() => _Login();
|
|
}
|
|
|
|
class _Login extends State<Login> {
|
|
final util = Utils();
|
|
final nationalIDorFile = TextEditingController();
|
|
final int loginType = LoginType.loginType;
|
|
String mobileNo;
|
|
String countryCode = '966';
|
|
bool isButtonDisabled = true;
|
|
final authService = new AuthProvider();
|
|
var sharedPref = new AppSharedPreferences();
|
|
bool isLoading = false;
|
|
AppointmentRateViewModel appointmentRateViewModel =
|
|
locator<AppointmentRateViewModel>();
|
|
|
|
AuthenticatedUserObject authenticatedUserObject =
|
|
locator<AuthenticatedUserObject>();
|
|
|
|
ProjectViewModel projectViewModel;
|
|
ToDoCountProviderModel toDoProvider;
|
|
|
|
@override
|
|
void initState() {
|
|
// getDeviceToken();
|
|
super.initState();
|
|
}
|
|
|
|
getDeviceToken() async {
|
|
setState(() async {
|
|
nationalIDorFile.text = await sharedPref.getString(PUSH_TOKEN);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
projectViewModel = Provider.of(context);
|
|
toDoProvider = Provider.of<ToDoCountProviderModel>(context);
|
|
return AppScaffold(
|
|
appBarTitle: TranslationBase.of(context).login,
|
|
isShowAppBar: true,
|
|
isShowDecPage: false,
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
padding: EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 30),
|
|
height: SizeConfig.realScreenHeight * .9,
|
|
width: SizeConfig.realScreenWidth,
|
|
child: Column(
|
|
children: <Widget>[
|
|
Expanded(
|
|
flex: 2,
|
|
child: AppText(
|
|
TranslationBase.of(context).enterNationalId,
|
|
fontSize: SizeConfig.textMultiplier * 3.5,
|
|
textAlign: TextAlign.start,
|
|
)),
|
|
Expanded(
|
|
flex: 3,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: <Widget>[
|
|
MobileNo(
|
|
onNumberChange: (value) =>
|
|
{mobileNo = value, validateForm()},
|
|
onCountryChange: (value) => countryCode = value),
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Container(
|
|
child: TextFields(
|
|
fontWeight: FontWeight.normal,
|
|
controller: nationalIDorFile,
|
|
onChanged: (value) => {validateForm()},
|
|
prefixIcon: Icon(
|
|
loginType == 1
|
|
? Icons.chrome_reader_mode
|
|
: Icons.receipt,
|
|
color: Color(0xFF40ACC9)),
|
|
padding: EdgeInsets.only(
|
|
top: 20, bottom: 20, left: 10, right: 10),
|
|
hintText: loginType == 1
|
|
? TranslationBase.of(context).nationalID
|
|
: TranslationBase.of(context).fileNo,
|
|
)))
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
flex: 3,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
Divider(
|
|
color: Colors.grey,
|
|
height: 2,
|
|
),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: DefaultButton(
|
|
TranslationBase.of(context).login,
|
|
() => {this.startLogin()},
|
|
color: isButtonDisabled == true
|
|
? Colors.grey
|
|
: Colors.grey[900],
|
|
textColor: Colors.white,
|
|
))
|
|
],
|
|
),
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
startLogin() {
|
|
if (isButtonDisabled == false) {
|
|
checkUserAuthentication();
|
|
}
|
|
}
|
|
|
|
void validateForm() {
|
|
if (util.validateIDBox(nationalIDorFile.text, loginType) == true &&
|
|
util.isSAUDIIDValid(nationalIDorFile.text, loginType) == true) {
|
|
setState(() {
|
|
isButtonDisabled = false;
|
|
});
|
|
} else {
|
|
setState(() {
|
|
isButtonDisabled = true;
|
|
});
|
|
}
|
|
}
|
|
|
|
checkUserAuthentication() {
|
|
// showLoader(true);
|
|
var request = CheckPatientAuthenticationReq();
|
|
request.isRegister = false;
|
|
request.patientMobileNumber = int.parse(mobileNo);
|
|
request.zipCode = countryCode;
|
|
request.searchType = this.loginType;
|
|
request.deviceTypeID = this.loginType;
|
|
if (this.loginType == 1) {
|
|
request.patientIdentificationID = this.nationalIDorFile.text;
|
|
request.patientID = 0;
|
|
} else {
|
|
request.patientIdentificationID = '';
|
|
request.patientID = int.parse(nationalIDorFile.text);
|
|
}
|
|
sharedPref.setObject(REGISTER_DATA_FOR_REGISTER, request);
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
authService
|
|
.checkPatientAuthentication(request)
|
|
.then((value) => {
|
|
//showLoader(false),
|
|
if (value['isSMSSent'])
|
|
{
|
|
sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']),
|
|
sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request),
|
|
GifLoaderDialogUtils.hideDialog(context),
|
|
Navigator.of(context).pushNamed(CONFIRM_LOGIN)
|
|
}
|
|
else
|
|
{
|
|
if (value['IsAuthenticated']) {this.checkActivationCode()}
|
|
}
|
|
})
|
|
.catchError((err) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
ConfirmDialog dialog = new ConfirmDialog(
|
|
context: context,
|
|
confirmMessage: err,
|
|
okText: TranslationBase.of(context).confirm,
|
|
cancelText: TranslationBase.of(context).cancel_nocaps,
|
|
okFunction: () => {
|
|
ConfirmDialog.closeAlertDialog(context),
|
|
Navigator.of(context).pushNamed(
|
|
REGISTER,
|
|
),
|
|
},
|
|
cancelFunction: () => {ConfirmDialog.closeAlertDialog(context)});
|
|
dialog.showAlertDialog(context);
|
|
});
|
|
// SMSOTP.showLoadingDialog(context, false),
|
|
}
|
|
|
|
checkActivationCode({code}) async {
|
|
Map<String, dynamic> request = {};
|
|
// request.logInTokenID = await sharedPref.getString(LOGIN_TOKEN_ID);
|
|
// request.activationCode = code ?? "0000";
|
|
// request.isSilentLogin = code != null ? false : true;
|
|
if (code == null)
|
|
//showLoader(true);
|
|
request['PatientMobileNumber'] = int.parse(mobileNo);
|
|
request['ZipCode'] = countryCode;
|
|
request['SearchType'] = loginType;
|
|
request['LoginType'] = loginType;
|
|
if (this.loginType == 1) {
|
|
request['PatientIdentificationID'] = this.nationalIDorFile.text;
|
|
request['PatientID'] = 0;
|
|
} else {
|
|
request['PatientIdentificationID'] = '';
|
|
request['PatientID'] = int.parse(nationalIDorFile.text);
|
|
}
|
|
// request.isRegister = false;
|
|
this.authService.checkActivationCode(request, code).then((result) => {
|
|
sharedPref.remove(FAMILY_FILE),
|
|
result = CheckActivationCode.fromJson(result),
|
|
result.list.isFamily = false,
|
|
this.sharedPref.setObject(USER_PROFILE, result.list),
|
|
this.sharedPref.setObject(MAIN_USER, result.list),
|
|
this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID),
|
|
this.sharedPref.setString(TOKEN, result.authenticationTokenID),
|
|
authenticatedUserObject.getUser(),
|
|
// authenticatedUserObject.user = AuthenticatedUser.fromJson(result.list),
|
|
authenticatedUserObject.isLogin = true,
|
|
appointmentRateViewModel.isLogin = true,
|
|
projectViewModel.isLogin = true,
|
|
appointmentRateViewModel
|
|
.getIsLastAppointmentRatedList()
|
|
.then((value) => {
|
|
getToDoCount(),
|
|
GifLoaderDialogUtils.hideDialog(context),
|
|
if (appointmentRateViewModel.isHaveAppointmentNotRate)
|
|
{
|
|
Navigator.pushAndRemoveUntil(
|
|
context,
|
|
FadePage(
|
|
page: RateAppointmentDoctor(),
|
|
),
|
|
(r) => false)
|
|
}
|
|
else
|
|
{
|
|
Navigator.pushAndRemoveUntil(
|
|
context,
|
|
FadePage(
|
|
page: LandingPage(),
|
|
),
|
|
(r) => false)
|
|
}
|
|
})
|
|
.catchError((err) {
|
|
print(err);
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
}),
|
|
// SMSOTP.showLoadingDialog(context, false),
|
|
});
|
|
}
|
|
|
|
getToDoCount() {
|
|
toDoProvider.setState(0, true);
|
|
ClinicListService service = new ClinicListService();
|
|
service.getActiveAppointmentNo(context).then((res) {
|
|
print(res['AppointmentActiveNumber']);
|
|
if (res['MessageStatus'] == 1) {
|
|
toDoProvider.setState(res['AppointmentActiveNumber'], true);
|
|
} else {}
|
|
}).catchError((err) {
|
|
print(err);
|
|
});
|
|
}
|
|
|
|
// showLoader(bool isTrue) {
|
|
// setState(() {
|
|
// isLoading = isTrue;
|
|
// });
|
|
// }
|
|
}
|