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.
500 lines
25 KiB
Dart
500 lines
25 KiB
Dart
import 'package:doctor_app_flutter/config/size_config.dart';
|
|
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
|
|
import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart';
|
|
import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart';
|
|
import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart';
|
|
import 'package:doctor_app_flutter/util/helpers.dart';
|
|
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
|
|
import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hexcolor/hexcolor.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../widgets/shared/app_scaffold_widget.dart';
|
|
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
@override
|
|
_LoginScreenState createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
String platformImei;
|
|
|
|
//TODO change AppTextFormField to AppTextFormFieldCustom
|
|
final loginFormKey = GlobalKey<FormState>();
|
|
var projectIdController = TextEditingController();
|
|
List<GetHospitalsResponseModel> projectsList = [];
|
|
FocusNode focusPass = FocusNode();
|
|
FocusNode focusProject = FocusNode();
|
|
AuthenticationViewModel authenticationViewModel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
authenticationViewModel = Provider.of<AuthenticationViewModel>(context);
|
|
return AppScaffold(
|
|
isShowAppBar: false,
|
|
backgroundColor: HexColor('#F8F8F8'),
|
|
body: SafeArea(
|
|
child: ListView(children: <Widget>[
|
|
Container(
|
|
margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 30),
|
|
alignment: Alignment.topLeft,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
//TODO Use App Text rather than text
|
|
Container(
|
|
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start,
|
|
children: <Widget>[
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start,
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: 30,
|
|
),
|
|
],
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start, children: [
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
Text(
|
|
TranslationBase
|
|
.of(context)
|
|
.welcomeTo,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight
|
|
.w600,
|
|
fontFamily: 'Poppins'),
|
|
),
|
|
Text(
|
|
TranslationBase
|
|
.of(context)
|
|
.drSulaimanAlHabib,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight
|
|
.w800,
|
|
fontSize: SizeConfig
|
|
.isMobile
|
|
? 24
|
|
: SizeConfig
|
|
.realScreenWidth *
|
|
0.029,
|
|
fontFamily: 'Poppins'),
|
|
),
|
|
|
|
Text(
|
|
"Doctor App",
|
|
style: TextStyle(
|
|
fontSize:
|
|
SizeConfig.isMobile
|
|
? 16
|
|
: SizeConfig
|
|
.realScreenWidth *
|
|
0.030,
|
|
fontWeight: FontWeight
|
|
.w800,
|
|
color: HexColor(
|
|
'#B8382C')),
|
|
),
|
|
]),
|
|
],
|
|
)),
|
|
SizedBox(
|
|
height: 40,
|
|
),
|
|
Form(
|
|
key: loginFormKey,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment
|
|
.spaceBetween,
|
|
children: <Widget>[
|
|
Container(
|
|
width: SizeConfig
|
|
.realScreenWidth * 0.90,
|
|
height: SizeConfig
|
|
.realScreenHeight * 0.65,
|
|
child:
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start, children: [
|
|
buildSizedBox(),
|
|
Padding(
|
|
child: AppText(
|
|
TranslationBase
|
|
.of(context)
|
|
.enterCredentials,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight
|
|
.bold,
|
|
),
|
|
padding: EdgeInsets.only(
|
|
top: 10, bottom: 10)),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius
|
|
.all(
|
|
Radius.circular(
|
|
6.0)),
|
|
border: Border.all(
|
|
width: 1.0,
|
|
color: HexColor(
|
|
"#CCCCCC"),
|
|
),
|
|
color: Colors.white),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets
|
|
.only(
|
|
left: 10,
|
|
top: 10),
|
|
child: AppText(
|
|
TranslationBase
|
|
.of(context)
|
|
.enterId,
|
|
fontWeight: FontWeight
|
|
.w800,
|
|
fontSize: 14,
|
|
)),
|
|
AppTextFormField(
|
|
labelText: '',
|
|
borderColor: Colors
|
|
.white,
|
|
textInputAction: TextInputAction
|
|
.next,
|
|
|
|
validator: (value) {
|
|
if (value !=
|
|
null && value
|
|
.isEmpty) {
|
|
return TranslationBase
|
|
.of(context)
|
|
.pleaseEnterYourID;
|
|
}
|
|
return null;
|
|
},
|
|
onSaved: (value) {
|
|
if (value !=
|
|
null) setState(() {
|
|
authenticationViewModel.userInfo
|
|
.userID =
|
|
value
|
|
.trim();
|
|
});
|
|
},
|
|
onChanged: (value) {
|
|
if (value != null)
|
|
setState(() {
|
|
authenticationViewModel.userInfo
|
|
.userID =
|
|
value
|
|
.trim();
|
|
});
|
|
},
|
|
onFieldSubmitted: (_) {
|
|
focusPass
|
|
.nextFocus();
|
|
},
|
|
)
|
|
])),
|
|
buildSizedBox(),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius
|
|
.all(
|
|
Radius.circular(
|
|
6.0)),
|
|
border: Border.all(
|
|
width: 1.0,
|
|
color: HexColor(
|
|
"#CCCCCC"),
|
|
),
|
|
color: Colors.white),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets
|
|
.only(
|
|
left: 10,
|
|
top: 10),
|
|
child: AppText(
|
|
TranslationBase
|
|
.of(context)
|
|
.enterPassword,
|
|
fontWeight: FontWeight
|
|
.w800,
|
|
fontSize: 14,
|
|
)),
|
|
AppTextFormField(
|
|
focusNode: focusPass,
|
|
obscureText: true,
|
|
borderColor: Colors
|
|
.white,
|
|
textInputAction: TextInputAction
|
|
.next,
|
|
validator: (value) {
|
|
if (value !=
|
|
null && value
|
|
.isEmpty) {
|
|
return TranslationBase
|
|
.of(context)
|
|
.pleaseEnterPassword;
|
|
}
|
|
return null;
|
|
},
|
|
onSaved: (value) {
|
|
if (value !=
|
|
null)
|
|
setState(() {
|
|
authenticationViewModel.userInfo
|
|
.password =
|
|
value;
|
|
});
|
|
},
|
|
onChanged: (value){
|
|
if (value !=
|
|
null)
|
|
setState(() {
|
|
authenticationViewModel.userInfo
|
|
.password =
|
|
value;
|
|
});
|
|
},
|
|
onFieldSubmitted: (_) {
|
|
focusPass
|
|
.nextFocus();
|
|
Helpers
|
|
.showCupertinoPicker(
|
|
context,
|
|
projectsList,
|
|
'facilityName',
|
|
onSelectProject,
|
|
authenticationViewModel);
|
|
},
|
|
onTap: () {
|
|
this.getProjects(
|
|
authenticationViewModel.userInfo
|
|
.userID);
|
|
},
|
|
)
|
|
])),
|
|
buildSizedBox(),
|
|
projectsList.length > 0
|
|
? Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius
|
|
.all(
|
|
Radius.circular(
|
|
6.0)),
|
|
border: Border.all(
|
|
width: 1.0,
|
|
color: HexColor(
|
|
"#CCCCCC"),
|
|
),
|
|
color: Colors.white),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets
|
|
.only(
|
|
left: 10,
|
|
top: 10),
|
|
child: AppText(
|
|
TranslationBase
|
|
.of(context)
|
|
.selectYourProject,
|
|
fontWeight: FontWeight
|
|
.w600,
|
|
)),
|
|
AppTextFormField(
|
|
focusNode: focusProject,
|
|
controller: projectIdController,
|
|
borderColor: Colors
|
|
.white,
|
|
suffixIcon: Icons
|
|
.arrow_drop_down,
|
|
onTap: () {
|
|
Helpers
|
|
.showCupertinoPicker(
|
|
context,
|
|
projectsList,
|
|
'facilityName',
|
|
onSelectProject,
|
|
authenticationViewModel);
|
|
},
|
|
validator: (value) {
|
|
if (value !=
|
|
null &&
|
|
value
|
|
.isEmpty) {
|
|
return TranslationBase
|
|
.of(
|
|
context)
|
|
.pleaseEnterYourProject;
|
|
}
|
|
return null;
|
|
})
|
|
]))
|
|
: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius
|
|
.all(
|
|
Radius.circular(
|
|
6.0)),
|
|
border: Border.all(
|
|
width: 1.0,
|
|
color: HexColor(
|
|
"#CCCCCC"),
|
|
),
|
|
color: Colors.white),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment
|
|
.start,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets
|
|
.only(
|
|
left: 10,
|
|
top: 10),
|
|
child: AppText(
|
|
TranslationBase
|
|
.of(context)
|
|
.selectYourProject,
|
|
fontWeight: FontWeight
|
|
.w800,
|
|
fontSize: 14,
|
|
)),
|
|
AppTextFormField(
|
|
readOnly: true,
|
|
borderColor: Colors
|
|
.white,
|
|
prefix: IconButton(
|
|
icon: Icon(Icons
|
|
.arrow_drop_down),
|
|
iconSize: 30,
|
|
padding: EdgeInsets
|
|
.only(
|
|
bottom: 30),
|
|
),
|
|
)
|
|
])),
|
|
]),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
)
|
|
]))
|
|
]),
|
|
),
|
|
bottomSheet: Container(
|
|
|
|
height: 90,
|
|
width: double.infinity,
|
|
child: Center(
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
AppButton(
|
|
title: TranslationBase
|
|
.of(context)
|
|
.login,
|
|
color: Color(0xFFD02127),
|
|
disabled: authenticationViewModel.userInfo
|
|
.userID == null ||
|
|
authenticationViewModel.userInfo
|
|
.password ==
|
|
null,
|
|
fontWeight: FontWeight
|
|
.bold,
|
|
onPressed: () {
|
|
login(context);
|
|
},
|
|
),
|
|
|
|
SizedBox(height: 25,)
|
|
],
|
|
),
|
|
),
|
|
),),
|
|
);
|
|
}
|
|
|
|
SizedBox buildSizedBox() {
|
|
return SizedBox(
|
|
height: 20,
|
|
);
|
|
}
|
|
|
|
login(context,) async {
|
|
if (loginFormKey.currentState.validate()) {
|
|
loginFormKey.currentState.save();
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
await authenticationViewModel.login(authenticationViewModel.userInfo);
|
|
if (authenticationViewModel.state == ViewState.ErrorLocal) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
Helpers.showErrorToast(authenticationViewModel.error);
|
|
} else {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
Navigator.of(context).pushReplacement(
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) =>
|
|
VerificationMethodsScreen(
|
|
password: authenticationViewModel.userInfo.password,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
onSelectProject(index) {
|
|
setState(() {
|
|
authenticationViewModel.userInfo.projectID = projectsList[index].facilityId;
|
|
projectIdController.text = projectsList[index].facilityName;
|
|
});
|
|
|
|
primaryFocus.unfocus();
|
|
}
|
|
|
|
getProjects(memberID)async {
|
|
if (memberID != null && memberID != '') {
|
|
if (projectsList.length == 0) {
|
|
await authenticationViewModel.getHospitalsList(memberID);
|
|
if(authenticationViewModel.state == ViewState.Idle) {
|
|
projectsList = authenticationViewModel.hospitals;
|
|
setState(() {
|
|
authenticationViewModel.userInfo.projectID = projectsList[0].facilityId;
|
|
projectIdController.text = projectsList[0].facilityName;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|