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.
diplomatic-quarter/lib/pages/pharmacies/medicine_search_screen.dart

146 lines
6.1 KiB
Dart

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/pharmacies_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacies_view_model.dart';
import '../base/base_view.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/input/text_field.dart';
import 'package:diplomaticquarterapp/widgets/buttons/BottomButton.dart';
import 'package:diplomaticquarterapp/widgets/pharmacy/drug_item.dart';
import '../../locator.dart';
import 'package:diplomaticquarterapp/core/service/pharmacies_service.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/pharmacies_list_screen.dart';
class MedicineSearch extends StatefulWidget {
@override
_MedicineSearchState createState() => _MedicineSearchState();
}
class _MedicineSearchState extends State<MedicineSearch> {
final textController = TextEditingController();
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return BaseView<PharmacyViewModel>(
builder: (BuildContext context, PharmacyViewModel model, Widget child) =>
AppScaffold(
baseViewModel: model,
appBarTitle: 'Search Medicine',
body: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
bottom: SizeConfig.heightMultiplier * 1,
right: SizeConfig.heightMultiplier * 2.5,
top: SizeConfig.heightMultiplier * 4,
left: SizeConfig.heightMultiplier * 2.5,
),
child: Form(
key: _formKey,
child: TextFields(
hintText: 'Search Medicine here ',
inputAction: TextInputAction.search,
onSaved: (value) {},
onSubmit: (value) {
searchMedicine(model);
},
controller: textController,
validator: (value) {
if (value.isEmpty) {
return 'please enter medicine name';
}
return null;
},
),
),
),
Container(
margin: EdgeInsets.only(
bottom: SizeConfig.heightMultiplier * 0.0,
right: SizeConfig.heightMultiplier * 5,
top: SizeConfig.heightMultiplier * 1,
left: SizeConfig.heightMultiplier * 5,
),
child: Wrap(
children: <Widget>[
Container(
child: Button(
loading: model.state == ViewState.BusyLocal,
label: 'Search',
onTap: () {
searchMedicine(model);
}),
width: 350.0,
),
],
),
),
Container(
margin:
EdgeInsets.only(left: SizeConfig.heightMultiplier * 2),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Texts(
'You Can Find ' +
'${model.pharmacy == null ? '0' : model.pharmacy.length.toString()}'
' Item In Search ',
),
],
),
),
if (model.state == ViewState.ErrorLocal)
Container(
child: Texts(model.error),
),
Expanded(
child: Container(
width: SizeConfig.screenWidth * 0.85,
//child: _getHospitals(model.pharmacy),
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: model.pharmacy == null
? 0
: model.pharmacy.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
child: MedicineItemWidget(
label: model.pharmacy[index].itemDes,
url: model.pharmacy[index].productImage),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PharmaciesList()),
);
},
);
}),
),
)
],
)),
);
}
searchMedicine(PharmacyViewModel model) {
Utils.hideKeyboard(context);
if (_formKey.currentState.validate())
model.getMedicine2(name: textController.text);
}
Widget _getHospitals(List<PharmaciesModel> hospitals) => ListView.builder(
itemCount: hospitals.length,
itemBuilder: (BuildContext context, int index) => Container(
child: Texts(hospitals[index].itemDes),
),
);
}