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 medicine_name='';
List medImages=[];
//String dropdownType = 'Tank'; //String dropdownType = 'Tank';
Future<void> getSuppliersDataByMedecineName(var MedecineName) async {
Future<void> getAllMedecineData(var medicineName) async {
FilteredList=[]; FilteredList=[];
isMedecineDataLoading = true; isMedecineDataLoading = true;
try { try {
var medecineResponse = await AppSettings.getAllMedecines(MedecineName); var medecineResponse = await AppSettings.getAllMedecines(medicineName);
print(jsonDecode(medecineResponse));
if(jsonDecode(medecineResponse)!=''){
setState(() { setState(() {
medecineList = 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(distance).fromJson(model); return GetMedecineDetailsModel.fromJson(model);
}).toList(); }).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;
} catch (e) {
setState(() {
isMedecineDataLoading = false; isMedecineDataLoading = false;
isSereverIssue = true;
}); });
} }
} else{
Future<void> getAllMedecineData(var distance) async {
FilteredList=[];
isMedecineDataLoading = true;
try {
var medecineResponse = await AppSettings.getAllMedecines();
setState(() { setState(() {
medecineList = medicine_name='';
((jsonDecode(medecineResponse)['medicine']) as List).map((dynamic model) {
return GetMedecineDetailsModel.fromJson(model);
}).toList();
FilteredList=[];
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);
}*/
});
//FilteredList=suppliersList.where((product) => product.address.toString().toUpperCase()=='SUMP').toList();
isMedecineDataLoading = false; 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) {
return GestureDetector(
onTap: () {
// modelBottomSheet(FilteredList[index]);
},
child: Card(
child: Padding(
padding: EdgeInsets.fromLTRB(0,8,0,0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Container( Container(
width: MediaQuery.of(context).size.width * .18, width: MediaQuery.of(context).size.width * .18,
height: height:
MediaQuery.of(context).size.height * .10, MediaQuery.of(context).size.height * .10,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.rectangle,
image: DecorationImage( image: DecorationImage(
image: FilteredList[index].picture=='' image: NetworkImage(medImages[0]) as ImageProvider, // picked file
?AssetImage("images/logo.png")
: NetworkImage(FilteredList[index].picture) as ImageProvider, // picked file
fit: BoxFit.contain)), fit: BoxFit.contain)),
), ),
/*Container( Text(medicine_name),
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,),
],
)
),
),
], ],
), ),
), ),
),
); );
});
} }
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,8 +158,7 @@ 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: [
@ -300,13 +170,14 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
cursorColor: greyColor, cursorColor: greyColor,
controller: searchController, controller: searchController,
keyboardType: TextInputType.number,
onChanged: (string) { onChanged: (string) {
if(string.length>=1){ if(string.length>=4){
getSuppliersDataByPhnNumber(string); getAllMedecineData(searchController.text);
} }
else{ else{
getAllMedecineData(dropdownArea); setState(() {
medicine_name='';
});
} }
}, },
decoration: InputDecoration( decoration: InputDecoration(
@ -314,10 +185,6 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
Icons.search, Icons.search,
color: greyColor, color: greyColor,
), ),
/*suffixIcon: Icon(
Icons.clear,
color: greyColor,
),*/
suffixIcon: IconButton( suffixIcon: IconButton(
icon: Icon( icon: Icon(
Icons.clear, Icons.clear,
@ -326,8 +193,8 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
onPressed: () { onPressed: () {
setState(() { setState(() {
searchController.text=''; searchController.text='';
medicine_name='';
}); });
getAllMedecineData(dropdownArea);
}, },
), ),
border: OutlineInputBorder( border: OutlineInputBorder(
@ -343,7 +210,7 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
borderRadius: BorderRadius.circular(30), borderRadius: BorderRadius.circular(30),
), ),
//labelText: 'Search by phone number', //labelText: 'Search by phone number',
hintText: 'Search phone number', hintText: 'Search by medicine name',
labelStyle: TextStyle( labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE color: greyColor, //<-- SEE HERE
), ),
@ -361,13 +228,11 @@ class _WaterSuppliersState extends State<WaterSuppliers> with TickerProviderStat
strokeWidth: 5.0, strokeWidth: 5.0,
), ),
) )
: _tanker() , : _bindMedicines() ,
)) ))
], ],
), ),
), ),
]),
); );
} }

Loading…
Cancel
Save