updated the code for request_customers

dev
suresh 2 years ago
parent 45ed63be9c
commit 35c4ea57aa

@ -6,6 +6,7 @@ import 'package:watermanagement/addtankers.dart';
import 'package:watermanagement/getdeliveryboydata.dart';
import 'package:watermanagement/login.dart';
import 'package:watermanagement/place_picker.dart';
import 'package:watermanagement/request_customers.dart';
import 'package:watermanagement/settings.dart';
import 'package:image_picker/image_picker.dart';
import 'package:watermanagement/tankersview.dart';
@ -399,7 +400,28 @@ class _DashboardState extends State<Dashboard> {
);
},
),
Divider(
color: Colors.grey,
),
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('Pending Customers', style: TextStyle(color:primaryColor)),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PendingCustomers()),
);
},
),
Divider(
color: Colors.grey,
),

@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:watermanagement/settings.dart';
class PendingSuppliersModel {
String customer_name = '';
String customer_phone_number='';
String customer_address='';
String customer_id='';
Color text_color=Colors.black;
PendingSuppliersModel();
factory PendingSuppliersModel.fromJson(Map<String, dynamic> json){
PendingSuppliersModel rtvm = new PendingSuppliersModel();
rtvm.customer_name = json['username'] ?? '';
rtvm.customer_phone_number = json['contactNumber'] ?? '';
rtvm.customer_address = json['profile']['address1'] ?? '';
rtvm.customer_id = json['customerId'] ?? '';
return rtvm;
}
}

@ -0,0 +1,237 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:watermanagement/addtankers.dart';
import 'package:watermanagement/models/pending_suppliers_model.dart';
import 'package:watermanagement/settings.dart';
import 'models/tankersview_model.dart';
class PendingCustomers extends StatefulWidget {
@override
State<PendingCustomers> createState() => _PendingCustomersState();
}
class _PendingCustomersState extends State<PendingCustomers> {
TextEditingController tankerNameController = TextEditingController();
TextEditingController tankerPhoneController = TextEditingController();
TextEditingController tankerAlterPhoneController = TextEditingController();
bool isPendingDataLoading=false;
List<PendingSuppliersModel> pendingSuppliersList = [];
bool isSereverIssuePending = false;
bool isLoading=false;
Future<void> getPendingSuppliersData() async {
isPendingDataLoading = true;
try {
var response = await AppSettings.getPendingSuppliers();
setState(() {
pendingSuppliersList =
((jsonDecode(response)['data']) as List).map((dynamic model) {
return PendingSuppliersModel.fromJson(model);
}).toList();
isPendingDataLoading = false;
});
} catch (e) {
setState(() {
isPendingDataLoading = false;
isSereverIssuePending = true;
});
}
}
@override
void initState() {
isLoading=true;
getPendingSuppliersData();
super.initState();
}
Widget renderzUi(){
if(pendingSuppliersList.length!=0){
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child:ListView.builder(
padding: EdgeInsets.all(0),
itemCount: pendingSuppliersList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding:EdgeInsets.all(8) ,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width * .50,
child: Row(
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('username :',
style: labelTextStyle()),
SizedBox(height: 10,),
Text('contactNumber:',
style: labelTextStyle()),
SizedBox(height: 10,),
Text('address1:',
style: labelTextStyle()),
],
),
SizedBox(width: 10,),
Expanded(child:Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
pendingSuppliersList[index]
.customer_name
.toUpperCase(),
style: valuesTextStyle()),
SizedBox(height: 10,),
Text(
pendingSuppliersList[index]
.customer_phone_number
.toUpperCase(),
style: valuesTextStyle()),
SizedBox(height: 10,),
Text(
pendingSuppliersList[index]
.customer_address
.toUpperCase(),
style: valuesTextStyle())
],
),)
],
)
),
TextButton(
child: Text(
'Connect',
style: TextStyle(fontSize: 15,
color:primaryColor/*FilteredList[index].text_color*/ ),
),
onPressed: () async{
/* var payload = new Map<String, dynamic>();
payload["customerId"] =AppSettings.customerId;
payload["supplierId"] = FilteredList[index].supplier_id;
bool requestStatus = await AppSettings.connectRequest(payload);
if(requestStatus){
AppSettings.longSuccessToast("Request Sent Successfully");
await 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["customerId"] =AppSettings.customerId;
payload["supplierId"] = FilteredList[index].supplier_id;
bool requestStatus = await AppSettings.connectRequest(payload);
if(requestStatus){
AppSettings.longSuccessToast("Request Sent Successfully");
await 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('Pending Customers'),
body: isLoading?Center(
child: CircularProgressIndicator(
color: primaryColor,
strokeWidth: 5.0,
),
):renderzUi(),
));
}
}

@ -92,6 +92,8 @@ class AppSettings {
static String getAllDeliverboyUrl = host + 'getActiveDeliveryboys';
static String updateDeliveryboyUrl = host + 'updatedeliveryboy';
static String deleteDeliveryboyUrl = host + 'deletedeliveryboy';
static String pendingCustomersUrl = host + 'pendingCustomers';
@ -465,7 +467,7 @@ class AppSettings {
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.get(Uri.parse(addDeliveryboyUrl + '/' + supplierId),
response = await http.get(Uri.parse(getAllDeliverboyUrl + '/' + supplierId),
headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return response.body;
@ -543,7 +545,36 @@ class AppSettings {
}
static Future<String> getPendingSuppliers() async {
var response = await http.get(Uri.parse(pendingCustomersUrl + '/' + 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(pendingCustomersUrl + '/' + supplierId),
headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return response.body;
} else {
return "";
}
} else {
return "";
}
} else {
return "";
}
}
/*Apis ends here*/

Loading…
Cancel
Save