refactor code in subjective step2
parent
3e7bf817f3
commit
344ca9c55a
@ -0,0 +1,472 @@
|
||||
// ignore: must_be_immutable
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart';
|
||||
import 'package:doctor_app_flutter/core/model/get_medication_response_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
||||
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
|
||||
import 'package:doctor_app_flutter/screens/base/base_view.dart';
|
||||
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app-textfield-custom.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/dialogs/master_key_dailog.dart';
|
||||
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hexcolor/hexcolor.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../custom_validation_error.dart';
|
||||
import '../bottom_sheet_title.dart';
|
||||
|
||||
class AddMedication extends StatefulWidget {
|
||||
final Function addMedicationFun;
|
||||
TextEditingController medicationController;
|
||||
|
||||
AddMedication({Key key, this.addMedicationFun, this.medicationController})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_AddMedicationState createState() => _AddMedicationState();
|
||||
}
|
||||
|
||||
class _AddMedicationState extends State<AddMedication> {
|
||||
MasterKeyModel _selectedMedicationDose;
|
||||
MasterKeyModel _selectedMedicationStrength;
|
||||
MasterKeyModel _selectedMedicationRoute;
|
||||
MasterKeyModel _selectedMedicationFrequency;
|
||||
|
||||
MasterKeyModel _selectedAllergy;
|
||||
TextEditingController doseController = TextEditingController();
|
||||
TextEditingController strengthController = TextEditingController();
|
||||
TextEditingController routeController = TextEditingController();
|
||||
TextEditingController frequencyController = TextEditingController();
|
||||
GetMedicationResponseModel _selectedMedication;
|
||||
|
||||
GlobalKey key =
|
||||
new GlobalKey<AutoCompleteTextFieldState<GetMedicationResponseModel>>();
|
||||
bool isFormSubmitted = false;
|
||||
|
||||
InputDecoration textFieldSelectorDecoration(
|
||||
String hintText, String selectedText, bool isDropDown,
|
||||
{IconData icon}) {
|
||||
return InputDecoration(
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 0.00),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 0.00),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
disabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 0.00),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
hintText: selectedText != null ? selectedText : hintText,
|
||||
suffixIcon: isDropDown ? Icon(icon ?? Icons.arrow_drop_down) : null,
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Theme
|
||||
.of(context)
|
||||
.hintColor,
|
||||
fontWeight: FontWeight.w700
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ProjectViewModel projectViewModel = Provider.of(context);
|
||||
final screenSize = MediaQuery
|
||||
.of(context)
|
||||
.size;
|
||||
return FractionallySizedBox(
|
||||
child: BaseView<SOAPViewModel>(
|
||||
onModelReady: (model) async {
|
||||
if (model.medicationStrengthList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationStrength,);
|
||||
}
|
||||
if (model.medicationFrequencyList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationFrequency);
|
||||
}
|
||||
if (model.medicationDoseTimeList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationDoseTime);
|
||||
}
|
||||
if (model.medicationRouteList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationRoute);
|
||||
}
|
||||
if (model.allMedicationList.length == 0)
|
||||
await model.getMedicationList();
|
||||
},
|
||||
builder: (_, model, w) =>
|
||||
AppScaffold(
|
||||
baseViewModel: model,
|
||||
isShowAppBar: false,
|
||||
body: Center(
|
||||
child: Container(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
||||
BottomSheetTitle(
|
||||
title: TranslationBase.of(context).addMedication,
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: 0.9,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Container(
|
||||
height: screenSize.height * 0.070,
|
||||
child: InkWell(
|
||||
onTap: model.allMedicationList != null
|
||||
? () {
|
||||
setState(() {
|
||||
_selectedMedication = null;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: _selectedMedication == null
|
||||
? AutoCompleteTextField<
|
||||
GetMedicationResponseModel>(
|
||||
decoration:
|
||||
textFieldSelectorDecoration(
|
||||
|
||||
TranslationBase.of(context)
|
||||
.searchMedicineNameHere,
|
||||
_selectedMedication != null
|
||||
? _selectedMedication
|
||||
.genericName
|
||||
: null,
|
||||
true,
|
||||
icon: EvaIcons.search),
|
||||
itemSubmitted: (item) => setState(
|
||||
() =>
|
||||
_selectedMedication = item),
|
||||
key: key,
|
||||
suggestions:
|
||||
model.allMedicationList,
|
||||
itemBuilder: (context,
|
||||
suggestion) =>
|
||||
new Padding(
|
||||
child: Texts(suggestion
|
||||
.description +
|
||||
'/' +
|
||||
suggestion.genericName),
|
||||
padding:
|
||||
EdgeInsets.all(8.0)),
|
||||
itemSorter: (a, b) => 1,
|
||||
itemFilter: (suggestion, input) =>
|
||||
suggestion.genericName
|
||||
.toLowerCase()
|
||||
.startsWith(
|
||||
input.toLowerCase()) ||
|
||||
suggestion.description
|
||||
.toLowerCase()
|
||||
.startsWith(
|
||||
input.toLowerCase()) ||
|
||||
suggestion.keywords
|
||||
.toLowerCase()
|
||||
.startsWith(
|
||||
input.toLowerCase()),
|
||||
)
|
||||
: AppTextFieldCustom(
|
||||
hintText: _selectedMedication != null
|
||||
? _selectedMedication
|
||||
.description +
|
||||
(' (${_selectedMedication.genericName} )')
|
||||
: TranslationBase.of(context)
|
||||
.searchMedicineNameHere,
|
||||
minLines: 2,
|
||||
maxLines: 2,
|
||||
enabled: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedication == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
enabled: false,
|
||||
onClick: model.medicationDoseTimeList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationDoseTimeList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationDose =
|
||||
selectedValue;
|
||||
|
||||
doseController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationDose
|
||||
.nameAr
|
||||
: _selectedMedicationDose
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText:
|
||||
TranslationBase.of(context).doseTime,
|
||||
//TODO add translation
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
isDropDown: true,
|
||||
controller: doseController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationDose == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
enabled: false,
|
||||
isDropDown: true,
|
||||
onClick: model.medicationStrengthList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationStrengthList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationStrength =
|
||||
selectedValue;
|
||||
|
||||
strengthController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationStrength
|
||||
.nameAr
|
||||
: _selectedMedicationStrength
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText:
|
||||
TranslationBase.of(context).strength,
|
||||
// hintColor: Colors.black,
|
||||
// fontWeight: FontWeight.w600,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: strengthController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationStrength == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
enabled: false,
|
||||
isDropDown: true,
|
||||
onClick: model.medicationRouteList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationRouteList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationRoute =
|
||||
selectedValue;
|
||||
|
||||
routeController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationRoute
|
||||
.nameAr
|
||||
: _selectedMedicationRoute
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText: TranslationBase.of(context).route,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: routeController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationRoute == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
onClick: model.medicationFrequencyList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationFrequencyList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationFrequency =
|
||||
selectedValue;
|
||||
|
||||
frequencyController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationFrequency
|
||||
.nameAr
|
||||
: _selectedMedicationFrequency
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText:
|
||||
TranslationBase.of(context).frequency,
|
||||
//TODO add translation
|
||||
enabled: false,
|
||||
// hintColor: Colors.black,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
isDropDown: true,
|
||||
controller: frequencyController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationFrequency == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
bottomSheet: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
),
|
||||
border: Border.all(color: HexColor('#707070'), width: 0.30),
|
||||
),
|
||||
height: MediaQuery.of(context).size.height * 0.1,
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Container(
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: .80,
|
||||
child: Center(
|
||||
child: AppButton(
|
||||
title: TranslationBase.of(context).addMedication.toUpperCase(),
|
||||
color: Color(0xFF359846),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
isFormSubmitted = true;
|
||||
});
|
||||
if (_selectedMedication != null &&
|
||||
_selectedMedicationDose != null &&
|
||||
_selectedMedicationStrength != null &&
|
||||
_selectedMedicationRoute != null &&
|
||||
_selectedMedicationFrequency != null) {
|
||||
widget.medicationController.text = widget
|
||||
.medicationController.text +
|
||||
'${_selectedMedication.description} (${TranslationBase.of(context).doseTime} ) ${doseController.text} (${TranslationBase.of(context).strength}) ${strengthController.text} (${TranslationBase.of(context).route}) ${routeController.text} (${TranslationBase.of(context).frequency}) ${frequencyController.text} \n \n';
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,118 @@
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:doctor_app_flutter/config/size_config.dart';
|
||||
import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart';
|
||||
import 'package:doctor_app_flutter/core/model/get_medication_response_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
||||
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
|
||||
import 'package:doctor_app_flutter/models/SOAP/my_selected_allergy.dart';
|
||||
import 'package:doctor_app_flutter/screens/base/base_view.dart';
|
||||
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/TextFields.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app-textfield-custom.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/dialogs/master_key_dailog.dart';
|
||||
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:hexcolor/hexcolor.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../custom_validation_error.dart';
|
||||
import '../bottom_sheet_title.dart';
|
||||
import 'add_medication.dart';
|
||||
|
||||
class UpdateMedicationWidget extends StatefulWidget {
|
||||
final TextEditingController medicationController;
|
||||
|
||||
UpdateMedicationWidget({
|
||||
Key key,
|
||||
this.medicationController,
|
||||
});
|
||||
|
||||
@override
|
||||
_UpdateMedicationWidgetState createState() => _UpdateMedicationWidgetState();
|
||||
}
|
||||
|
||||
class _UpdateMedicationWidgetState extends State<UpdateMedicationWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ProjectViewModel projectViewModel = Provider.of(context);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
openMedicationList(context);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 8, horizontal: 8.0),
|
||||
margin:
|
||||
EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade400,
|
||||
width: 0.5),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppText(
|
||||
"${TranslationBase.of(context).addMedication}",
|
||||
fontSize: SizeConfig
|
||||
.textMultiplier *
|
||||
1.8,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
],
|
||||
)),
|
||||
Icon(
|
||||
Icons.add_box_rounded,
|
||||
size: 25,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
openMedicationList(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
backgroundColor: Colors.white,
|
||||
isScrollControlled: true,
|
||||
isDismissible: false,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AddMedication(
|
||||
addMedicationFun: (MySelectedAllergy mySelectedAllergy) {},
|
||||
medicationController: widget.medicationController,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,569 +0,0 @@
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:doctor_app_flutter/config/size_config.dart';
|
||||
import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart';
|
||||
import 'package:doctor_app_flutter/core/model/get_medication_response_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
||||
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
|
||||
import 'package:doctor_app_flutter/models/SOAP/my_selected_allergy.dart';
|
||||
import 'package:doctor_app_flutter/screens/base/base_view.dart';
|
||||
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/TextFields.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app-textfield-custom.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/dialogs/master_key_dailog.dart';
|
||||
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:hexcolor/hexcolor.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../custom_validation_error.dart';
|
||||
import 'bottom_sheet_title.dart';
|
||||
|
||||
class UpdateMedicationWidget extends StatefulWidget {
|
||||
final TextEditingController medicationController;
|
||||
|
||||
UpdateMedicationWidget({
|
||||
Key key,
|
||||
this.medicationController,
|
||||
});
|
||||
|
||||
@override
|
||||
_UpdateMedicationWidgetState createState() => _UpdateMedicationWidgetState();
|
||||
}
|
||||
|
||||
class _UpdateMedicationWidgetState extends State<UpdateMedicationWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ProjectViewModel projectViewModel = Provider.of(context);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
openMedicationList(context);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 8, horizontal: 8.0),
|
||||
margin:
|
||||
EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade400,
|
||||
width: 0.5),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppText(
|
||||
"${TranslationBase.of(context).addMedication}",
|
||||
fontSize: SizeConfig
|
||||
.textMultiplier *
|
||||
1.8,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
],
|
||||
)),
|
||||
Icon(
|
||||
Icons.add_box_rounded,
|
||||
size: 25,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
openMedicationList(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
backgroundColor: Colors.white,
|
||||
isScrollControlled: true,
|
||||
isDismissible: false,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AddMedication(
|
||||
addMedicationFun: (MySelectedAllergy mySelectedAllergy) {},
|
||||
medicationController: widget.medicationController,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class AddMedication extends StatefulWidget {
|
||||
final Function addMedicationFun;
|
||||
TextEditingController medicationController;
|
||||
|
||||
AddMedication({Key key, this.addMedicationFun, this.medicationController})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_AddMedicationState createState() => _AddMedicationState();
|
||||
}
|
||||
|
||||
class _AddMedicationState extends State<AddMedication> {
|
||||
MasterKeyModel _selectedMedicationDose;
|
||||
MasterKeyModel _selectedMedicationStrength;
|
||||
MasterKeyModel _selectedMedicationRoute;
|
||||
MasterKeyModel _selectedMedicationFrequency;
|
||||
|
||||
MasterKeyModel _selectedAllergy;
|
||||
TextEditingController doseController = TextEditingController();
|
||||
TextEditingController strengthController = TextEditingController();
|
||||
TextEditingController routeController = TextEditingController();
|
||||
TextEditingController frequencyController = TextEditingController();
|
||||
GetMedicationResponseModel _selectedMedication;
|
||||
|
||||
GlobalKey key =
|
||||
new GlobalKey<AutoCompleteTextFieldState<GetMedicationResponseModel>>();
|
||||
bool isFormSubmitted = false;
|
||||
|
||||
InputDecoration textFieldSelectorDecoration(
|
||||
String hintText, String selectedText, bool isDropDown,
|
||||
{IconData icon}) {
|
||||
return InputDecoration(
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 0.00),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 0.00),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
disabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey, width: 0.00),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
hintText: selectedText != null ? selectedText : hintText,
|
||||
suffixIcon: isDropDown ? Icon(icon ?? Icons.arrow_drop_down) : null,
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Theme
|
||||
.of(context)
|
||||
.hintColor,
|
||||
fontWeight: FontWeight.w700
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ProjectViewModel projectViewModel = Provider.of(context);
|
||||
final screenSize = MediaQuery
|
||||
.of(context)
|
||||
.size;
|
||||
return FractionallySizedBox(
|
||||
child: BaseView<SOAPViewModel>(
|
||||
onModelReady: (model) async {
|
||||
if (model.medicationStrengthList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationStrength,);
|
||||
}
|
||||
if (model.medicationFrequencyList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationFrequency);
|
||||
}
|
||||
if (model.medicationDoseTimeList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationDoseTime);
|
||||
}
|
||||
if (model.medicationRouteList.length == 0) {
|
||||
await model.getMasterLookup(MasterKeysService.MedicationRoute);
|
||||
}
|
||||
if (model.allMedicationList.length == 0)
|
||||
await model.getMedicationList();
|
||||
},
|
||||
builder: (_, model, w) =>
|
||||
AppScaffold(
|
||||
baseViewModel: model,
|
||||
isShowAppBar: false,
|
||||
body: Center(
|
||||
child: Container(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
||||
BottomSheetTitle(
|
||||
title: TranslationBase.of(context).addMedication,
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: 0.9,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
Container(
|
||||
height: screenSize.height * 0.070,
|
||||
child: InkWell(
|
||||
onTap: model.allMedicationList != null
|
||||
? () {
|
||||
setState(() {
|
||||
_selectedMedication = null;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: _selectedMedication == null
|
||||
? AutoCompleteTextField<
|
||||
GetMedicationResponseModel>(
|
||||
decoration:
|
||||
textFieldSelectorDecoration(
|
||||
|
||||
TranslationBase.of(context)
|
||||
.searchMedicineNameHere,
|
||||
_selectedMedication != null
|
||||
? _selectedMedication
|
||||
.genericName
|
||||
: null,
|
||||
true,
|
||||
icon: EvaIcons.search),
|
||||
itemSubmitted: (item) => setState(
|
||||
() =>
|
||||
_selectedMedication = item),
|
||||
key: key,
|
||||
suggestions:
|
||||
model.allMedicationList,
|
||||
itemBuilder: (context,
|
||||
suggestion) =>
|
||||
new Padding(
|
||||
child: Texts(suggestion
|
||||
.description +
|
||||
'/' +
|
||||
suggestion.genericName),
|
||||
padding:
|
||||
EdgeInsets.all(8.0)),
|
||||
itemSorter: (a, b) => 1,
|
||||
itemFilter: (suggestion, input) =>
|
||||
suggestion.genericName
|
||||
.toLowerCase()
|
||||
.startsWith(
|
||||
input.toLowerCase()) ||
|
||||
suggestion.description
|
||||
.toLowerCase()
|
||||
.startsWith(
|
||||
input.toLowerCase()) ||
|
||||
suggestion.keywords
|
||||
.toLowerCase()
|
||||
.startsWith(
|
||||
input.toLowerCase()),
|
||||
)
|
||||
: AppTextFieldCustom(
|
||||
hintText: _selectedMedication != null
|
||||
? _selectedMedication
|
||||
.description +
|
||||
(' (${_selectedMedication.genericName} )')
|
||||
: TranslationBase.of(context)
|
||||
.searchMedicineNameHere,
|
||||
minLines: 2,
|
||||
maxLines: 2,
|
||||
enabled: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedication == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
enabled: false,
|
||||
onClick: model.medicationDoseTimeList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationDoseTimeList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationDose =
|
||||
selectedValue;
|
||||
|
||||
doseController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationDose
|
||||
.nameAr
|
||||
: _selectedMedicationDose
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText:
|
||||
TranslationBase.of(context).doseTime,
|
||||
//TODO add translation
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
isDropDown: true,
|
||||
controller: doseController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationDose == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
enabled: false,
|
||||
isDropDown: true,
|
||||
onClick: model.medicationStrengthList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationStrengthList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationStrength =
|
||||
selectedValue;
|
||||
|
||||
strengthController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationStrength
|
||||
.nameAr
|
||||
: _selectedMedicationStrength
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText:
|
||||
TranslationBase.of(context).strength,
|
||||
// hintColor: Colors.black,
|
||||
// fontWeight: FontWeight.w600,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: strengthController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationStrength == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
enabled: false,
|
||||
isDropDown: true,
|
||||
onClick: model.medicationRouteList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationRouteList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationRoute =
|
||||
selectedValue;
|
||||
|
||||
routeController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationRoute
|
||||
.nameAr
|
||||
: _selectedMedicationRoute
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText: TranslationBase.of(context).route,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: routeController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationRoute == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
AppTextFieldCustom(
|
||||
onClick: model.medicationFrequencyList != null
|
||||
? () {
|
||||
MasterKeyDailog dialog =
|
||||
MasterKeyDailog(
|
||||
list: model.medicationFrequencyList,
|
||||
okText:
|
||||
TranslationBase.of(context).ok,
|
||||
okFunction: (selectedValue) {
|
||||
setState(() {
|
||||
_selectedMedicationFrequency =
|
||||
selectedValue;
|
||||
|
||||
frequencyController
|
||||
.text = projectViewModel
|
||||
.isArabic
|
||||
? _selectedMedicationFrequency
|
||||
.nameAr
|
||||
: _selectedMedicationFrequency
|
||||
.nameEn;
|
||||
});
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return dialog;
|
||||
},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
hintText:
|
||||
TranslationBase.of(context).frequency,
|
||||
//TODO add translation
|
||||
enabled: false,
|
||||
// hintColor: Colors.black,
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
isDropDown: true,
|
||||
controller: frequencyController,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (isFormSubmitted &&
|
||||
_selectedMedicationFrequency == null)
|
||||
CustomValidationError(),
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
bottomSheet: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
),
|
||||
border: Border.all(color: HexColor('#707070'), width: 0.30),
|
||||
),
|
||||
height: MediaQuery.of(context).size.height * 0.1,
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Container(
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: .80,
|
||||
child: Center(
|
||||
child: AppButton(
|
||||
title: TranslationBase.of(context).addMedication.toUpperCase(),
|
||||
color: Color(0xFF359846),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
isFormSubmitted = true;
|
||||
});
|
||||
if (_selectedMedication != null &&
|
||||
_selectedMedicationDose != null &&
|
||||
_selectedMedicationStrength != null &&
|
||||
_selectedMedicationRoute != null &&
|
||||
_selectedMedicationFrequency != null) {
|
||||
widget.medicationController.text = widget
|
||||
.medicationController.text +
|
||||
'${_selectedMedication.description} (${TranslationBase.of(context).doseTime} ) ${doseController.text} (${TranslationBase.of(context).strength}) ${strengthController.text} (${TranslationBase.of(context).route}) ${routeController.text} (${TranslationBase.of(context).frequency}) ${frequencyController.text} \n \n';
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue