import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:watermanagement/settings.dart'; import 'models/booking_requests_model.dart'; class BookingRequets extends StatefulWidget { const BookingRequets({Key? key}) : super(key: key); @override State createState() => _BookingRequetsState(); } class _BookingRequetsState extends State { List BookingRequestsList = []; bool isSereverIssuePending = false; bool isDataLoading = false; Future getBookingRequestsData() async { isDataLoading = true; try { var response = await AppSettings.getBookingRequests(); setState(() { BookingRequestsList = ((jsonDecode(response)['data']) as List).map((dynamic model) { return BookingRequestsModel.fromJson(model); }).toList(); isDataLoading = false; }); } catch (e) { setState(() { isDataLoading = false; isSereverIssuePending = true; }); } } @override void initState() { isDataLoading = true; getBookingRequestsData(); super.initState(); } Widget renderzUi() { if (BookingRequestsList.length != 0) { return Column(crossAxisAlignment: CrossAxisAlignment.end, children: [ Expanded( child: ListView.builder( padding: EdgeInsets.all(0), itemCount: BookingRequestsList.length, itemBuilder: (BuildContext context, int index) { return Card( child: Padding( padding: EdgeInsets.all(8), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Container( width: MediaQuery.of(context).size.width * .70, child: Row( children: [ Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Tanker Name:', style: labelTextStyle()), SizedBox( height: 10, ), Text('CustomerId:', style: labelTextStyle()), SizedBox( height: 10, ), Text('BookingId:', style: labelTextStyle()), SizedBox( height: 10, ), Text('Type Of Water:', style: labelTextStyle()), SizedBox( height: 10, ), Text('Capacity:', style: labelTextStyle()), SizedBox( height: 10, ), Text('Price:', style: labelTextStyle()), SizedBox( height: 10, ), Text('Payment Status:', style: labelTextStyle()), SizedBox( height: 10, ), Text('Order Status:', style: labelTextStyle()), SizedBox( height: 10, ), Text('Address:', style: labelTextStyle()), ], ), SizedBox( width: 10, ), Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( BookingRequestsList[index] .tanker_name .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .customer_id .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .booking_id .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .type_of_water .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .capacity .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .price .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .payment_status .toUpperCase(), style: valuesTextStyle()), SizedBox( height: 10, ), Text( BookingRequestsList[index] .orderStatus .toUpperCase(), style: TextStyle(fontSize: 12,fontWeight: FontWeight.bold,color:BookingRequestsList[index].textColor )), SizedBox( height: 10, ), Container( width: MediaQuery.of(context).size.width * .50, child: Text( BookingRequestsList[index] .customer_address .toUpperCase(), style: valuesTextStyle()), ) ], ), ], )), ), /*Row( children: [ Text('Tanker Name:', style: labelTextStyle()), Text( BookingRequestsList[index] .tanker_name .toUpperCase(), style: valuesTextStyle()), ], ),*/ Visibility( visible:BookingRequestsList[index].orderStatus.toString().toLowerCase()=='pending', child: Column( children: [ TextButton( child: Text( 'Accept', style: TextStyle( fontSize: 15, color: primaryColor /*FilteredList[index].text_color*/), ), onPressed: () async { var payload = new Map(); payload["supplierName"] = AppSettings.suppliername; payload["supplierId"] = AppSettings.supplierId; payload["customerId"] = BookingRequestsList[index].customer_id; payload["capacity"] = BookingRequestsList[index].capacity; payload["customer_address"] = BookingRequestsList[index] .customer_address; payload["dateOfOrder"] = BookingRequestsList[index].date_of_order; payload["action"] = "accept"; payload["price"] = BookingRequestsList[index].price; payload["delivery_agent"] = ''; payload["agent_mobile"] = ''; payload["agent_alternative_mobile"] = ''; bool requestStatus = await AppSettings.acceptBookingRequests( BookingRequestsList[index].booking_id, payload); if (requestStatus) { AppSettings.longSuccessToast( "Booking Accepted"); await getBookingRequestsData(); // getAllSuppliersData(); //await getConnectedSuppliersData(); //await getPendingSuppliersData(); } else {} }, ), TextButton( child: Text( 'Reject', style: TextStyle( fontSize: 15, color: primaryColor /*FilteredList[index].text_color*/), ), onPressed: () async { var payload = new Map(); payload["supplierName"] = AppSettings.suppliername; payload["supplierId"] = AppSettings.supplierId; payload["customerId"] = BookingRequestsList[index].customer_id; payload["capacity"] = BookingRequestsList[index].capacity; payload["customer_address"] = BookingRequestsList[index] .customer_address; payload["dateOfOrder"] = BookingRequestsList[index].date_of_order; payload["action"] = "reject"; payload["price"] = BookingRequestsList[index].price; payload["delivery_agent"] = ''; payload["agent_mobile"] = ''; payload["agent_alternative_mobile"] = ''; bool requestStatus = await AppSettings.acceptBookingRequests( BookingRequestsList[index].booking_id, payload); if (requestStatus) { AppSettings.longSuccessToast( "Booking Rejected"); await getBookingRequestsData(); // getAllSuppliersData(); //await getConnectedSuppliersData(); //await getPendingSuppliersData(); } else {} }, ), ], )) ], ), ), ); })), ]); } 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 Data Found'), SizedBox( height: 20, ), ], ), )); } } @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( appBar: AppSettings.appBar('Booking Requests'), body: isDataLoading ? Center( child: CircularProgressIndicator( color: primaryColor, strokeWidth: 5.0, ), ) : renderzUi(), )); } }