Merge branch 'textfield-validation' into 'development'

Textfield validation

See merge request Cloud_Solution/doctor_app_flutter!470
merge-requests/471/merge
Mohammad Aljammal 5 years ago
commit dccea9a077

@ -843,6 +843,10 @@ const Map<String, Map<String, String>> localizedValues = {
"en": "Step", "en": "Step",
"ar": "خطوة" "ar": "خطوة"
}, },
"fieldRequired": {
"en": "This field is required",
"ar": "هذه الخانة مطلوبه"
},
"applyOrRescheduleLeave": { "applyOrRescheduleLeave": {
"en": "Apply Or Reschedule Leave", "en": "Apply Or Reschedule Leave",
"ar": "التقدم بطلب أو إعادة جدولة الإجازة" "ar": "التقدم بطلب أو إعادة جدولة الإجازة"

@ -39,6 +39,11 @@ class _PatientMakeReferralScreenState extends State<PatientMakeReferralScreen> {
DateTime appointmentDate; DateTime appointmentDate;
final _remarksController = TextEditingController(); final _remarksController = TextEditingController();
String branchError = null;
String hospitalError = null;
String clinicError = null;
String doctorError = null;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -148,6 +153,28 @@ class _PatientMakeReferralScreenState extends State<PatientMakeReferralScreen> {
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
color: HexColor("#359846"), color: HexColor("#359846"),
onPressed: () { onPressed: () {
setState(() {
if(_referTo == null){
branchError = TranslationBase.of(context).fieldRequired;
}else {
branchError = null;
}
if(_selectedBranch == null){
hospitalError = TranslationBase.of(context).fieldRequired;
}else {
hospitalError = null;
}
if(_selectedClinic == null){
clinicError = TranslationBase.of(context).fieldRequired;
}else {
clinicError = null;
}
if(_selectedDoctor == null){
doctorError = TranslationBase.of(context).fieldRequired;
}else {
doctorError = null;
}
});
if (appointmentDate == null || if (appointmentDate == null ||
_selectedBranch == null || _selectedBranch == null ||
_selectedClinic == null || _selectedClinic == null ||
@ -189,6 +216,7 @@ class _PatientMakeReferralScreenState extends State<PatientMakeReferralScreen> {
dropDownText: _referTo != null ? _referTo['name'] : null, dropDownText: _referTo != null ? _referTo['name'] : null,
enabled: false, enabled: false,
isDropDown: true, isDropDown: true,
validationError: branchError,
onClick: referToList != null onClick: referToList != null
? () { ? () {
ListSelectDialog dialog = ListSelectDialog( ListSelectDialog dialog = ListSelectDialog(
@ -241,6 +269,7 @@ class _PatientMakeReferralScreenState extends State<PatientMakeReferralScreen> {
: null, : null,
enabled: false, enabled: false,
isDropDown: true, isDropDown: true,
validationError: hospitalError,
onClick: model.branchesList != null && onClick: model.branchesList != null &&
model.branchesList.length > 0 && model.branchesList.length > 0 &&
_referTo != null && _referTo != null &&
@ -288,6 +317,7 @@ class _PatientMakeReferralScreenState extends State<PatientMakeReferralScreen> {
: null, : null,
enabled: false, enabled: false,
isDropDown: true, isDropDown: true,
validationError: clinicError,
onClick: _selectedBranch != null && onClick: _selectedBranch != null &&
model.clinicsList != null && model.clinicsList != null &&
model.clinicsList.length > 0 model.clinicsList.length > 0
@ -335,6 +365,7 @@ class _PatientMakeReferralScreenState extends State<PatientMakeReferralScreen> {
_selectedDoctor != null ? _selectedDoctor['DoctorName'] : null, _selectedDoctor != null ? _selectedDoctor['DoctorName'] : null,
enabled: false, enabled: false,
isDropDown: true, isDropDown: true,
validationError: doctorError,
onClick: _selectedClinic != null && onClick: _selectedClinic != null &&
model.doctorsList != null && model.doctorsList != null &&
model.doctorsList.length > 0 model.doctorsList.length > 0

@ -1216,7 +1216,7 @@ class TranslationBase {
String get remove => localizedValues['remove'][locale.languageCode]; String get remove => localizedValues['remove'][locale.languageCode];
String get step => localizedValues['step'][locale.languageCode]; String get step => localizedValues['step'][locale.languageCode];
String get fieldRequired => localizedValues['fieldRequired'][locale.languageCode];
String get noSickLeave => localizedValues['no-sickleve'][locale.languageCode]; String get noSickLeave => localizedValues['no-sickleve'][locale.languageCode];
String get changeOfSchedule => String get changeOfSchedule =>
localizedValues['changeOfSchedule'][locale.languageCode]; localizedValues['changeOfSchedule'][locale.languageCode];

@ -1,4 +1,5 @@
import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'app_texts_widget.dart'; import 'app_texts_widget.dart';
@ -19,6 +20,7 @@ class AppTextFieldCustom extends StatefulWidget {
final int maxLines; final int maxLines;
final List<TextInputFormatter> inputFormatters; final List<TextInputFormatter> inputFormatters;
final Function(String) onChanged; final Function(String) onChanged;
final String validationError;
AppTextFieldCustom({ AppTextFieldCustom({
this.height = 0, this.height = 0,
@ -36,6 +38,7 @@ class AppTextFieldCustom extends StatefulWidget {
this.maxLines = 1, this.maxLines = 1,
this.inputFormatters, this.inputFormatters,
this.onChanged, this.onChanged,
this.validationError,
}); });
@override @override
@ -45,12 +48,19 @@ class AppTextFieldCustom extends StatefulWidget {
class _AppTextFieldCustomState extends State<AppTextFieldCustom> { class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Column(
children: [
Container(
height: widget.height != 0 ? widget.height + 8 : null, height: widget.height != 0 ? widget.height + 8 : null,
decoration: widget.hasBorder decoration: widget.hasBorder
? containerBorderDecoration(Color(0Xffffffff), Color(0xFFEFEFEF)) ? containerBorderDecoration(
Color(0Xffffffff),
widget.validationError == null
? Color(0xFFEFEFEF)
: Colors.red.shade700)
: null, : null,
padding: EdgeInsets.only(top: 4.0, bottom: 4.0, left: 8.0, right: 8.0), padding:
EdgeInsets.only(top: 4.0, bottom: 4.0, left: 8.0, right: 8.0),
child: InkWell( child: InkWell(
onTap: widget.onClick ?? null, onTap: widget.onClick ?? null,
child: Row( child: Row(
@ -58,7 +68,9 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
children: [ children: [
Expanded( Expanded(
child: Container( child: Container(
padding: widget.dropDownText == null ? EdgeInsets.symmetric(vertical: 0): EdgeInsets.symmetric(vertical: 8), padding: widget.dropDownText == null
? EdgeInsets.symmetric(vertical: 0)
: EdgeInsets.symmetric(vertical: 8),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -91,11 +103,9 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
? widget.inputFormatters ? widget.inputFormatters
: [], : [],
onChanged: (value) { onChanged: (value) {
if (widget.onChanged != null){ if (widget.onChanged != null) {
widget.onChanged(value); widget.onChanged(value);
setState(() { setState(() {});
});
} }
}, },
) )
@ -122,6 +132,31 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
], ],
), ),
), ),
),
if (widget.validationError != null)
Container(
margin: EdgeInsets.only(top: 8, right: 8, left: 8, bottom: 8),
child: Row(
children: [
Icon(
DoctorApp.warning,
size: 20,
color: Colors.red.shade700,
),
SizedBox(
width: 12,
),
AppText(
widget.validationError,
fontFamily: 'Poppins',
fontSize: SizeConfig.textMultiplier * 1.7,
color: Colors.red.shade700,
fontWeight: FontWeight.w700,
),
],
),
),
],
); );
} }

Loading…
Cancel
Save