import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:healthcare_user/common/settings.dart'; import 'package:healthcare_user/common/zoom_image.dart'; import 'package:healthcare_user/models/get_all_offers_model.dart'; import 'package:healthcare_user/models/get_connected_doctors_model.dart'; import 'package:healthcare_user/models/get_offer_details_model.dart'; import 'package:healthcare_user/my_connections/add-doctor.dart'; import 'package:healthcare_user/orders/cart-items.dart'; import '../models/get_all_quotations.dart'; class AllQuotations extends StatefulWidget { const AllQuotations({Key? key}) : super(key: key); @override State createState() => _AllQuotationsState(); } class _AllQuotationsState extends State with TickerProviderStateMixin { late TabController _controller; bool isDataLoading = false; bool isOffersLoading = false; bool isSereverIssue = false; final List topTabs = [ Tab( child: Text( 'Pending', style: TextStyle(fontSize: 14), )), Tab( child: Text( 'Completed', style: TextStyle(fontSize: 14), )), ]; List quotationsListOriginal = []; List offersListOriginal = []; List offersList = []; List pharmaciesCheckboxes = []; List pharmaciesCheckboxesInDialog = []; List selectedPharmacies = []; @override void initState() { _controller = TabController(vsync: this, length: topTabs.length); getAllQuotations(); super.initState(); } Future getAllQuotations() async { isDataLoading = true; try { var response = await AppSettings.getAllQuotations(); setState(() { quotationsListOriginal = ((jsonDecode(response)['data']) as List).map((dynamic model) { return GetAllQuotationsModel.fromJson(model); }).toList(); quotationsListOriginal = quotationsListOriginal.reversed.toList(); isDataLoading = false; }); } catch (e) { setState(() { isDataLoading = false; isSereverIssue = true; }); } } Future getAllOffers(pharmacyId) async { isOffersLoading = true; try { var response = await AppSettings.getAllOffersUnderPharmacy(pharmacyId); setState(() { offersListOriginal = ((jsonDecode(response)['data']) as List).map((dynamic model) { return GetAllOffersModel.fromJson(model); }).toList(); offersListOriginal = offersListOriginal.reversed.toList(); isOffersLoading = false; }); } catch (e) { setState(() { isOffersLoading = false; isSereverIssue = true; }); } } Widget _pendingQuotations() { if (quotationsListOriginal.length != 0) { return ListView.builder( padding: EdgeInsets.all(0), itemCount: quotationsListOriginal.length, itemBuilder: (BuildContext context, int index) { return GestureDetector( onTap: () async{ Navigator.push( context, MaterialPageRoute( builder: (context) => CartItems(myObject: quotationsListOriginal[index],)), ); }, child: Card( //color: prescriptionsList[index].cardColor, child: Padding( padding: EdgeInsets.all(10), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.end, children: [ Row( children: [ Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Booking Id', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context).size.height * .01, ), Text( 'Pharmacy Name', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context).size.height * .01, ), Text( 'Pharmacy ContactNumber', style: labelTextStyle(), ), ], ), SizedBox( width: MediaQuery.of(context).size.width * .01, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context).size.height * .01, ), Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context).size.height * .01, ), Text( ':', style: labelTextStyle(), ), ], ), SizedBox( width: MediaQuery.of(context).size.width * .01, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( quotationsListOriginal[index] .bookingId .toString() .toUpperCase(), style: valuesTextStyle()), SizedBox( height: MediaQuery.of(context).size.height * .01, ), Text( quotationsListOriginal[index].pharmacyName, style: valuesTextStyle(), ), SizedBox( height: MediaQuery.of(context).size.height * .01, ), Text( quotationsListOriginal[index] .pharmacyContactNumber, style: valuesTextStyle(), ), ], ), ], ), /*ElevatedButton( style: ElevatedButton.styleFrom( primary: buttonColors, // background onPrimary: Colors.black, // foreground ), onPressed: () async { await getAllOffers(quotationsListOriginal[index] .pharmacyId .toString()); showModalBottomSheet( context: context, builder: (BuildContext context) { return SizedBox( child: isOffersLoading ? Center( child: CircularProgressIndicator( color: primaryColor, strokeWidth: 5.0, ), ) : _offersData(), ); }); }, child: Text('Check Offers'), ),*/ ], )), ), ); }); } else { return Center( child: Padding( padding: EdgeInsets.fromLTRB(0, 40, 0, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( height: MediaQuery.of(context).size.height * .25, ), Text('No pending quotations'), SizedBox( height: 20, ), CircleAvatar( backgroundColor: primaryColor, radius: 40, child: IconButton( iconSize: 40, icon: const Icon( Icons.info, color: Colors.white, ), onPressed: () async {}, ), ) ], ), )); } } Widget _offers() { if (offersListOriginal.length != 0) { return ListView.builder( padding: EdgeInsets.all(10), itemCount: offersListOriginal.length, itemBuilder: (BuildContext context, int index) { return GestureDetector( onTap: () {}, child: Card( //color: prescriptionsList[index].cardColor, child: Padding( padding: EdgeInsets.all(10), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.end, children: [ Row( children: [ Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Booking Id', style: labelTextStyle(), ), /* SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( 'Specialization', style: labelTextStyle(), ), SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( 'Qualification', style: labelTextStyle(), ), SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( 'Hospital', style: labelTextStyle(), ),*/ ], ), SizedBox( width: MediaQuery.of(context).size.width * .01, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( ':', style: labelTextStyle(), ), /* SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( ':', style: labelTextStyle(), ), SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( ':', style: labelTextStyle(), ), SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( ':', style: labelTextStyle(), ),*/ ], ), SizedBox( width: MediaQuery.of(context).size.width * .01, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( offersListOriginal[index] .description .toString() .toUpperCase(), style: valuesTextStyle()), /* SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( quotationsListOriginal[index].specialization, style: valuesTextStyle(), ), SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( quotationsListOriginal[index].qualification, style: valuesTextStyle(), ), SizedBox(height:MediaQuery.of(context).size.height * .01,), Text( quotationsListOriginal[index].hospital_name, style: valuesTextStyle(), ),*/ ], ), ], ), ], )), ), ); }); } else { return Center( child: Padding( padding: EdgeInsets.fromLTRB(0, 40, 0, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ SizedBox( height: MediaQuery.of(context).size.height * .25, ), Text('No pending quotations'), SizedBox( height: 20, ), CircleAvatar( backgroundColor: primaryColor, radius: 40, child: IconButton( iconSize: 40, icon: const Icon( Icons.info, color: Colors.white, ), onPressed: () async {}, ), ) ], ), )); } } Widget _offersData() { if (offersListOriginal.length != 0) { return Container( color: Colors.white60, child: Column(crossAxisAlignment: CrossAxisAlignment.end, children: [ Expanded( child: GridView.builder( itemCount: offersListOriginal.length, itemBuilder: (context, index) { return Card( color: Colors.white, elevation: 3.0, child: CheckboxListTile( title: Padding( padding: EdgeInsets.fromLTRB(0, 10, 0, 0), child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Column( children: [ Expanded( child: GestureDetector( onTap: () { Navigator.push( context, new MaterialPageRoute( builder: (__) => new ImageZoomPage( imageName: 'Reports', imageDetails: offersListOriginal[ index] .picture))); }, child: Container( width: MediaQuery.of(context).size.width * .18, height: MediaQuery.of(context).size.height * .10, decoration: BoxDecoration( shape: BoxShape.rectangle, image: DecorationImage( image: offersListOriginal[index] .picture == '' ? AssetImage( "images/logo.png") : NetworkImage( offersListOriginal[ index] .picture) as ImageProvider, // picked file fit: BoxFit.contain)), ), ), ), ], ), SizedBox( width: 5, ), Expanded( child: Container( //width: MediaQuery.of(context).size.width * .70, child: Row( children: [ Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Name', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( 'Code', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( 'Description', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( 'Category', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( 'Start Date', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( 'End Date', style: labelTextStyle(), ), ], ), SizedBox( width: MediaQuery.of(context).size.width * .01, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( ':', style: labelTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( ':', style: labelTextStyle(), ), ], ), SizedBox( width: MediaQuery.of(context).size.width * .01, ), Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( offersListOriginal[index] .name .toString() .toUpperCase(), style: valuesTextStyle()), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( offersListOriginal[index].code, style: valuesTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( offersListOriginal[index].description, style: valuesTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( offersListOriginal[index].category, style: valuesTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( offersListOriginal[index].startDate, style: valuesTextStyle(), ), SizedBox( height: MediaQuery.of(context) .size .height * .01, ), Text( offersListOriginal[index].endDate, style: valuesTextStyle(), ), ], ), ], ), ), ), ], )), checkColor: Colors.white, activeColor: primaryColor, value: offersListOriginal[index].isChecked, onChanged: (val) { setState( () { offersListOriginal[index].isChecked = val!; }, ); /*if (offersListOriginal[index].isChecked) { pharmaciesCheckboxes.add({ 'pharmacyId': offersListOriginal[index].pharmacy_id, }); selectedPharmacies.add(offersListOriginal[index]); } else { pharmaciesCheckboxes.removeWhere((e) => e['pharmacyId'].toString().toUpperCase() == offersListOriginal[index] .pharmacy_id .toString() .toUpperCase()); selectedPharmacies.remove(offersListOriginal[index]); }*/ }, ), ); }, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 1, //.size.width * .33, childAspectRatio: MediaQuery.of(context).size.width / (MediaQuery.of(context).size.height / 5)), ), ), ]), ); } 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(), ), ], ) : Column( mainAxisAlignment: MainAxisAlignment.center, children: [ /*Image( image: AssetImage('images/resourceblue.pngs'), // height: MediaQuery.of(context).size.height * .10, ),*/ Icon( Icons.info, color: primaryColor, size: 40, ), SizedBox( height: 20, ), Text( 'No offers available', style: TextStyle( color: primaryColor, fontWeight: FontWeight.bold, ), ), ], ))); } } Widget _pharmacies() { return Container(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('All Quotations'), backgroundColor: primaryColor, bottom: TabBar( controller: _controller, tabs: topTabs, indicatorColor: buttonColors, unselectedLabelColor: Colors.white60, indicatorWeight: 2, ), ), body: Container( child: TabBarView(controller: _controller, children: [ Padding( padding: EdgeInsets.all(10), child: isDataLoading ? Center( child: CircularProgressIndicator( color: primaryColor, strokeWidth: 5.0, ), ) : _pendingQuotations(), ), Padding( padding: EdgeInsets.all(10), ) ]), ), ); } }