added booking requests screen

dev
Sneha 2 years ago
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(),
));
}
}

@ -15,6 +15,8 @@ import 'dart:io';
import 'package:watermanagement/updateprofile.dart'; import 'package:watermanagement/updateprofile.dart';
import 'booking_requests.dart';
class Dashboard extends StatefulWidget { class Dashboard extends StatefulWidget {
const Dashboard({super.key}); const Dashboard({super.key});
@ -448,6 +450,29 @@ class _DashboardState extends State<Dashboard> {
}, },
), ),
Divider(
color: Colors.grey,
),
// Add Tanks
ListTile(
title: Row(
children: const [
Image(image: const AssetImage('images/ic_launcher.png'),height: 25,width: 25,fit: BoxFit.fill),
const SizedBox(
width: 10,
),
Text('Booking Requests',style: TextStyle(color:primaryColor)),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => BookingRequets()),
);
},
),
Divider( Divider(
color: Colors.grey, color: Colors.grey,
), ),

@ -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;
}
}

@ -95,6 +95,9 @@ class AppSettings {
static String deleteDeliveryboyUrl = host + 'deletedeliveryboy'; static String deleteDeliveryboyUrl = host + 'deletedeliveryboy';
static String pendingCustomersUrl = host + 'pendingCustomers'; static String pendingCustomersUrl = host + 'pendingCustomers';
static String connectedCustomersUrl = host + 'connectedCustomers'; static String connectedCustomersUrl = host + 'connectedCustomers';
static String bookingRequestsUrl = host + 'getAllTankersBookingdetails';
static String acceptBookingRequestsUrl = host + 'ordernow';
String a=""; String a="";
String b=""; String b="";
@ -636,6 +639,68 @@ class AppSettings {
} }
} }
static Future<String> getBookingRequests() async {
var response = await http.get(Uri.parse(bookingRequestsUrl + '/' + supplierId),
headers: await buildRequestHeaders());
if (response.statusCode == 200) {
try {
var _response = json.decode(response.body);
print(_response);
return response.body;
} catch (e) {
// display error toast
return '';
}
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.get(Uri.parse(bookingRequestsUrl + '/' + supplierId),
headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return response.body;
} else {
return "";
}
} else {
return "";
}
} else {
return "";
}
}
static Future<bool> acceptBookingRequests(var bookingId,payload) async {
var response = await http.post(Uri.parse(acceptBookingRequestsUrl + '/' + bookingId),
body: json.encode(payload), headers: await buildRequestHeaders());
if (response.statusCode == 200) {
try {
var _response = json.decode(response.body);
print(_response);
return true;
} catch (e) {
// display error toast
return false;
}
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.post(Uri.parse(acceptBookingRequestsUrl + '/' + bookingId),
body: json.encode(payload), headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
static Future<bool> acceptRequest( payload) async { static Future<bool> acceptRequest( payload) async {
var uri = Uri.parse(acceptRequestUrl ); var uri = Uri.parse(acceptRequestUrl );

Loading…
Cancel
Save