added search medicine functionaliy

dev
Sneha 1 year ago
parent 49439bfafc
commit 26a73149c9

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:healthcare_pharmacy/getmedicines.dart';
import 'package:healthcare_pharmacy/inactiveoffersview.dart'; import 'package:healthcare_pharmacy/inactiveoffersview.dart';
import 'package:healthcare_pharmacy/offers.dart'; import 'package:healthcare_pharmacy/offers.dart';
import 'package:healthcare_pharmacy/offersview.dart'; import 'package:healthcare_pharmacy/offersview.dart';
@ -621,6 +622,35 @@ class _DashboardState extends State<Dashboard> {
},
),
Divider(
color: Colors.grey,
),
ListTile(
title: Row(
children: const [
Image(
image: const AssetImage('images/inactive.png'),
height: 25,
width: 25,
fit: BoxFit.fill),
const SizedBox(
width: 10,
),
Text('Get Medicines', style: TextStyle(color: Colors.black)),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const GetMedicines()),
);
}, },
), ),
Divider( Divider(

@ -8,109 +8,61 @@ import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:cloudinary_public/cloudinary_public.dart'; import 'package:cloudinary_public/cloudinary_public.dart';
class WaterSuppliers extends StatefulWidget { class GetMedicines extends StatefulWidget {
const WaterSuppliers({Key? key}) : super(key: key); const GetMedicines({Key? key}) : super(key: key);
@override @override
State<WaterSuppliers> createState() => _WaterSuppliersState(); State<GetMedicines> createState() => _GetMedicinesState();
} }
class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStateMixin { class _GetMedicinesState extends State<GetMedicines> with TickerProviderStateMixin {
bool isMedecineDataLoading=false; bool isMedecineDataLoading=false;
bool isSereverIssue = false; bool isSereverIssue = false;
List<GetMedecineDetailsModel> medecineList = []; List<GetMedecineDetailsModel> medecineList = [];
List<GetMedecineDetailsModel> FilteredList = []; List<GetMedecineDetailsModel> FilteredList = [];
String userAddress='';
TextEditingController searchController = TextEditingController(); TextEditingController searchController = TextEditingController();
String dropdownArea = '2'; String dropdownArea = '2';
//String dropdownType = 'Tank'; String medicine_name='';
List medImages=[];
Future<void> getSuppliersDataByMedecineName(var MedecineName) async {
FilteredList=[];
isMedecineDataLoading = true;
try {
var medecineResponse = await AppSettings.getAllMedecines(MedecineName);
setState(() {
medecineList =
((jsonDecode(medecineResponse)['medicine']) as List).map((dynamic model) {
return GetMedecineDetailsModel(distance).fromJson(model);
}).toList();
FilteredList= medecineList.where(
(x) => x.name.toLowerCase().contains(MedecineName)
).toList();
//FilteredList=suppliersList.where((product) => product.supplier_phone_number.toString()==phnNum).toList();
});
//FilteredList=suppliersList.where((product) => product.address.toString().toUpperCase()=='SUMP').toList();
isMedecineDataLoading = false; //String dropdownType = 'Tank';
} catch (e) {
setState(() {
isMedecineDataLoading = false;
isSereverIssue = true;
});
}
}
Future<void> getAllMedecineData(var distance) async { Future<void> getAllMedecineData(var medicineName) async {
FilteredList=[]; FilteredList=[];
isMedecineDataLoading = true; isMedecineDataLoading = true;
try { try {
var medecineResponse = await AppSettings.getAllMedecines(); var medecineResponse = await AppSettings.getAllMedecines(medicineName);
setState(() {
medecineList = print(jsonDecode(medecineResponse));
if(jsonDecode(medecineResponse)!=''){
setState(() {
medicine_name=jsonDecode(medecineResponse)['medicine'][0]['name'];
medImages=jsonDecode(medecineResponse)['imageUrls'];
/* medecineList =
((jsonDecode(medecineResponse)['medicine']) as List).map((dynamic model) { ((jsonDecode(medecineResponse)['medicine']) as List).map((dynamic model) {
return GetMedecineDetailsModel.fromJson(model); return GetMedecineDetailsModel.fromJson(model);
}).toList(); }).toList();*/
FilteredList=[]; isMedecineDataLoading = false;
medecineList.forEach((element) async{
var distanceInM;
if(distance=='2'){
distanceInM=2000;
}
else if(distance=='5'){
distanceInM=5000;
}
else if(distance=='10'){
distanceInM=10000;
}
else if(distance=='25'){
distanceInM=25000;
}
else if(distance=='50'){
distanceInM=50000;
}
else if(distance=='100'){
distanceInM=100000;
}
/* double distanceInMeters = await Geolocator.distanceBetween(element.lat,element.lng,lat,lng);
if(distanceInMeters<=distanceInM){
FilteredList.add(element);
}*/
}); });
}
else{
setState(() {
medicine_name='';
isMedecineDataLoading = false;
});
}
//FilteredList=suppliersList.where((product) => product.address.toString().toUpperCase()=='SUMP').toList();
isMedecineDataLoading = false;
});
} catch (e) { } catch (e) {
setState(() { setState(() {
medicine_name='';
isMedecineDataLoading = false; isMedecineDataLoading = false;
isSereverIssue = true; isSereverIssue = true;
}); });
@ -120,107 +72,34 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
@override @override
void initState() { void initState() {
// TODO: implement initState // TODO: implement initState
//getAllSuppliers();
getAllMedecineData(dropdownArea);
super.initState(); super.initState();
} }
Widget _tanker() { Widget _bindMedicines() {
if (FilteredList.length != 0) { if (medicine_name!='') {
return ListView.builder( return Padding(padding: EdgeInsets.all(10),
padding: EdgeInsets.all(0), child: Container(
itemCount: FilteredList.length, width: double.infinity,
itemBuilder: (BuildContext context, int index) { child: Row(
return GestureDetector( crossAxisAlignment: CrossAxisAlignment.start,
onTap: () { mainAxisAlignment: MainAxisAlignment.start,
// modelBottomSheet(FilteredList[index]); children: [
}, Container(
child: Card( width: MediaQuery.of(context).size.width * .18,
child: Padding( height:
padding: EdgeInsets.fromLTRB(0,8,0,0), MediaQuery.of(context).size.height * .10,
child: Row( decoration: BoxDecoration(
mainAxisAlignment: MainAxisAlignment.start, shape: BoxShape.rectangle,
crossAxisAlignment: CrossAxisAlignment.start, image: DecorationImage(
children: [ image: NetworkImage(medImages[0]) as ImageProvider, // picked file
Container( fit: BoxFit.contain)),
width: MediaQuery.of(context).size.width * .18,
height:
MediaQuery.of(context).size.height * .10,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: FilteredList[index].picture==''
?AssetImage("images/logo.png")
: NetworkImage(FilteredList[index].picture) as ImageProvider, // picked file
fit: BoxFit.contain)),
),
/*Container(
width: MediaQuery.of(context).size.width * .15,
height: MediaQuery.of(context).size.height * .10,
child: CircleAvatar(
child:(FilteredList[index].picture)==''
? Image(image: AssetImage("images/logo.png"))
: Image.network('https://storage.googleapis.com/arminta_profile_pictures/photo.jpeg'),
)
),*/
SizedBox(width: 5,),
Expanded(
child: Container(
width: MediaQuery.of(context).size.width * .70,
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
FilteredList[index]
.name
.toUpperCase(),
style: wrapTextStyleBlack()),
SizedBox(height: 10,),
Text(
FilteredList[index]
.manufacturers
.toUpperCase(),
style: wrapTextStyleBlack()),
Visibility(
visible: FilteredList[index].name!='',
child: Text(
FilteredList[index]
.salt_composition
.toUpperCase(),
style: wrapTextStyleBlack()),),
SizedBox(height: 10,),
Text(
FilteredList[index]
.mrp
.toUpperCase(),
style: wrapTextStyleBlack()),
Visibility(
visible: FilteredList[index].primary_use!='',
child: SizedBox(height: 10,),),
Visibility(
visible: FilteredList[index].primary_use!='',
child: Text(
FilteredList[index]
.primary_use
.toUpperCase(),
style: wrapTextStyleBlack()),),
SizedBox(height: 10,),
],
)
),
),
],
),
),
), ),
); Text(medicine_name),
}); ],
),
),
);
} }
else { else {
return Center( return Center(
@ -230,30 +109,22 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
? Column( ? Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Image(
image: AssetImage('images/serverissue.png'),
// height: MediaQuery.of(context).size.height * .10,
),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
Text( Text(
'There is an issue at server please try after some time',style:serverIssueTextStyle() ,), 'No medicine found with your search',style:serverIssueTextStyle() ,),
], ],
) )
: userAddress==''?Column( : userAddress==''?Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
/*Image( Icon(Icons.search,color: primaryColor,size: 40,),
image: AssetImage('images/resourceblue.pngs'),
// height: MediaQuery.of(context).size.height * .10,
),*/
Icon(Icons.location_on_outlined,color: primaryColor,size: 40,),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
Text( Text(
'Please select location to see near by tankers',style:TextStyle( 'Please enter atleast 4 letters to continue search',style:TextStyle(
color: primaryColor, color: primaryColor,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
),), ),),
@ -262,15 +133,15 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
Column( Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Image( Icon(Icons.dataset_rounded,color: primaryColor,size: 40,),
image: AssetImage('images/no_data.png'), SizedBox(
// height: MediaQuery.of(context).size.height * .10, height: 20,
), ),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
Text( Text(
'No Tankers',style:serverIssueTextStyle() ,), 'No medicine found with your search',style:serverIssueTextStyle() ,),
], ],
), ),
)); ));
@ -287,87 +158,81 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
title: Text('Medecine Details'), title: Text('Medecine Details'),
backgroundColor: primaryColor,), backgroundColor: primaryColor,),
/* body: */ /* body: */
body: TabBarView(controller: _controller, children: [ body: Container(
Container( //color: Colors.purpleAccent,
//color: Colors.purpleAccent, child:Column(
child:Column( children: [
children: [ Padding(padding:EdgeInsets.all(10) ,
Padding(padding:EdgeInsets.all(10) , child: Container(
child: Container( height: MediaQuery.of(context).size.height * .07,
height: MediaQuery.of(context).size.height * .07, padding: EdgeInsets.all(5),
padding: EdgeInsets.all(5), child: Center(child: TextField(
child: Center(child: TextField(
cursorColor: greyColor,
cursorColor: greyColor, controller: searchController,
controller: searchController, onChanged: (string) {
keyboardType: TextInputType.number, if(string.length>=4){
onChanged: (string) { getAllMedecineData(searchController.text);
if(string.length>=1){ }
getSuppliersDataByPhnNumber(string); else{
} setState(() {
else{ medicine_name='';
getAllMedecineData(dropdownArea); });
} }
}, },
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: Icon( prefixIcon: Icon(
Icons.search, Icons.search,
color: greyColor,
),
suffixIcon: IconButton(
icon: Icon(
Icons.clear,
color: greyColor, color: greyColor,
), ),
/*suffixIcon: Icon( onPressed: () {
Icons.clear, setState(() {
color: greyColor, searchController.text='';
),*/ medicine_name='';
suffixIcon: IconButton( });
icon: Icon( },
Icons.clear,
color: greyColor,
),
onPressed: () {
setState(() {
searchController.text='';
});
getAllMedecineData(dropdownArea);
},
),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
borderRadius: BorderRadius.circular(30),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
borderRadius: BorderRadius.circular(30),
),
//labelText: 'Search by phone number',
hintText: 'Search phone number',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
), ),
),) border: OutlineInputBorder(
),), borderSide: BorderSide(color: greyColor),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
borderRadius: BorderRadius.circular(30),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
borderRadius: BorderRadius.circular(30),
),
//labelText: 'Search by phone number',
hintText: 'Search by medicine name',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
),)
),),
Expanded(child: Container( Expanded(child: Container(
child:isMedecineDataLoading child:isMedecineDataLoading
? Center( ? Center(
child: CircularProgressIndicator( child: CircularProgressIndicator(
color: primaryColor, color: primaryColor,
strokeWidth: 5.0, strokeWidth: 5.0,
), ),
) )
: _tanker() , : _bindMedicines() ,
)) ))
], ],
),
), ),
),
]),
); );
} }

Loading…
Cancel
Save