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.
126 lines
5.0 KiB
Dart
126 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hexcolor/hexcolor.dart';
|
|
|
|
import '../../../config/config.dart';
|
|
import '../../../core/model/search_drug/get_medication_response_model.dart';
|
|
import '../../../core/viewModel/medicine_view_model.dart';
|
|
import '../../../core/viewModel/prescription/prescription_view_model.dart';
|
|
import '../../../utils/translations_delegate_base_utils.dart';
|
|
import '../../../utils/utils.dart';
|
|
import '../../../widgets/medicine/medicine_item_widget.dart';
|
|
import '../../../widgets/shared/buttons/app_buttons_widget.dart';
|
|
import '../../../widgets/shared/loader/gif_loader_dialog_utils.dart';
|
|
import '../../../widgets/shared/network_base_view.dart';
|
|
import '../../../widgets/shared/text_fields/app_text_form_field.dart';
|
|
import '../../base/base_view.dart';
|
|
|
|
final myController = TextEditingController();
|
|
|
|
class SearchPrescriptionWidget extends StatelessWidget {
|
|
final double? spaceBetweenTextFields;
|
|
final MedicineViewModel? medicineViewModel;
|
|
final PrescriptionViewModel? prescriptionViewModel;
|
|
final Function(GetMedicationResponseModel)? onItemSelected;
|
|
|
|
const SearchPrescriptionWidget({Key? key, this.spaceBetweenTextFields, this.medicineViewModel, this.prescriptionViewModel, this.onItemSelected}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BaseView<MedicineViewModel>(
|
|
onModelReady: (model) async {},
|
|
builder: (
|
|
BuildContext context,
|
|
MedicineViewModel model,
|
|
Widget? child,
|
|
) =>
|
|
NetworkBaseView(
|
|
baseViewModel: model,
|
|
child: Column(
|
|
children: [
|
|
FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: Container(
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(6.0)), border: Border.all(width: 1.0, color: HexColor("#CCCCCC"))),
|
|
padding: EdgeInsets.all(6),
|
|
child: AppTextFormField(
|
|
borderColor: Colors.transparent,
|
|
hintText: TranslationBase.of(context).searchMedicineNameHere,
|
|
controller: myController,
|
|
onSaved: (value) {},
|
|
onFieldSubmitted: (value) {
|
|
searchMedicine(context, model);
|
|
},
|
|
inputFormatter: ONLY_LETTERS,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 15.0,
|
|
),
|
|
Container(
|
|
child: Column(
|
|
children: [
|
|
FractionallySizedBox(
|
|
widthFactor: 0.8,
|
|
child: Container(
|
|
child: Wrap(
|
|
alignment: WrapAlignment.center,
|
|
children: <Widget>[
|
|
AppButton(
|
|
title: TranslationBase.of(context).search,
|
|
onPressed: () async {
|
|
await searchMedicine(
|
|
context,
|
|
model,
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (myController.text != '')
|
|
Container(
|
|
height: MediaQuery.of(context).size.height * 0.5,
|
|
child: ListView.builder(
|
|
padding: const EdgeInsets.only(top: 20),
|
|
scrollDirection: Axis.vertical,
|
|
itemCount: model.allMedicationList == null ? 0 : model.allMedicationList.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return InkWell(
|
|
child: MedicineItemWidget(label: model.allMedicationList[index].description!),
|
|
onTap: () async {
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
await model.getItem(itemID: model.allMedicationList[index].itemId!, isLocalBusy: true);
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
onItemSelected!(model.allMedicationList[index]);
|
|
// uom = _selectedMedication.uom;
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: spaceBetweenTextFields,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
searchMedicine(context, MedicineViewModel model) async {
|
|
FocusScope.of(context).unfocus();
|
|
if (myController.text.length < 3) {
|
|
Utils.showErrorToast(TranslationBase.of(context).moreThan3Letter);
|
|
return;
|
|
}
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
await model.getMedicationList(drug: myController.text, isLocalBusy: true);
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
}
|
|
}
|