fix login

merge-requests/709/head
Elham Rababah 5 years ago
parent 362d9425cd
commit 8f6de2e02b

@ -13,7 +13,6 @@ import 'package:provider/provider.dart';
import '../../widgets/shared/app_scaffold_widget.dart'; import '../../widgets/shared/app_scaffold_widget.dart';
class LoginScreen extends StatefulWidget { class LoginScreen extends StatefulWidget {
@override @override
_LoginScreenState createState() => _LoginScreenState(); _LoginScreenState createState() => _LoginScreenState();
@ -35,6 +34,7 @@ class _LoginScreenState extends State<LoginScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
authenticationViewModel = Provider.of<AuthenticationViewModel>(context); authenticationViewModel = Provider.of<AuthenticationViewModel>(context);
double textFieldHeight = SizeConfig.heightMultiplier * (SizeConfig.isHeightShort ?10:6);
return AppScaffold( return AppScaffold(
isShowAppBar: false, isShowAppBar: false,
backgroundColor: HexColor('#F8F8F8'), backgroundColor: HexColor('#F8F8F8'),
@ -49,124 +49,100 @@ class _LoginScreenState extends State<LoginScreen> {
//TODO Use App Text rather than text //TODO Use App Text rather than text
Container( Container(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.start,
.start, children: [
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment
.start,
children: <Widget>[
SizedBox(
height: 30,
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment
.start, children: [
SizedBox( SizedBox(
height: 10, height: 10,
), ),
Text( Text(
TranslationBase TranslationBase.of(context).welcomeTo,
.of(context)
.welcomeTo,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: SizeConfig
fontWeight: FontWeight .getTextMultiplierBasedOnWidth() *
.w600, 4,
fontWeight: FontWeight.w600,
fontFamily: 'Poppins'), fontFamily: 'Poppins'),
), ),
Text( Text(
TranslationBase TranslationBase.of(context).drSulaimanAlHabib,
.of(context)
.drSulaimanAlHabib,
style: TextStyle( style: TextStyle(
color: Color(0xFF2B353E), color: Color(0xFF2B353E),
fontWeight: FontWeight fontWeight: FontWeight.bold,
.bold, fontSize: SizeConfig
fontSize: 24, .getTextMultiplierBasedOnWidth() *
6,
fontFamily: 'Poppins'), fontFamily: 'Poppins'),
), ),
Text( Text(
"Doctor App", "Doctor App",
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: SizeConfig
fontWeight: FontWeight .getTextMultiplierBasedOnWidth() *
.w600, 4,
fontWeight: FontWeight.w600,
color: Color(0xFFD02127)), color: Color(0xFFD02127)),
), ),
]), ])),
],
)),
SizedBox( SizedBox(
height: 40, height: 40,
), ),
Form( Form(
key: loginFormKey, key: loginFormKey,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment crossAxisAlignment: CrossAxisAlignment.start,
.start, children: [ children: [
buildSizedBox(),
buildSizedBox(), AppTextFieldCustom(
AppTextFieldCustom( height: textFieldHeight,
hintText: TranslationBase.of(context).enterId, hintText: TranslationBase.of(context).enterId,
hasBorder: true, hasBorder: true,
controller: userIdController, controller: userIdController,
onChanged: (value){ onChanged: (value) {
if (value != null) if (value != null)
setState(() { setState(() {
authenticationViewModel.userInfo authenticationViewModel.userInfo.userID =
.userID = value.trim();
value });
.trim(); },
}); ),
}, buildSizedBox(),
), AppTextFieldCustom(
buildSizedBox(), height: textFieldHeight,
AppTextFieldCustom( hintText: TranslationBase.of(context).enterPassword,
hintText: TranslationBase.of(context).enterPassword, hasBorder: true,
hasBorder: true, isSecure: true,
isSecure: true, controller: passwordController,
controller: passwordController, onChanged: (value) {
onChanged: (value){ if (value != null)
if (value != null) setState(() {
setState(() { authenticationViewModel.userInfo.password =
authenticationViewModel.userInfo value.trim();
.password = });
value this.getProjects(
.trim(); authenticationViewModel.userInfo.userID);
}); },
this.getProjects( onClick: () {},
authenticationViewModel.userInfo ),
.userID); buildSizedBox(),
}, AppTextFieldCustom(
onClick: (){ height: textFieldHeight,
hintText:
}, TranslationBase.of(context).selectYourProject,
), hasBorder: true,
buildSizedBox(), controller: projectIdController,
AppTextFieldCustom( isTextFieldHasSuffix: true,
hintText: TranslationBase.of(context).selectYourProject, enabled: false,
hasBorder: true, onClick: projectsList.isEmpty== null ? null:() {
controller: projectIdController, Helpers.showCupertinoPicker(
isTextFieldHasSuffix: true, context,
enabled: false, projectsList,
onClick: (){ 'facilityName',
Helpers onSelectProject,
.showCupertinoPicker( authenticationViewModel);
context, },
projectsList, ),
'facilityName', buildSizedBox(),
onSelectProject, ]),
authenticationViewModel);
},
),
buildSizedBox(),
]),
), ),
SizedBox( SizedBox(
height: 40, height: 40,
@ -176,46 +152,47 @@ class _LoginScreenState extends State<LoginScreen> {
), ),
), ),
bottomSheet: Container( bottomSheet: Container(
// color: Colors.green,
height: 85, height: SizeConfig.heightMultiplier * 10,
width: double.infinity, width: double.infinity,
child: Center( child: Center(
child: FractionallySizedBox( child: FractionallySizedBox(
widthFactor: 0.9, widthFactor: 0.9,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
AppButton( AppButton(
title: TranslationBase height: SizeConfig.heightMultiplier *
.of(context) (SizeConfig.isHeightShort ? 8 : 6),
.login, hPadding: 1,
title: TranslationBase.of(context).login,
color: Color(0xFFD02127), color: Color(0xFFD02127),
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
disabled: authenticationViewModel.userInfo disabled: authenticationViewModel.userInfo.userID == null ||
.userID == null || authenticationViewModel.userInfo.password == null,
authenticationViewModel.userInfo
.password ==
null,
onPressed: () { onPressed: () {
login(context); login(context);
}, },
), ),
SizedBox(height: 25,) // SizedBox(height: SizeConfig.heightMultiplier * (SizeConfig.isHeightShort? 1 : 3),)
], ],
), ),
), ),
),), ),
),
); );
} }
SizedBox buildSizedBox() { SizedBox buildSizedBox() {
return SizedBox( return SizedBox(
height: 20, height: SizeConfig.heightMultiplier * 2,
); );
} }
login(context,) async { login(
context,
) async {
if (loginFormKey.currentState.validate()) { if (loginFormKey.currentState.validate()) {
loginFormKey.currentState.save(); loginFormKey.currentState.save();
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
@ -225,29 +202,32 @@ class _LoginScreenState extends State<LoginScreen> {
Helpers.showErrorToast(authenticationViewModel.error); Helpers.showErrorToast(authenticationViewModel.error);
} else { } else {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
authenticationViewModel.setUnverified(true,isFromLogin: true); authenticationViewModel.setUnverified(true, isFromLogin: true);
} }
} }
} }
onSelectProject(index) { onSelectProject(index) {
setState(() { setState(() {
authenticationViewModel.userInfo.projectID = projectsList[index].facilityId; authenticationViewModel.userInfo.projectID =
projectsList[index].facilityId;
projectIdController.text = projectsList[index].facilityName; projectIdController.text = projectsList[index].facilityName;
}); });
primaryFocus.unfocus(); primaryFocus.unfocus();
} }
String memberID ="";
getProjects(memberID)async { String memberID = "";
getProjects(memberID) async {
if (memberID != null && memberID != '') { if (memberID != null && memberID != '') {
if (this.memberID !=memberID) { if (this.memberID != memberID) {
this.memberID = memberID; this.memberID = memberID;
await authenticationViewModel.getHospitalsList(memberID); await authenticationViewModel.getHospitalsList(memberID);
if(authenticationViewModel.state == ViewState.Idle) { if (authenticationViewModel.state == ViewState.Idle) {
projectsList = authenticationViewModel.hospitals; projectsList = authenticationViewModel.hospitals;
setState(() { setState(() {
authenticationViewModel.userInfo.projectID = projectsList[0].facilityId; authenticationViewModel.userInfo.projectID =
projectsList[0].facilityId;
projectIdController.text = projectsList[0].facilityName; projectIdController.text = projectsList[0].facilityName;
}); });
} }

Loading…
Cancel
Save