import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; import 'package:healthcare_pharmacy/models/medicineview_model.dart'; import 'package:healthcare_pharmacy/settings.dart'; 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); @override State createState() => _WaterSuppliersState(); } class _WaterSuppliersState extends State with TickerProviderStateMixin { bool isMedecineDataLoading=false; bool isSereverIssue = false; List medecineList = []; List FilteredList = []; 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(); isMedecineDataLoading = false; } catch (e) { setState(() { isMedecineDataLoading = false; isSereverIssue = true; }); } } Future getAllMedecineData(var distance) async { FilteredList=[]; isMedecineDataLoading = true; try { var medecineResponse = await AppSettings.getAllMedecines(); setState(() { 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); }*/ }); //FilteredList=suppliersList.where((product) => product.address.toString().toUpperCase()=='SUMP').toList(); isMedecineDataLoading = false; }); } catch (e) { setState(() { isMedecineDataLoading = false; isSereverIssue = true; }); } } @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,), ], ) ), ), ], ), ), ), ); }); } else { return Center( child: Padding( padding: EdgeInsets.fromLTRB(0, 40, 0, 0), child: isSereverIssue ? 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() ,), ], ) : 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,), SizedBox( height: 20, ), Text( 'Please select location to see near by tankers',style:TextStyle( color: primaryColor, fontWeight: FontWeight.bold, ),), ], ): Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image( image: AssetImage('images/no_data.png'), // height: MediaQuery.of(context).size.height * .10, ), SizedBox( height: 20, ), Text( 'No Tankers',style:serverIssueTextStyle() ,), ], ), )); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( 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, 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 ), ), ),) ),), Expanded(child: Container( child:isMedecineDataLoading ? Center( child: CircularProgressIndicator( color: primaryColor, strokeWidth: 5.0, ), ) : _tanker() , )) ], ), ), ]), ); } }