added all deliveryboys service

dev
suresh 2 years ago
parent b0be1b56fc
commit f8f13f1433

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:watermanagement/adddeliveryboy.dart';
import 'package:watermanagement/addtankers.dart';
import 'package:watermanagement/getdeliveryboydata.dart';
import 'package:watermanagement/login.dart';
import 'package:watermanagement/place_picker.dart';
import 'package:watermanagement/settings.dart';
@ -355,6 +356,27 @@ 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('All Deliveryboys',style: TextStyle(color:primaryColor)),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => GetDeliveryboyData()),
);
},
),
Divider(
color: Colors.grey,

@ -0,0 +1,263 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:watermanagement/adddeliveryboy.dart';
import 'package:watermanagement/models/getdeliveryboy_model.dart';
import 'package:watermanagement/settings.dart';
class GetDeliveryboyData extends StatefulWidget {
@override
State<GetDeliveryboyData> createState() => _GetDeliveryboyDataState();
}
class _GetDeliveryboyDataState extends State<GetDeliveryboyData> {
List<GetDeliveryboyDetailsModel> modeldeliveryboyList = [];
TextEditingController deliveryboyNameController = TextEditingController();
TextEditingController deliveryboyPhoneController = TextEditingController();
TextEditingController deliveryboyAlterPhoneController = TextEditingController();
TextEditingController deliveryboyAddress = TextEditingController();
bool isLoading=false;
Future<void> readJson() async {
var response1= await AppSettings.getAllDeliverboy();
print(response1);
setState(() {
modeldeliveryboyList =
((jsonDecode(response1)['data']) as List).map((dynamic model) {
return GetDeliveryboyDetailsModel.fromJson(model);
}).toList();
isLoading=false;
});
}
@override
void initState() {
isLoading=true;
readJson();
super.initState();
}
Widget renderzUi(){
if(modeldeliveryboyList.length!=0){
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child:ListView.builder(
padding: EdgeInsets.all(0),
itemCount: modeldeliveryboyList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
color: modeldeliveryboyList[index].cardColor,
child: Padding(
padding:EdgeInsets.all(8) ,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
//width: MediaQuery.of(context).size.width * .55,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('name :',style: labelTextStyle()),
Text('phone :',style: labelTextStyle()),
Text('alternativeContactNumber :',style: labelTextStyle()),
Text('address :',style: labelTextStyle()),
],
),
SizedBox(width: 5,),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(modeldeliveryboyList[index].deliveryboy_name,style: valuesTextStyle()),
Text(modeldeliveryboyList[index].deliveryboy_phone,style: valuesTextStyle()),
Text(modeldeliveryboyList[index].deliveryboy_alternativeContactNumber,style: valuesTextStyle()),
Text(modeldeliveryboyList[index].deliveryboy_address,style: valuesTextStyle(),
overflow: TextOverflow.ellipsis,
maxLines: 1),
],
),
],
),
),
Expanded(child:IconButton(
icon: const Icon(Icons.edit,color: primaryColor,),
onPressed: () {
// showTankerUpdateDialog(modeldeliveryboyList[index]);
},
),),
Expanded(child:IconButton(
icon: const Icon(Icons.delete,color: primaryColor,),
onPressed: () async{
/* showDialog(
//if set to true allow to close popup by tapping out of the popup
//barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Do you want to delete tank?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: ()async {
bool deleteTankStatus = await AppSettings.deleteTanker(modelTanksViewList[index].tanker_name);
if(deleteTankStatus){
readJson();
AppSettings.longSuccessToast('tank deleted successfully');
Navigator.of(context).pop(true);
}
else{
AppSettings.longFailedToast('tank deletion failed');
}
},
child: const Text('Yes',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('No',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
],
),
);
*/
},
),)
],
),
),
);
}) ),
Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async{
Navigator.pop(context);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Deliverboy()),
);
//showBoreAddingDialog();
},
),
/* Padding(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Text(
'Add Tanks ',
style: TextStyle(color: Colors.white),
),
)*/
],
),
),
),
]);
}
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('Click below icon to add new Deliveryboy'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
Navigator.pop(context);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Deliverboy()),
);
},
),
)
],
),
)
);
}
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppSettings.appBar('Deliveryboy'),
body: isLoading?Center(
child: CircularProgressIndicator(
color: primaryColor,
strokeWidth: 5.0,
),
):renderzUi(),
));
}
}

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
class GetDeliveryboyDetailsModel {
String deliveryboy_name = '';
String deliveryboy_phone = '';
String deliveryboy_alternativeContactNumber = '';
String deliveryboy_address='';
Color cardColor=Colors.white;
GetDeliveryboyDetailsModel();
factory GetDeliveryboyDetailsModel.fromJson(Map<String, dynamic> json){
GetDeliveryboyDetailsModel rtvm = new GetDeliveryboyDetailsModel();
rtvm.deliveryboy_name = json['name'] ?? '';
rtvm.deliveryboy_phone = json['phone'] ?? '';
rtvm.deliveryboy_alternativeContactNumber = json['alternativeContactNumber'] ?? '';
rtvm.deliveryboy_address = json['address'] ??'';
return rtvm;
}
}

@ -64,12 +64,12 @@ class AppSettings {
static String accessToken = '';
static String customerId = '';
static String supplierId = '';
static String supplierAddress = '';
static String customerIdsign = '';
static List<String> storedPreferenceValidKeys = ['suppliername', 'access_token'];
static String preloadText = 'Please wait';
static String latitude='';
static String longitude='';
static String supplierAddress = '';
static bool servicestatus = false;
static bool haspermission = false;
static late LocationPermission permission;
@ -85,11 +85,12 @@ class AppSettings {
static String verifyPhnUrl = host+'supplierphone';
static String resetTokenUrl = host+'reset_token';
static String addTankerUrl = host + 'addTankers';
static String UpdateTankerUrl = host + 'updateTankers';
static String getTankersDataUrl = host + 'getTankers';
static String deleteTankerUrl = host + 'deleteTanker';
static String UpdateTankerUrl = host + 'updateTankers';
static String addDeliveryboyUrl = host + 'addDeliveryboys';
static String getAllDeliverboyUrl = host + 'getActiveDeliveryboys';
@ -348,21 +349,21 @@ class AppSettings {
}
}
static Future<bool> updateTanker(tankerName, payload) async {
var uri = Uri.parse(UpdateTankerUrl + '/' + supplierId);
static Future<bool> deleteTanker(tankerName) async {
var uri = Uri.parse(deleteTankerUrl + '/' + supplierId);
uri = uri.replace(query: 'tankerName=$tankerName');
try {
var response = await http.put(uri,
body: json.encode(payload), headers: await buildRequestHeaders());
var response =
await http.put(uri, headers: await buildPutRequestHeaders());
if (response.statusCode == 200) {
return true;
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.put(uri,
body: json.encode(payload), headers: await buildRequestHeaders());
response =
await http.put(uri, headers: await buildPutRequestHeaders());
if (response.statusCode == 200) {
return true;
} else {
@ -380,21 +381,21 @@ class AppSettings {
}
}
static Future<bool> deleteTanker(tankerName) async {
var uri = Uri.parse(deleteTankerUrl + '/' + supplierId);
static Future<bool> updateTanker(tankerName, payload) async {
var uri = Uri.parse(UpdateTankerUrl + '/' + supplierId);
uri = uri.replace(query: 'tankerName=$tankerName');
try {
var response =
await http.put(uri, headers: await buildPutRequestHeaders());
var response = await http.put(uri,
body: json.encode(payload), headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response =
await http.put(uri, headers: await buildPutRequestHeaders());
response = await http.put(uri,
body: json.encode(payload), headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else {
@ -412,6 +413,7 @@ class AppSettings {
}
}
static Future<bool> addDeliverboy(payload) async {
var response = await http.post(Uri.parse(addDeliveryboyUrl + '/' + supplierId),
body: json.encode(payload), headers: await buildRequestHeaders());
@ -444,6 +446,39 @@ class AppSettings {
}
static Future<String> getAllDeliverboy() async {
var response = await http.get(Uri.parse(getAllDeliverboyUrl + '/' + 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(addDeliveryboyUrl + '/' + supplierId),
headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return response.body;
} else {
return "";
}
} else {
return "";
}
} else {
return "";
}
}

Loading…
Cancel
Save