diff --git a/lib/dashboard.dart b/lib/dashboard.dart index 403e179..537fed2 100644 --- a/lib/dashboard.dart +++ b/lib/dashboard.dart @@ -1,4 +1,14 @@ +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_deliveryboy/model/getdeliveryboy_model.dart'; +import 'package:watermanagement_deliveryboy/settings.dart'; class Dashboard extends StatefulWidget { const Dashboard({Key? key}) : super(key: key); @@ -7,22 +17,349 @@ class Dashboard extends StatefulWidget { State createState() => _DashboardState(); } -class _DashboardState extends State { +class _DashboardState extends State with TickerProviderStateMixin { + bool isSupplierDataLoading=false; + bool isSereverIssue = false; + bool isSereverIssueConnected = false; + bool isSereverIssuePending = false; + + List connectedSuppliersList = []; + bool isLoading=false; + + Future 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 - Widget build(BuildContext context) { - return Scaffold( - body: Stack( - children: [ - Container( - decoration: const BoxDecoration( - image: DecorationImage(image: AssetImage("images/logo.png"), fit: BoxFit.cover,), + 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: const Icon( + Icons.download, + color: primaryColor, + ), + onPressed: () { + + /* Navigator.push( + context, + new MaterialPageRoute( + builder: (__) => new BookedTanerDetails(myObject:tankersList[index].tanker_name)));*/ + + + }, + ), + 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(), + )); + } +} diff --git a/lib/model/getdeliveryboy_model.dart b/lib/model/getdeliveryboy_model.dart new file mode 100644 index 0000000..7fa1686 --- /dev/null +++ b/lib/model/getdeliveryboy_model.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; + + +class GetDeliveryboyDetailsModel { + String tankerName = ''; + String bookingid = ''; + String supplierId = ''; + String dateOfOrder=''; + String typeofwater=''; + String delivery_agent_mobile=''; + + + + Color cardColor=Colors.white; + + GetDeliveryboyDetailsModel(); + + factory GetDeliveryboyDetailsModel.fromJson(Map json){ + GetDeliveryboyDetailsModel rtvm = new GetDeliveryboyDetailsModel(); + + rtvm.tankerName = json['tankerName'] ?? ''; + rtvm.bookingid = json['bookingid'] ?? ''; + rtvm.supplierId = json['supplierId'] ?? ''; + rtvm.dateOfOrder = json['dateOfOrder'] ??''; + rtvm.typeofwater = json['typeofwater'] ??''; + rtvm.delivery_agent_mobile = json['delivery_agent_mobile'] ??''; + + + + + return rtvm; + } + +} \ No newline at end of file diff --git a/lib/settings.dart b/lib/settings.dart index 58731ca..bb63c59 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -104,6 +104,8 @@ class AppSettings { static String loginUrl = host + 'sendSms'; static String deliveryboyloginUrl = host + 'deliveryboylogin'; + static String deliveryboybookingsUrl = host + 'getdeliveryboybookings'; + static String verifyPhnUrl = host + 'phone'; static String updateProfileUrl = host + 'update/currentUser'; @@ -257,6 +259,37 @@ class AppSettings { } + static Future getdeliveryboybookings() async { + var response = await http.get(Uri.parse(deliveryboybookingsUrl + '/' + phoneNumber), + 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(deliveryboybookingsUrl + '/' + phoneNumber), + headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return response.body; + } else { + return ""; + } + } else { + return ""; + } + } else { + return ""; + } + } + static Future verifyPhn(payload) async { var response = await http.post(Uri.parse(verifyPhnUrl),