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.
diplomatic-quarter/lib/pages/login/forgot-password.dart

157 lines
5.4 KiB
Dart

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/alert_dialog.dart';
import 'package:diplomaticquarterapp/widgets/mobile-no/mobile_no.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/otp/sms-popup.dart';
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ForgotPassword extends StatefulWidget {
@override
_ForgotPassword createState() => _ForgotPassword();
}
class _ForgotPassword extends State<ForgotPassword> {
String selectedType = 'Saudi Arabia';
String countryCode = '966';
final TextEditingController nationalIDorFile = null;
String mobileNo = "";
var con;
@override
Widget build(BuildContext context) {
con = context;
return AppScaffold(
appBarTitle: TranslationBase.of(context).forgotFileNoTitle,
isShowAppBar: true,
isShowDecPage: false,
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(top: 10, left: 20, right: 20),
height: SizeConfig.realScreenHeight * .8,
width: SizeConfig.realScreenWidth,
child: Column(children: <Widget>[
Expanded(
flex: 1,
child: AppText(
TranslationBase.of(context).forgotDesc,
fontSize: SizeConfig.textMultiplier * 3,
textAlign: TextAlign.start,
marginTop: 10.0,
)),
Expanded(
flex: 2,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[],
),
MobileNo(onNumberChange: (value) {
setState(() {
mobileNo = value;
});
}, onCountryChange: (value) {
setState(() {
countryCode = value;
});
}),
],
),
),
Expanded(
flex: 2,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: DefaultButton(
TranslationBase.of(context).submit,
() {
sendPatientIDBySMS();
// print(mobileNo.text);
},
color: mobileNo.length >= 9 == true
? Colors.grey[900]
: Colors.grey,
textColor: Colors.white,
)),
],
),
],
))
]),
)));
}
sendPatientIDBySMS() {
GifLoaderDialogUtils.showMyDialog(context);
final authService = new AuthProvider();
authService.sendPatientIDSMS(mobileNo, countryCode, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
if (res['MessageStatus'] == 1) {
this.startSMSService(mobileNo, res['LogInTokenID']);
} else {
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
}
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
print(err);
});
}
startSMSService(mobile, token) {
new SMSOTP(
context,
1,
mobile,
(value) => {this.checkActivationCode(value, token, int.parse(mobileNo))},
() => {
print('Faild..'),
},
).displayDialog(context);
}
checkActivationCode(value, token, mobileNo) {
GifLoaderDialogUtils.showMyDialog(context);
final authService = new AuthProvider();
var request = {
"LogInTokenID": token,
"PatientOutSA": countryCode == '966' ? 0 : 1,
"PatientMobileNumber": mobileNo,
"ZipCode": countryCode,
"activationCode": value,
"isRegister": false,
"IsSilentLogin": false
};
authService.forgotPasswordActivation(request, value).then((res) {
if (res is String) {
GifLoaderDialogUtils.hideDialog(con);
Future.delayed(Duration(seconds: 1), () {
AppToast.showErrorToast(message: res);
});
} else {
GifLoaderDialogUtils.hideDialog(con);
Navigator.of(context).pop();
AlertDialogBox(
context: con,
confirmMessage: res['ReturnMessage'],
okText: TranslationBase.of(con).ok,
okFunction: () {
AlertDialogBox.closeAlertDialog(con);
Navigator.of(context).pop();
}).showAlertDialog(context);
}
});
}
}