diff --git a/lib/dashboard.dart b/lib/dashboard.dart index 327416f..9bd73a8 100644 --- a/lib/dashboard.dart +++ b/lib/dashboard.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:healthcare_pharmacy/getmedicines.dart'; import 'package:healthcare_pharmacy/inactiveoffersview.dart'; import 'package:healthcare_pharmacy/offers.dart'; import 'package:healthcare_pharmacy/offersview.dart'; @@ -621,6 +622,35 @@ class _DashboardState extends State { + }, + ), + 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( diff --git a/lib/getmedicines.dart b/lib/getmedicines.dart index cb2d0bd..bfea93c 100644 --- a/lib/getmedicines.dart +++ b/lib/getmedicines.dart @@ -8,109 +8,61 @@ import 'package:flutter/services.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:cloudinary_public/cloudinary_public.dart'; -class WaterSuppliers extends StatefulWidget { - const WaterSuppliers({Key? key}) : super(key: key); +class GetMedicines extends StatefulWidget { + const GetMedicines({Key? key}) : super(key: key); @override - State createState() => _WaterSuppliersState(); + State createState() => _GetMedicinesState(); } -class _WaterSuppliersState extends State with TickerProviderStateMixin { +class _GetMedicinesState extends State with TickerProviderStateMixin { bool isMedecineDataLoading=false; bool isSereverIssue = false; List medecineList = []; List FilteredList = []; + String userAddress=''; TextEditingController searchController = TextEditingController(); String dropdownArea = '2'; - //String dropdownType = 'Tank'; - - Future 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(); - + String medicine_name=''; + List medImages=[]; - isMedecineDataLoading = false; - - - } catch (e) { - setState(() { - isMedecineDataLoading = false; - isSereverIssue = true; - }); - } - } + //String dropdownType = 'Tank'; - Future getAllMedecineData(var distance) async { + Future getAllMedecineData(var medicineName) async { FilteredList=[]; isMedecineDataLoading = true; try { - var medecineResponse = await AppSettings.getAllMedecines(); - setState(() { - medecineList = + var medecineResponse = await AppSettings.getAllMedecines(medicineName); + + 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) { 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); - }*/ + }).toList();*/ + isMedecineDataLoading = false; }); + } + else{ + setState(() { + medicine_name=''; + isMedecineDataLoading = false; + }); + } - //FilteredList=suppliersList.where((product) => product.address.toString().toUpperCase()=='SUMP').toList(); - - - isMedecineDataLoading = false; - }); } catch (e) { setState(() { + medicine_name=''; isMedecineDataLoading = false; isSereverIssue = true; }); @@ -120,107 +72,34 @@ class _WaterSuppliersState extends State with TickerProviderStat @override void initState() { // TODO: implement initState - //getAllSuppliers(); - getAllMedecineData(dropdownArea); super.initState(); } - Widget _tanker() { - if (FilteredList.length != 0) { - return ListView.builder( - padding: EdgeInsets.all(0), - itemCount: FilteredList.length, - itemBuilder: (BuildContext context, int index) { - return GestureDetector( - onTap: () { - // modelBottomSheet(FilteredList[index]); - }, - child: Card( - child: Padding( - padding: EdgeInsets.fromLTRB(0,8,0,0), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - 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,), - - ], - ) - ), - ), - - - ], - ), - ), + Widget _bindMedicines() { + if (medicine_name!='') { + return Padding(padding: EdgeInsets.all(10), + child: Container( + width: double.infinity, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Container( + width: MediaQuery.of(context).size.width * .18, + height: + MediaQuery.of(context).size.height * .10, + decoration: BoxDecoration( + shape: BoxShape.rectangle, + image: DecorationImage( + image: NetworkImage(medImages[0]) as ImageProvider, // picked file + fit: BoxFit.contain)), ), - ); - }); + Text(medicine_name), + ], + ), + ), + ); } else { return Center( @@ -230,30 +109,22 @@ class _WaterSuppliersState extends State with TickerProviderStat ? Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image( - image: AssetImage('images/serverissue.png'), - // height: MediaQuery.of(context).size.height * .10, - ), SizedBox( height: 20, ), Text( - 'There is an issue at server please try after some time',style:serverIssueTextStyle() ,), + 'No medicine found with your search',style:serverIssueTextStyle() ,), ], ) : userAddress==''?Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - /*Image( - image: AssetImage('images/resourceblue.pngs'), - // height: MediaQuery.of(context).size.height * .10, - ),*/ - Icon(Icons.location_on_outlined,color: primaryColor,size: 40,), + Icon(Icons.search,color: primaryColor,size: 40,), SizedBox( height: 20, ), Text( - 'Please select location to see near by tankers',style:TextStyle( + 'Please enter atleast 4 letters to continue search',style:TextStyle( color: primaryColor, fontWeight: FontWeight.bold, ),), @@ -262,15 +133,15 @@ class _WaterSuppliersState extends State with TickerProviderStat Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image( - image: AssetImage('images/no_data.png'), - // height: MediaQuery.of(context).size.height * .10, + Icon(Icons.dataset_rounded,color: primaryColor,size: 40,), + SizedBox( + height: 20, ), SizedBox( height: 20, ), Text( - 'No Tankers',style:serverIssueTextStyle() ,), + 'No medicine found with your search',style:serverIssueTextStyle() ,), ], ), )); @@ -287,87 +158,81 @@ class _WaterSuppliersState extends State with TickerProviderStat title: Text('Medecine Details'), backgroundColor: primaryColor,), /* body: */ - body: TabBarView(controller: _controller, children: [ - Container( - //color: Colors.purpleAccent, - child:Column( - children: [ - Padding(padding:EdgeInsets.all(10) , - child: Container( - height: MediaQuery.of(context).size.height * .07, - padding: EdgeInsets.all(5), - child: Center(child: TextField( - - cursorColor: greyColor, - controller: searchController, - keyboardType: TextInputType.number, - onChanged: (string) { - if(string.length>=1){ - getSuppliersDataByPhnNumber(string); - } - else{ - getAllMedecineData(dropdownArea); - } - }, - decoration: InputDecoration( - prefixIcon: Icon( - Icons.search, + body: Container( + //color: Colors.purpleAccent, + child:Column( + children: [ + Padding(padding:EdgeInsets.all(10) , + child: Container( + height: MediaQuery.of(context).size.height * .07, + padding: EdgeInsets.all(5), + child: Center(child: TextField( + + cursorColor: greyColor, + controller: searchController, + onChanged: (string) { + if(string.length>=4){ + getAllMedecineData(searchController.text); + } + else{ + setState(() { + medicine_name=''; + }); + } + }, + decoration: InputDecoration( + prefixIcon: Icon( + Icons.search, + color: greyColor, + ), + suffixIcon: IconButton( + icon: Icon( + Icons.clear, color: greyColor, ), - /*suffixIcon: Icon( - Icons.clear, - color: greyColor, - ),*/ - 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 - ), + onPressed: () { + setState(() { + searchController.text=''; + medicine_name=''; + }); + }, ), - ),) - ),), + 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( - child:isMedecineDataLoading - ? Center( - child: CircularProgressIndicator( - color: primaryColor, - strokeWidth: 5.0, - ), - ) - : _tanker() , - )) - ], - ), + Expanded(child: Container( + child:isMedecineDataLoading + ? Center( + child: CircularProgressIndicator( + color: primaryColor, + strokeWidth: 5.0, + ), + ) + : _bindMedicines() , + )) + ], ), - - ]), + ), ); }