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.
179 lines
6.8 KiB
Dart
179 lines
6.8 KiB
Dart
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
import 'package:diplomaticquarterapp/config/size_config.dart';
|
|
import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart';
|
|
import 'package:diplomaticquarterapp/core/service/client/base_app_client.dart';
|
|
import 'package:diplomaticquarterapp/pages/login/login-type.dart';
|
|
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
|
|
import 'package:diplomaticquarterapp/routes.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
|
|
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
|
|
import 'package:diplomaticquarterapp/widgets/card/rounded_container.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/progress_indicator/app_circular_progress_Indeicator.dart';
|
|
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppScaffold(
|
|
appBarTitle: TranslationBase.of(context).login,
|
|
isShowAppBar: true,
|
|
body: isLoading == true
|
|
? AppCircularProgressIndicator()
|
|
: 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.left,
|
|
)),
|
|
Expanded(
|
|
flex: 3,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: <Widget>[
|
|
MobileNo(
|
|
onNumberChange: (value) =>
|
|
{mobileNo = value, validateForm()},
|
|
onCountryChange: (value) => countryCode = value),
|
|
Container(
|
|
child: TextFields(
|
|
controller: nationalIDorFile,
|
|
onChanged: (value) => {validateForm()},
|
|
prefixIcon: Icon(
|
|
loginType == 1
|
|
? Icons.chrome_reader_mode
|
|
: Icons.receipt,
|
|
color: Colors.red),
|
|
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>[
|
|
Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: DefaultButton(
|
|
TranslationBase.of(context).login,
|
|
() => {this.startLogin()},
|
|
color: isButtonDisabled == true
|
|
? Colors.grey
|
|
: Colors.grey[600],
|
|
textColor: Colors.white,
|
|
))
|
|
],
|
|
),
|
|
],
|
|
))
|
|
]),
|
|
)));
|
|
}
|
|
|
|
startLogin() {
|
|
if (isButtonDisabled == false) {
|
|
checkUserAuthentication();
|
|
}
|
|
}
|
|
|
|
void validateForm() {
|
|
if (validateIDBox(nationalIDorFile.text) == true &&
|
|
mobileNo != null &&
|
|
util.isSAUDIIDValid(nationalIDorFile.text) == true) {
|
|
setState(() {
|
|
isButtonDisabled = false;
|
|
});
|
|
} else {
|
|
setState(() {
|
|
isButtonDisabled = true;
|
|
});
|
|
}
|
|
}
|
|
|
|
bool validateIDBox(String value) {
|
|
Pattern pattern = loginIDPattern(); //r'^\d+(?:\.\d+)?$';
|
|
|
|
RegExp regex = new RegExp(pattern);
|
|
return regex.hasMatch(value);
|
|
}
|
|
|
|
String loginIDPattern() {
|
|
var length = loginType == 1 ? 10 : 7;
|
|
return "([0-9]{" + length.toString() + "})";
|
|
}
|
|
|
|
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);
|
|
authService.checkPatientAuthentication(request).then((value) => {
|
|
showLoader(false),
|
|
if (value['isSMSSent'])
|
|
{
|
|
sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']),
|
|
sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request),
|
|
Navigator.of(context).pushNamed(CONFIRM_LOGIN)
|
|
}
|
|
else
|
|
{
|
|
if (value.IsAuthenticated) {this.checkActivationCode()}
|
|
}
|
|
});
|
|
}
|
|
|
|
checkActivationCode() {}
|
|
showLoader(bool isTrue) {
|
|
setState(() {
|
|
isLoading = isTrue;
|
|
});
|
|
}
|
|
}
|