parent
299dafd5a1
commit
3d687526ad
@ -0,0 +1,339 @@
|
||||
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<BookingRequets> createState() => _BookingRequetsState();
|
||||
}
|
||||
|
||||
class _BookingRequetsState extends State<BookingRequets> {
|
||||
List<BookingRequestsModel> BookingRequestsList = [];
|
||||
bool isSereverIssuePending = false;
|
||||
bool isDataLoading = false;
|
||||
|
||||
Future<void> 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,
|
||||
),
|
||||
Text(
|
||||
BookingRequestsList[index]
|
||||
.customer_address
|
||||
.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<String, dynamic>();
|
||||
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<String, dynamic>();
|
||||
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(),
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:watermanagement/settings.dart';
|
||||
|
||||
|
||||
class BookingRequestsModel {
|
||||
String tanker_name = '';
|
||||
String customer_address = '';
|
||||
String customer_id = '';
|
||||
String booking_id='';
|
||||
String date_of_order='';
|
||||
String type_of_water='';
|
||||
String capacity='';
|
||||
String price='';
|
||||
String payment_status='';
|
||||
String orderStatus='';
|
||||
|
||||
|
||||
Color textColor=Colors.black;
|
||||
|
||||
BookingRequestsModel();
|
||||
|
||||
factory BookingRequestsModel.fromJson(Map<String, dynamic> json){
|
||||
BookingRequestsModel rtvm = new BookingRequestsModel();
|
||||
|
||||
rtvm.tanker_name = json['tankerName'] ?? '';
|
||||
rtvm.customer_address = json['address'] ?? '';
|
||||
rtvm.customer_id = json['customerId'] ?? '';
|
||||
rtvm.booking_id = json['bookingid'] ?? '';
|
||||
rtvm.type_of_water = json['dateOfOrder'] ?? '';
|
||||
rtvm.capacity = json['capacity'] ?? '';
|
||||
rtvm.price = json['price'] ?? '';
|
||||
rtvm.payment_status = json['payment_status'] ?? '';
|
||||
rtvm.orderStatus = json['orderStatus'] ?? '';
|
||||
|
||||
if(rtvm.orderStatus.toString().toLowerCase()=='accepted'){
|
||||
rtvm.textColor=Colors.green;
|
||||
}
|
||||
else if(rtvm.orderStatus.toString().toLowerCase()=='rejected'){
|
||||
rtvm.textColor=Colors.red;
|
||||
}
|
||||
else{
|
||||
rtvm.textColor=primaryColor;
|
||||
}
|
||||
|
||||
|
||||
return rtvm;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue