You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
deliveryboy/lib/delivrybookingdata.dart

388 lines
16 KiB

import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:watermanagement/model/getdeliveryboy_model.dart';
import 'package:watermanagement/settings.dart';
class DelivryBookingData extends StatefulWidget {
const DelivryBookingData({Key? key}) : super(key: key);
@override
State<DelivryBookingData> createState() => _DelivryBookingDataState();
}
class _DelivryBookingDataState extends State<DelivryBookingData> with TickerProviderStateMixin {
bool isSupplierDataLoading=false;
bool isSereverIssue = false;
bool isSereverIssueConnected = false;
bool isSereverIssuePending = false;
List<GetDeliveryboyDetailsModel> connectedSuppliersList = [];
bool isLoading=false;
Future<void> getConnectedSuppliersData() async {
isLoading = true;
try {
var response = await AppSettings.getdeliveryboybookings();
setState(() {
connectedSuppliersList =
((jsonDecode(response)['data']) as List).map((dynamic model) {
return GetDeliveryboyDetailsModel.fromJson(model);
}).toList();
isLoading = false;
});
} catch (e) {
setState(() {
isLoading = false;
isSereverIssueConnected = true;
});
}
}
@override
void initState() {
// TODO: implement initState
getConnectedSuppliersData();
super.initState();
}
Widget connectedTankers(){
if (connectedSuppliersList.length != 0) {
return ListView.builder(
padding: EdgeInsets.all(8),
itemCount: connectedSuppliersList.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 * .75,
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('TankerName :',
style: labelTextStyle()),
SizedBox(
width: 5.0,
),
Text(
connectedSuppliersList[index]
.tankerName
.toUpperCase(),
style: valuesTextStyle()),
],
),
Row(
children: [
Text('Bookingid :',
style: labelTextStyle()),
SizedBox(
width: 5.0,
),
Text(
connectedSuppliersList [index]
.bookingid
.toString(),
style: valuesTextStyle()),
],
),
Row(
children: [
Text('SupplierId :',
style: labelTextStyle()),
SizedBox(
width: 5.0,
),
Text(connectedSuppliersList[index].supplierId,
style: valuesTextStyle()),
],
),
Row(
children: [
Text('DateOfOrder :',
style: labelTextStyle()),
SizedBox(
width: 5.0,
),
Text(connectedSuppliersList[index].dateOfOrder,
style: valuesTextStyle()),
],
),
Row(
children: [
Text('Typeofwater :',
style: labelTextStyle()),
SizedBox(
width: 5.0,
),
Text(connectedSuppliersList[index].typeofwater,
style: valuesTextStyle()),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Column(
children: [
IconButton(
iconSize: 30,
icon: const Icon(
Icons.phone,
color: primaryColor,
),
onPressed: () async {
final Uri _phoneUri = Uri(
scheme: "tel",
path: connectedSuppliersList[index]
.delivery_agent_mobile);
try {
await launch(
_phoneUri.toString());
} catch (error) {
throw ("Cannot dial");
}
},
),
Text(
'Call now',
style: iconBelowTextStyle(),
),
],
),
SizedBox(
width: 30,
),
Column(
children: [
IconButton(
iconSize: 30,
icon: const Icon(
Icons.start,
color: primaryColor,
),
onPressed: () {
/* showTankerBookingDialog(
tankersList[index]);*/
},
),
Text(
'Start Trip',
style: iconBelowTextStyle(),
),
],
),
SizedBox(
width: 30,
),
Column(
children: [
IconButton(
iconSize: 30,
icon: Icon(
Icons.download,
color:connectedSuppliersList[index].isStart?Colors.grey: primaryColor,
),
onPressed: () async{
if(connectedSuppliersList[index].isStart){
var payload = new Map<String, dynamic>();
payload["action"] = 'stop';
payload["percentage"] = '';
var capacity = await AppSettings.startAndStop(connectedSuppliersList[index].bookingid,payload);
print(capacity);
//var modelTanksViewList = jsonDecode(capacity)['data'];
setState(() {
connectedSuppliersList[index].isStart=false;
});
}
else{
var payload = new Map<String, dynamic>();
payload["action"] = 'start';
payload["percentage"] = '';
var capacity = await AppSettings.startAndStop(connectedSuppliersList[index].bookingid,payload);
print(capacity);
setState(() {
connectedSuppliersList[index].isStart=true;
});
}
},
),
Text(
'Download Water',
style: iconBelowTextStyle(),
),
],
),
],
)
],
),
),
/* Expanded(
child:TextButton(
child: const Text(
'Connect',
style: TextStyle(fontSize: 15,
decoration: TextDecoration.underline,color: primaryColor),
),
onPressed: () {
},
)),*/
/* Expanded(
child: IconButton(
onPressed: () {
//showTankerUpdateDialog(tankersList[index]);
},
icon: Icon(Icons.edit),
color: primaryColor,
),
),
SizedBox(
width: 5,
),
Expanded(
child: IconButton(
onPressed: () async {
showDialog(
context: context,
builder: (BuildContext context) =>
AlertDialog(
title: const Text(
'Do you want to delete Tanker?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment:
MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: () async {
bool deletePipelineStatus =
await AppSettings.deleteTanker(
tankersList[index]
.tanker_name);
if (deletePipelineStatus) {
getTankers();
AppSettings.longSuccessToast(
'Tanker deleted successfully');
Navigator.of(context).pop(true);
} else {
AppSettings.longFailedToast(
'Tanker deletion failed');
Navigator.of(context).pop(true);
}
},
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,
)),
),
],
),
);
},
icon: Icon(Icons.delete),
color: primaryColor,
),
)*/
],
),
),
);
});
}
else {
return Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
child: isSereverIssueConnected
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
image: AssetImage('images/serverissue.png'),
// height: MediaQuery.of(context).size.height * .10,
),
SizedBox(
height: 20,
),
Text(
'There is an issue at server please try after some time',style:serverIssueTextStyle() ,),
],
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
image: AssetImage('images/no_data.png'),
// height: MediaQuery.of(context).size.height * .10,
),
SizedBox(
height: 20,
),
Text(
'No Connected Tankers',style:serverIssueTextStyle() ,),
],
),
));
}
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppSettings.appBar('Deliveryboy'),
body: isLoading?Center(
child: CircularProgressIndicator(
color: primaryColor,
strokeWidth: 5.0,
),
):connectedTankers(),
));
}
}