import 'dart:io'; import 'dart:typed_data'; import 'package:bookatanker/common/preloader.dart'; import 'package:flutter/material.dart'; import 'dart:convert'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:http/http.dart' as http; import 'package:fluttertoast/fluttertoast.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:intl/intl.dart'; import 'dart:async'; import 'package:geolocator/geolocator.dart'; import 'package:dio/dio.dart'; //const Color primaryColor = Color(0XFF0D4E84); //const Color primaryColor = Color(0XFF075A7C); const Color primaryColor = Color(0XFF1D7AFC); const Color tankLocationColor = Color(0XFFF3E998); const Color typeOfWaterColor = Color(0XFFCE93D8); const Color newTextColor = Color(0XFF424242); const Color secondaryColor = Color(0XFFBFE0ED); const Color greyColor = Color(0XFF7E7F80); const Color textFieldStartColor = Colors.grey; const Color screenBackgroundColor = Color(0XFFBFE0ED); const Color screenBackgroundColord = Colors.black12; const Color dashboardbackground = Color(0XFFF5F5F5); Color AppBarGradient_1 = Color(0XFF4D317D); String capitalizeFirstLetter(String text) { if (text.isEmpty) return text; return text[0].toUpperCase() + text.substring(1).toLowerCase(); } TextStyle PreloaderText() { return TextStyle(color:primaryColor); } TextStyle labelTextStyle() { return TextStyle(color: primaryColor, fontSize: 12,fontWeight: FontWeight.bold); } TextStyle newTextStyle() { return TextStyle(color:newTextColor,fontWeight: FontWeight.bold ); } TextStyle labelTextStyleRed() { return TextStyle(color: Colors.red, fontSize: 12,fontWeight: FontWeight.bold); } TextStyle labelTextStyleMotorRunning() { return TextStyle(color: primaryColor, fontSize: 16); } TextStyle labelTextStylewithBold() { return TextStyle(color: primaryColor, fontSize: 12,fontWeight: FontWeight.bold); } TextStyle haveMotorTextStyle() { return TextStyle( color: Colors.red, fontSize: 12, fontWeight: FontWeight.bold); } TextStyle textButtonStyle() { return TextStyle(color: primaryColor, fontSize: 15); } TextStyle iconBelowTextStyle() { return TextStyle(fontSize: 10, color: primaryColor); } TextStyle valuesTextStyle() { return TextStyle( fontSize: 12, color: Colors.black, fontWeight: FontWeight.bold, ); } TextStyle valuesTextStyleConsumption() { return TextStyle( fontSize: 12, color: Colors.red, fontWeight: FontWeight.bold, ); } TextStyle valuesTextStyleCapacity() { return TextStyle( fontSize: 14, color: Colors.red, fontWeight: FontWeight.bold, ); } TextStyle valuesTextStyleRed() { return TextStyle( fontSize: 12, color: Colors.red, fontWeight: FontWeight.bold, ); } TextStyle valuesTextStyleBig() { return TextStyle( fontSize: 15, fontWeight: FontWeight.bold, ); } TextStyle valuesTextStyleBigImportant() { return TextStyle( fontSize: 15, fontWeight: FontWeight.bold, color: Colors.red ); } TextStyle valuesTextStyleImportant() { return TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: Colors.red ); } TextStyle valuesTextStyleImportantMotorRunning() { return TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red ); } TextStyle valuesTextStyleForDisplayLastUpdatedTime() { return TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: primaryColor ); } TextStyle valuesTextStyleForOrders() { return TextStyle( fontSize: 14, fontWeight: FontWeight.bold, color: primaryColor ); } TextStyle lablesTextStyleForOrders() { return TextStyle( fontSize: 14, ); } TextStyle tabTextStyle() { return TextStyle( fontSize: 12, ); } TextStyle valuesTextStyleWithoutTextSize() { return TextStyle( fontWeight: FontWeight.bold, ); } TextStyle startAndStopHeading() { return TextStyle( fontSize: 14, fontWeight: FontWeight.bold, color: primaryColor, ); } Text capacitySuffixText() { return Text('in Ltrs.'); } Text dimensionSuffixText() { return Text('in fts'); } TextStyle dashboardTextStyle() { return TextStyle( color: primaryColor, fontSize: 12, fontWeight: FontWeight.bold, ); } TextStyle labelTextStyleBold() { return TextStyle( fontSize: 12, color: primaryColor, fontWeight: FontWeight.bold, ); } TextStyle labelTextStyleButton() { return TextStyle( fontSize: 12, color: Colors.white, fontWeight: FontWeight.bold, ); } TextStyle labelTextStyleCapacity() { return TextStyle( fontSize: 14, color: primaryColor, fontWeight: FontWeight.bold, ); } TextStyle radioItemsTextStyle() { return TextStyle(color: primaryColor,fontSize: 11,fontWeight: FontWeight.bold); } TextStyle serverIssueTextStyle() { return TextStyle(color: Colors.red, fontSize: 15); } TextStyle bottomSheetValuesTextStyle() { return TextStyle( fontSize: 12, fontWeight: FontWeight.bold, overflow: TextOverflow.ellipsis, ); } TextStyle wrapTextStyle() { return TextStyle( color: primaryColor, fontSize: 12, fontWeight: FontWeight.bold, overflow: TextOverflow.ellipsis, ); } TextStyle wrapTextStyleStartMotor() { return TextStyle( color: Colors.black, fontSize: 15, fontWeight: FontWeight.bold, overflow: TextOverflow.ellipsis, ); } TextStyle wrapTextStyleBlack() { return TextStyle( color: Colors.black, fontSize: 12, fontWeight: FontWeight.bold, overflow: TextOverflow.ellipsis, ); } TextStyle withoutWrapTextStyle() { return TextStyle( color: primaryColor, fontSize: 12, fontWeight: FontWeight.bold, ); } TextStyle elevatedButtonTextStyle() { return TextStyle( fontSize: 16, ); } TextStyle underLineTextStyle() { return TextStyle( color: primaryColor, decoration: TextDecoration.underline, ); } TextStyle fontTextStyle(double fontSize,Color fontColor,FontWeight weight) { return GoogleFonts.inter( textStyle: TextStyle( fontSize: fontSize, fontWeight: weight, color:fontColor, ), ); } TextStyle fontTextStylewithUnderline(double fontSize,Color fontColor,FontWeight weight, Color underlineColor) { return GoogleFonts.inter( textStyle: TextStyle( fontSize: fontSize, fontWeight: weight, color:fontColor, decoration: TextDecoration.underline, decorationColor: underlineColor, decorationThickness: 1, ), ); } TextStyle italicFontTextStyle(double fontSize, Color fontColor, FontWeight weight) { return GoogleFonts.roboto( textStyle: TextStyle( fontSize: fontSize, fontWeight: weight, color: fontColor, fontStyle: FontStyle.italic, ), ); } TextStyle fontTextStyleHeight(double fontSize,Color fontColor,FontWeight weight,double height) { return GoogleFonts.inter( textStyle: TextStyle( fontSize: fontSize, fontWeight: weight, color:fontColor, height: height ), ); } TextStyle fontTextStyleUnderline(double fontSize,Color fontColor,FontWeight weight) { return GoogleFonts.inter( textStyle: TextStyle( fontSize: fontSize, fontWeight: weight, color:fontColor, decoration: TextDecoration.underline, ), ); } InputDecoration textFormFieldDecoration(IconData icon,var text){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, /*prefixIcon: Icon( icon, color: Colors.white, ),*/ border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF1D7AFC),width: 2,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), labelText: text, labelStyle:fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400), /* TextStyle(color: greyColor, fontWeight: FontWeight.bold //<-- SEE HERE ),*/ ); } InputDecoration searchTextFormFieldDecoration(var path,var text){ return InputDecoration( counterText: '', filled: true, fillColor: Color(0XFFE8F2FF), prefixIcon:Padding( padding: EdgeInsets.all(15.0), // Adjust the padding around the image child: Image.asset( path, // Path to your image width: 24, // Set the width height: 24, // Set the height color: Color(0XFF7E7F80), // Optional: Set color filter if needed fit: BoxFit.contain, // Ensure the image is contained within the available space ), ), hintText: text, hintStyle: fontTextStyle(12, Color(0XFF646566), FontWeight.w400), border: OutlineInputBorder( borderRadius: BorderRadius.circular(30.0), borderSide: BorderSide( color: Color(0XFFE8F2FF), width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(30.0), borderSide: BorderSide( color: Color(0XFFE8F2FF), width: 2, ), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(30.0), borderSide: BorderSide(color: Color(0XFFE8F2FF)), ), ); } String capitalizeFirst(String text) { if (text.isEmpty) return text; return text[0].toUpperCase() + text.substring(1); } InputDecoration textFormFieldDecorationHintText(IconData icon,var text){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, /*prefixIcon: Icon( icon, color: Colors.white, ),*/ border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF1D7AFC),width: 2,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), hintText: text, hintStyle:fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400), /* TextStyle(color: greyColor, fontWeight: FontWeight.bold //<-- SEE HERE ),*/ ); } InputDecoration textFormFieldDecorationWithoutLabelText(){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF939495), width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF939495),width: 1,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF939495)), ), ); } InputDecoration DisableTextFormFieldDecoration(){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF939495), width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF939495),width: 1,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF939495)), ), ); } InputDecoration textFormFieldDecorationWithoutLabelTextWithEnableBorder(){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF1D7AFC),width: 2,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), labelStyle:fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400), ); } InputDecoration textFormFieldDecorationWithoutLabelTextWithErrorText(msg){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF1D7AFC),width: 2,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), errorText: msg, errorStyle:fontTextStyle(14,Color(0XFFE2483D),FontWeight.w400), ); } InputDecoration textFormFieldDecorationForSuffixText(IconData icon,var text,var suffixText){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF1D7AFC),width: 2,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), labelText: text, suffix: Text('mins'), labelStyle:fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400), /* TextStyle(color: greyColor, fontWeight: FontWeight.bold //<-- SEE HERE ),*/ ); } InputDecoration textFormFieldDecorationForDateRange(var path,var text){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, suffixIcon:IconButton( icon: Image.asset( path, // Path to your image asset width: 24, // Set the width height: 24, // Set the height color: Color(0XFF7E7F80), fit: BoxFit.contain, // Ensure the image is contained within the given space ), onPressed: () { // Define the action for the icon if necessary print('Suffix icon pressed'); }, ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: Color(0XFF1D7AFC),width: 2,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), labelText: text, labelStyle:fontTextStyle(14,Color(0XFF939495),FontWeight.w400), /* TextStyle(color: greyColor, fontWeight: FontWeight.bold //<-- SEE HERE ),*/ ); } InputDecoration textFormFieldDecorationForSuffix(var path,var text){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, suffixIcon: Padding( padding: EdgeInsets.all(12.0), // Adjust the padding around the image child: Image.asset( path, // Path to your image width: 8, // Set the width height: 8, // Set the height color: Color(0XFF7E7F80), // Optional: Set color filter if needed fit: BoxFit.contain, // Ensure the image is contained within the available space ), ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor,width: 1,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), ); } InputDecoration decorationForDropdown(var path,var text){ return InputDecoration( counterText: '', filled: false, fillColor: Colors.white, prefixIcon:Padding( padding: EdgeInsets.all(15.0), // Adjust the padding around the image child: Image.asset( path, // Path to your image width: 24, // Set the width height: 24, // Set the height color: Color(0XFF7E7F80), // Optional: Set color filter if needed fit: BoxFit.contain, // Ensure the image is contained within the available space ), ), /*IconButton( icon: Image.asset( path, // Path to your image asset width: 20, // Set the width height: 20, // Set the height color: Color(0XFF515253), fit: BoxFit.contain, // Ensure the image is contained within the given space ), onPressed: () { // Define the action for the icon if necessary print('Suffix icon pressed'); }, ),*/ border: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor, width: 1, )), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor,width: 1,), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(15.0), borderSide: BorderSide(color: greyColor), ), labelText: text, labelStyle:fontTextStyle(14,Color(0XFF939495),FontWeight.w400), /* TextStyle(color: greyColor, fontWeight: FontWeight.bold //<-- SEE HERE ),*/ ); } Widget valuesText(var text){ return Container( child: Text( text, overflow: TextOverflow.ellipsis, style: valuesTextStyle(), textScaleFactor: AppSettings.textScaleFactor, ), ); } Widget valuesTextConsumption(var text){ return Container( child: Text( text, overflow: TextOverflow.ellipsis, style: valuesTextStyleConsumption(), textScaleFactor: AppSettings.textScaleFactor, ), ); } Widget valuesTextMotorStatus(var text){ Color textColor=Colors.black; if(text.toString().toLowerCase()=='off'){ textColor=Colors.red; } else{ textColor=Colors.green; } return Container( child: Text( text, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 12, color:textColor, fontWeight: FontWeight.bold, ), textScaleFactor: AppSettings.textScaleFactor, ), ); } Widget valuesTextCapacity(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: valuesTextStyleCapacity(), textScaleFactor: AppSettings.textScaleFactor, ); } Widget valuesTextLowTextScaleFactor(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: valuesTextStyle(), textScaleFactor: 0.9, ); } Widget labelsTextLowTextScaleFactor(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: labelTextStyleBold(), textScaleFactor: 0.9, ); } Widget valuesTextNewBig(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: valuesTextStyleBig(), textScaleFactor: AppSettings.textScaleFactor, ); } Widget labelsText(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: labelTextStyle(), textScaleFactor: AppSettings.textScaleFactor, ); } Widget labelsTextFont(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: fontTextStyle(16,Color(0XFF1D7AFC),FontWeight.w600), textScaleFactor: AppSettings.textScaleFactor, ); } Widget labelsTextBold(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: labelTextStyleBold(), textScaleFactor: AppSettings.textScaleFactor, ); } Widget labelsTextButton(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: labelTextStyleButton(), textScaleFactor: AppSettings.textScaleFactor, ); } Widget labelsTextCapacity(var text){ return Text( text, overflow: TextOverflow.ellipsis, style: labelTextStyleCapacity(), textScaleFactor: AppSettings.textScaleFactor, ); } InputDecoration textFormFieldDecorationForBoxId(IconData icon,var text){ return InputDecoration( filled: true, fillColor: Colors.white, prefixIcon: Icon( icon, color: primaryColor, ), border: OutlineInputBorder(borderSide: BorderSide(color: primaryColor)), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: primaryColor), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: primaryColor), ), labelText: text, labelStyle: TextStyle(color: primaryColor, fontWeight: FontWeight.bold //<-- SEE HERE ), ); } final GlobalKey preloaderWindowKey = new GlobalKey(); Future preloaderWindow(BuildContext context) async { try { Dialogs.showLoadingDialog(context, preloaderWindowKey); } catch (error) {} } class AppSettings { static SharedPreferences sharedPreferences = SharedPreferences.getInstance() as SharedPreferences; static String userName = ''; static String loginType = ''; static String accessType = ''; static String buildingName = ''; static String userAddress = ''; static String email = ''; static String phoneNumber = ''; static String accessToken = ''; static String customerId = ''; static double userLatitude = 0; static double userLongitude = 0; static String customerIdsign = ''; static String profileImage = ''; static List storedPreferenceValidKeys = ['phone', 'access_token']; static String preloadText = 'Please wait'; static String latitude = ''; static String longitude = ''; static bool servicestatus = false; static bool haspermission = false; static late LocationPermission permission; static late Position position; static String long = "", lat = ""; late StreamSubscription positionStream; static String fcmId = ''; static double textScaleFactor = 1.1; static String serverToken = 'AAAAA66BLaA:APA91bHcmbyiNN8hCL-t-M9oH-u7ZMOl74fcImMM2DQZLgdyY98Wu9XxME-CTPcjpjU6Yy48ouxISrOMb9lpa3PJofh8qciUKMNxV2al-bDvGvPP_VVaH0mrTHzR56hdkGy1Zl-0frDO'; static String profilePictureUrl = ''; //api urls //static String host = 'http://34.100.133.20:5000/api/'; //static String host = 'http://35.207.198.4:3000/api/'; //public host static String host = 'http://armintaaqua.com:3000/api/'; // local host //static String host = 'http://10.10.1.127:5000/api/'; static String addTanksUrl = host + 'addTanks'; static String addTankerUrl = host + 'addTankers'; static String addBoreUrl = host + 'addBores'; static String addGovtPipelinesUrl = host + 'addGovtPIpeline'; static String loginUrl = host + 'login'; static String signUpUrl = host + 'users'; static String verifyPhnUrl = host + 'phone'; static String getTanksDataUrl = host + 'getTanks'; static String getParticularTankConnectionsDataUrl = host + 'getConnectionsInfoOfParticularTank'; static String getIotDataUrl = host + 'APIRead'; static String capacityCaluculateUrl = host + 'calculateCapacity'; static String getBoresDataUrl = host + 'getBores'; static String UpdateBoresUrl = host + 'updateBores'; static String UpdateTankerUrl = host + 'updateTankers'; static String connectRequestUrl = host + 'users/friend-request'; static String disconnectRequestUrl = host + 'friend-request/reject'; static String cancelOrderUrl = host + 'deleteBookingInfo'; static String UpdateGovtPipelinesUrl = host + 'updatePipeline'; static String bookATankerUrl = host + 'bookingData'; static String updateProfileUrl = host + 'update/currentUser'; static String profilePicUrl = host + 'users/profile-picture'; static String uploadPicUrl = host + 'uploads-user'; static String getBookingTankerDetails = host + 'getTankersBookingdetails'; static String getPendingOrdersForConfirmationUrl = host + 'pendingconformation'; static String getOrdersYetDeliveryUrl = host + 'accepted'; static String getCancelledOrdersUrl = host + 'rejected'; static String getDeliveredOrdersUrl = host + 'delivered'; static String getAllOrdersUrl = host + 'orders'; static String getCustomerPlansUrl = host + 'getuserRequestbookingsforplansforcustomer'; static String getTankersDataUrl = host + 'getallTankers'; static String getSupplierAllTankersDataUrl = host + 'getTankers'; static String getCartItemsUrl = host + 'cart'; static String getAllSuppliersDataUrl = host + 'getSupplierswithoutbooking'; static String getConnectedSuppliersDataUrl = host + 'connectedSuppliers'; static String getPendingSuppliersDataUrl = host + 'pendingSuppliers'; static String getDisconnectedSuppliersDataUrl = host + 'rejectSuppliers'; static String getGovtPipelinesDataUrl = host + 'getPipelines'; static String deleteTankUrl = host + 'deleteTank'; static String deleteBoreUrl = host + 'deleteBore'; static String deleteGovtPipelineUrl = host + 'deletePipeline'; static String deleteTankerUrl = host + 'deleteTanker'; static String updateTankUrl = host + 'updateTanks'; static String createConnectionsUrl = host + 'createConnections'; static String UpdateConnectionsUrl = host + 'updateConnections'; static String deleteTankConnectionsUrl = host + 'deleteTankConnections'; static String getTankLevelsDataUrl = host + 'getTanklevels'; static String getinitialwaterlevel = host + 'updateTanklevels'; static String getConsumptionDataUrl = host + 'consumption'; static String getConsumptionDataDateWiseOfAllTanksUrl = host + 'consumptiondatewiseofalltanks'; static String resetTokenUrl = host + 'reset_token'; static String startAndStopUrl = host + 'motorAction'; static String getUserAccountsUrl = host + 'userAccounts'; static String getUserSupplierAccountsUrl = host + 'UserSupplierAccounts'; static String forgotPasswordUrl = host + 'forgotpassword'; static String forgotChangePasswordUrl = host + 'forgot-change-password'; static String ChangePasswordUrl = host + 'changePassword'; static String resetPasswordUrl = host + 'resetpassword'; static String acceptBookingRequestsUrl = host + 'ordernow'; static String readMotorStatusUrl = host + 'motor/readMotorIotStatus'; static String changeMotorStatusUrl = host + 'motor/changeMotorStatus'; static String updateTankMinMaxPercentageUrl = host + 'update_auto_percentage'; static String updateMotorModeUrl = host + 'update_auto_mode'; static String getBlocksDataUrl = host + 'getBlockData'; static String getConsumptionDataForParticulartankUrl = host + 'consumptionofparticulartank'; static String addStaffUrl = host + 'createstaff'; static String viewStaffDataUrl = host + 'currentUser'; static String deleteStaffUrl = host + 'deletestaff'; static String updateStaffUrl = host + 'editstaff'; static String getMotorHistoryDataUrl = host + 'getTankmotordata'; static String updateTankStatusUrl = host + 'updatetankstatus'; static String getMinMaxLevelsOfAllTanksUrl = host + 'getCustomerAutoPercentages'; static String getPumpsAndUsersDataUrl = host + 'getPumpsAndUsers'; static String blockStaffUrl = host + 'blockstaff'; static String pauseNotificationUrl = host + 'sendNotificationDailyPreference'; static String timeBasedNotificationUrl = host + 'sendNotificationDaily'; static String lowLevelNotificationUrl = host + 'sendNotificationLowWaterLevel'; static String criticalLowLevelNotificationUrl = host + 'sendNotificationCriticallyWaterLevel'; static String automaticNotificationUrl = host + 'sendNotificationAutomaticStartAndStop'; static String manualNotificationUrl = host + 'sendNotificationManualStartAndStop'; static String removeFavouritesUrl = host + 'deletefavoratesupplier'; static String addFavouriteUrl = host + 'addingfavoratesupplier'; static String getAllFavouritesDataUrl = host + 'favorites'; static String getSuppliersForBookingUrl = host + 'suppliersforbooking'; static String requestOrderUrl = host + 'requestedbookings'; static String requestPlanUrl = host + 'requestedplanbookings'; static String getAcceptedOrdersDataFromSupplierUrl = host + 'getuserRequestbookings'; static String getAcceptedPlansFromSupplierUrl = host + 'getuserRequestbookingsforplansforcustomer'; static String getSuppliersForPlanUrl = host + 'plan/suppliers'; static String acceptOrderRequestsUrl = host + 'request-advance-amount'; static String acceptPlanRequestsUrl = host + 'customer/recurring/respond'; static String getAcceptedOrdersUrl = host + 'getAllTankersBookingdetailsofuser'; static String acceptPlanRequestsWithPaymentUrl = host + 'user/recurring/payment'; static String updateTankNamehileDeliveryUrl = host + 'update-tank-name-while-delivery'; static String updateBookingDetailsByIdUrl = host + 'get_tanker_booking'; static String rescheduleOrderUrl = host + 'tanker/reSchedule'; static String cancelPlanOrderUrl = host + 'cancelOrder'; static String getAdvanceTransactionsByCustomerUrl = host + 'advance/transactions/customer'; static String payAdvanceUrl = host + 'advance/pay'; static String getAdvanceTransactionsBySupplierAndCustomerUrl = host + 'advance/transactions'; static String addAdvanceTopUpUrl = host + 'advance/transactions'; static String verifyRazorpayPaymentUrl = host + 'advance/transactions'; static String createRazorpayOrderUrl = host + 'advance/transactions'; static String cancelTankerBookingUrl = host + 'update-tank-cancel-status'; static String getSupplierBookingsUrl = host + 'getuserRequestbookingsforplansforcustomer'; static String recurringDateActionUrl = host + 'recurring-booking/date-action'; static File? updatedImage; static String image = ''; static var api = { 'signIn': host + '/login', }; /*Formatter*/ static String formNum(String s) { var comma = NumberFormat('#,##,###', 'en_IN'); return comma.format( int.parse(s), ); } static String formDouble(dynamic s) { var comma = NumberFormat('#,##,###.##', 'en_IN'); if (s == null) return "0.00"; String str = s.toString().trim(); if (str.isEmpty) return "0.00"; try { return comma.format(double.parse(str)); } catch (e) { return "0.00"; // fallback if it's not a valid number } } static String moneyConvertion(String value) { var comma = NumberFormat('#,##,###.00', 'en_IN'); return comma.format( double.parse(value), ); } /* Preloader */ static GlobalKey preLoaderKey = new GlobalKey(); static Future preLoaderDialog(BuildContext context) async { try { preLoaderKey = new GlobalKey(); Dialogs.showLoadingDialog(context, preLoaderKey); } catch (error) {} } ////request headers with content type static Future> buildRequestHeaders() async { Map _headers = new Map(); _headers[HttpHeaders.contentTypeHeader] = 'application/json'; _headers['Authorization'] = accessToken; return _headers; } static Future> buildRequestHeaders1() async { Map _headers = new Map(); _headers[HttpHeaders.contentTypeHeader] = 'application/json'; return _headers; } //request headers without content type static Future> buildPutRequestHeaders() async { Map _headers = new Map(); _headers['Authorization'] = accessToken; return _headers; } static Future> buildPutRequestHeadersForResetToken() async { Map _headers = new Map(); return _headers; } // Shared preferences save,get and clear data static saveData(String _key, _value, type) async { sharedPreferences = await SharedPreferences.getInstance(); if (type == 'STRING') { await sharedPreferences.setString(_key, _value.toString()); } else if (type == 'INTEGER') { await sharedPreferences.setInt(_key, _value); } else if (type == 'BOOL') { await sharedPreferences.setBool(_key, _value); } else if (type == 'DOUBLE') { await sharedPreferences.setDouble(_key, _value); } } static getData(String _key, type) async { sharedPreferences = await SharedPreferences.getInstance(); if (type == 'STRING') { return sharedPreferences.getString(_key) ?? ''; } else if (type == 'INTEGER') { return sharedPreferences.getInt(_key) ?? -1; } else if (type == 'BOOL') { return sharedPreferences.getBool(_key) ?? -1; } else if (type == 'DOUBLE') { return sharedPreferences.getDouble(_key) ?? -1; } } static clearSharedPreferences() async { sharedPreferences = await SharedPreferences.getInstance(); await sharedPreferences.clear(); } /*Sign in check*/ static Future isSigIn() async { bool isSignInCheck = true; for (var eachKey in storedPreferenceValidKeys) { if (await getData(eachKey, 'STRING') == '') { isSignInCheck = false; } } return isSignInCheck; } static Future internetConnectivity() async { try { final result = await InternetAddress.lookup('google.com'); if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) { return true; } } on SocketException catch (_) { return false; } return false; } /*Apis Starts here*/ static Future login(payload) async { var response = await http.post(Uri.parse(loginUrl), body: json.encode(payload), headers: {'Content-type': 'application/json'}); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response['simplydata']['error']); if (_response['simplydata']['error'] == false) { await saveAvailableReportAndLocationsInMemory(_response); //await saveProfilePic(_response); return true; } else { return false; } } catch (e) { // display error toast return false; } } else { return false; } } static Future signUp(payload) async { var response = await http.post(Uri.parse(signUpUrl), body: json.encode(payload), headers: {'Content-type': 'application/json'}); if (response.statusCode == 200) { try { var _response = json.decode(response.body); customerIdsign = _response['armintatankdata']['customerId']; print(_response); return true; } catch (e) { // display error toast return false; } } else { return false; } } static Future verifyPhn(payload) async { var response = await http.post(Uri.parse(verifyPhnUrl), body: json.encode(payload), headers: {'Content-type': 'application/json'}); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); if (_response['armintatankdata']['error'] == false) { return true; } else { return false; } } catch (e) { // display error toast return false; } } else { return false; } } static Future updateProfile(payload) async { var uri = Uri.parse(updateProfileUrl + '/' + customerId); try { var response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { var _response = json.decode(response.body); userName = _response['username']; phoneNumber = _response['phone']; email = _response['emails'][0]['email']; return true; } else { return false; } } catch (e) { print(e); return false; } } static Future updateProfilePicture(payload) async { var uri = Uri.parse(profilePicUrl + '/' + customerId); var response = await http.post(uri, 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 { return false; } } static Future uploadrofileImageHTTPNew(file) async { var request = http.MultipartRequest( 'POST', Uri.parse(uploadPicUrl + '/' + customerId)); request.files.add( await http.MultipartFile.fromPath('file', file.path) ); var res = await request.send(); var response = await http.Response.fromStream(res); return response.body; } static Future addTanks(payload) async { var uri = Uri.parse(addTanksUrl + '/' + customerId); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future addStaff(payload) async { var uri = Uri.parse(addStaffUrl + '/' + customerId); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future viewStaff(payload) async { var uri = Uri.parse(viewStaffDataUrl); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future updateStaff(phone,payload) async { var uri = Uri.parse(updateStaffUrl + '/' + customerId+ '/' + phone); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future blockStaff(phone) async { var uri = Uri.parse(blockStaffUrl + '/' + customerId+ '/' + phone); try { var response = await http.patch(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, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future deleteStaff(phone) async { var uri = Uri.parse(deleteStaffUrl + '/' + customerId+ '/' + phone); try { var response = await http.delete(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.delete(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future getTanks() async { var uri = Uri.parse(getTanksDataUrl); uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getParticularTankConnections(payload) async { var uri = Uri.parse(getParticularTankConnectionsDataUrl+'/'+customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getIotDataNew() async { var uri = Uri.parse(getIotDataUrl); uri = uri.replace(query: 'hardwareId=56789'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getTankLevels() async { var uri = Uri.parse(getTankLevelsDataUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future pauseNotificationsData(payload) async { var uri = Uri.parse(pauseNotificationUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); // You can inspect this response further for success return true; } catch (e) { print("Error decoding response: $e"); return false; } } else { print("Request failed with status: ${response.statusCode}"); print("Response body: ${response.body}"); return false; } } catch (e) { print("Error during request: $e"); return false; } } static Future timeBasedNotificationsData(payload) async { var uri = Uri.parse(timeBasedNotificationUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); // You can inspect this response further for success return true; } catch (e) { print("Error decoding response: $e"); return false; } } else { print("Request failed with status: ${response.statusCode}"); print("Response body: ${response.body}"); return false; } } catch (e) { print("Error during request: $e"); return false; } } static Future lowLevelNotificationsData(payload) async { var uri = Uri.parse(lowLevelNotificationUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); // You can inspect this response further for success return true; } catch (e) { print("Error decoding response: $e"); return false; } } else { print("Request failed with status: ${response.statusCode}"); print("Response body: ${response.body}"); return false; } } catch (e) { print("Error during request: $e"); return false; } } static Future criticalLowLevelNotificationsData(payload) async { var uri = Uri.parse(criticalLowLevelNotificationUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); // You can inspect this response further for success return true; } catch (e) { print("Error decoding response: $e"); return false; } } else { print("Request failed with status: ${response.statusCode}"); print("Response body: ${response.body}"); return false; } } catch (e) { print("Error during request: $e"); return false; } } static Future automaticNotificationsData(payload) async { var uri = Uri.parse(automaticNotificationUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); // You can inspect this response further for success return true; } catch (e) { print("Error decoding response: $e"); return false; } } else { print("Request failed with status: ${response.statusCode}"); print("Response body: ${response.body}"); return false; } } catch (e) { print("Error during request: $e"); return false; } } static Future manualNotificationsData(payload) async { var uri = Uri.parse(manualNotificationUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); // You can inspect this response further for success return true; } catch (e) { print("Error decoding response: $e"); return false; } } else { print("Request failed with status: ${response.statusCode}"); print("Response body: ${response.body}"); return false; } } catch (e) { print("Error during request: $e"); return false; } } static Future capacityCaluculate(payload) async { var uri = Uri.parse(capacityCaluculateUrl); var response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future deleteTank(tankName, payload) async { var uri = Uri.parse(deleteTankUrl + '/' + customerId); uri = uri.replace(query: 'tankName=$tankName'); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future updateTank(tankName, payload) async { var uri = Uri.parse(updateTankUrl + '/' + customerId); uri = uri.replace(query: 'tankName=$tankName'); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future updateTankMinMaxPercentage(payload) async { var uri = Uri.parse(updateTankMinMaxPercentageUrl + '/' + customerId); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future updateTankStatus(payload) async { var uri = Uri.parse(updateTankStatusUrl + '/' + customerId); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future updateMotorMode(payload) async { var uri = Uri.parse(updateMotorModeUrl + '/' + customerId); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future addTankers(payload) async { var uri = Uri.parse(addTankerUrl + '/' + customerId); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future getTankers() async { var uri = Uri.parse(getTankersDataUrl); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getAllTankers(var supplierId) async { var uri = Uri.parse(getSupplierAllTankersDataUrl); uri = uri.replace(query: 'supplierId=$supplierId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getCartItems() async { var uri = Uri.parse(getCartItemsUrl+ '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getAllSuppliers() async { var uri = Uri.parse(getAllSuppliersDataUrl+'/'+customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.post(uri,headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post(uri,headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getConnetcedSuppliers() async { var uri = Uri.parse(getConnectedSuppliersDataUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getPendingSuppliers() async { var uri = Uri.parse(getPendingSuppliersDataUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getDisconnectedSuppliers() async { var uri = Uri.parse(getDisconnectedSuppliersDataUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future updateTanker(tankerName, payload) async { var uri = Uri.parse(UpdateTankerUrl + '/' + customerId); uri = uri.replace(query: 'tankerName=$tankerName'); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future deleteTanker(tankerName) async { var uri = Uri.parse(deleteTankerUrl + '/' + customerId); uri = uri.replace(query: 'tankerName=$tankerName'); try { 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, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future getUpdateTankLevelsInitial() async { var uri = Uri.parse(getinitialwaterlevel + "/" + customerId); var response = await http.put(uri, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future addBores(payload) async { var uri = Uri.parse(addBoreUrl + '/' + customerId); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future getBores() async { var uri = Uri.parse(getBoresDataUrl); uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future updateBore(boreName, payload) async { var uri = Uri.parse(UpdateBoresUrl + '/' + customerId); uri = uri.replace(query: 'boreName=$boreName'); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future deleteBore(boreName) async { var uri = Uri.parse(deleteBoreUrl + '/' + customerId); uri = uri.replace(query: 'boreName=$boreName'); try { 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, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future addGovtPipelines(payload) async { var uri = Uri.parse(addGovtPipelinesUrl + '/' + customerId); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future getGovtPipelines() async { var uri = Uri.parse(getGovtPipelinesDataUrl); uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future updateGovtPipeline(pipelineName, payload) async { var uri = Uri.parse(UpdateGovtPipelinesUrl + '/' + customerId); uri = uri.replace(query: 'Name=$pipelineName'); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future deleteGovtPipeline(pipelineName) async { var uri = Uri.parse(deleteGovtPipelineUrl + '/' + customerId); uri = uri.replace(query: 'Name=$pipelineName'); try { 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, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future createConnections(payload) async { var uri = Uri.parse(createConnectionsUrl + '/' + customerId); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); return true; } catch (e) { print(e); return false; } } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future updateConnections(payload) async { var uri = Uri.parse(UpdateConnectionsUrl + '/' + customerId); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future deleteTankConnection(tankName) async { var uri = Uri.parse(deleteTankConnectionsUrl + '/' + customerId); uri = uri.replace(query: 'tankName=$tankName'); try { 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, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future bookATanker(payload) async { var uri = Uri.parse(bookATankerUrl + '/' + customerId); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response); return response.body; } catch (e) { print(e); return ''; } } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getBookedTankerDetails(tankerName) async { var uri = Uri.parse(getBookingTankerDetails + '/' + customerId); uri = uri.replace(query: 'tankerName=$tankerName'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { var _response = json.decode(response.body); //print(_response); return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getPendingOrdersForConfirmation() async { var uri = Uri.parse(getPendingOrdersForConfirmationUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getOrdersYetDelivery() async { var uri = Uri.parse(getOrdersYetDeliveryUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getDeliveredOrders() async { var uri = Uri.parse(getDeliveredOrdersUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getCancelledOrders() async { var uri = Uri.parse(getCancelledOrdersUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getAllOrders() async { var uri = Uri.parse(getAllOrdersUrl); uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getCustomerPlans() async { var uri = Uri.parse(getCustomerPlansUrl+'/'+customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getAcceptedOrdersDataFromSupplier() async { var uri = Uri.parse(getAcceptedOrdersDataFromSupplierUrl+'/'+customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getAcceptedPlansFromSupplier() async { var uri = Uri.parse(getAcceptedPlansFromSupplierUrl+'/'+customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getConsumptionData(payload) async { var uri = Uri.parse(getConsumptionDataUrl + '/' + customerId); var response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getMotorHistoryData(payload) async { var uri = Uri.parse(getMotorHistoryDataUrl + '/' + customerId); var response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getConsumptionDataDateWiseOfAllTanks(payload) async { var uri = Uri.parse(getConsumptionDataDateWiseOfAllTanksUrl + '/' + customerId); var response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getConsumptionDataForParticularTank(payload) async { var uri = Uri.parse(getConsumptionDataForParticulartankUrl + '/' + customerId); var response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getBlocks() async { var uri = Uri.parse(getBlocksDataUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri,headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getPumpsAndUsers() async { var uri = Uri.parse(getPumpsAndUsersDataUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri,headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future resetToken() async { var uri = Uri.parse(resetTokenUrl + '/' + customerId); try { // var response = await http.get(uri, headers: await buildPutRequestHeaders()); var response = await http.get(uri, headers: await buildPutRequestHeadersForResetToken()); if (response.statusCode == 200) { print(response.body); var res = jsonDecode(response.body); print(res); accessToken = res['access_token']; return true; } else { return false; } } catch (e) { print(e); return false; } } static Future startAndStop(payload) async { var uri = Uri.parse(startAndStopUrl + '/' + customerId); //uri = uri.replace(query: 'Name=$pipelineName'); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future startAndStopResponse(payload) async { var uri = Uri.parse(startAndStopUrl + '/' + customerId); //uri = uri.replace(query: 'Name=$pipelineName'); try { var response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { return response.body; } catch (e) { print(e); return ''; } } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } catch (e) { print(e); return ''; } } static Future connectRequest(payload) async { var uri = Uri.parse(connectRequestUrl); try { var response = await http.post(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.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future disconnectRequest(payload) async { var uri = Uri.parse(disconnectRequestUrl); try { 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future cancelOrder(var bookingId) async { var uri = Uri.parse(cancelOrderUrl + '/' + bookingId); try { 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, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } catch (e) { print(e); return false; } } static Future cancelOrderNew(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 getUserAccounts() async { var uri = Uri.parse(getUserAccountsUrl + '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getUserSupplierAccounts(var payload) async { var uri = Uri.parse(getUserSupplierAccountsUrl + '/' + customerId); var response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future forgotPassword(payload) async { var uri = Uri.parse(forgotPasswordUrl); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future forgotChangePassword(payload) async { var uri = Uri.parse(forgotChangePasswordUrl); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response['simplydata']['error']); if (_response['simplydata']['error'] == false) { await saveAvailableReportAndLocationsInMemory(_response); //await saveProfilePic(_response); return true; } else { return false; } } catch (e) { // display error toast return false; } /* 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future ChangePassword(payload) async { var uri = Uri.parse(ChangePasswordUrl); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); print(_response['armintatankdata']['error']); if (_response['armintatankdata']['error'] == false) { return true; } else { return false; } } catch (e) { // display error toast return false; } /* 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future resetPassword(payload) async { var uri = Uri.parse(resetPasswordUrl); var response = await http.post(uri, 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future sendNotification(var body, var titile) async { final postUrl = 'https://fcm.googleapis.com/fcm/send'; var token = fcmId; print('token : $token'); final data = { "notification": {"body": body, "title": titile}, "priority": "high", "data": { "click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done" }, "to": "$token" }; final headers = { 'content-type': 'application/json', 'Authorization': 'key=$serverToken', }; BaseOptions options = BaseOptions( headers: headers, ); try { final response = await Dio(options).post(postUrl, data: data); if (response.statusCode == 200) { longSuccessToast('Request notification sent to supplier'); } else { print('notification sending failed'); // on failure do sth } } catch (e) { print('exception $e'); } } static Future sendNotificationFromApp(var body, var titile) async { http.post( Uri.parse('https://fcm.googleapis.com/fcm/send'), headers: { 'Content-Type': 'application/json', 'Authorization': 'key=$serverToken', }, body: jsonEncode( { 'notification': { 'title': titile, 'body': body, }, 'priority': 'high', 'data': { 'click_action': 'FLUTTER_NOTIFICATION_CLICK', 'id': '1', 'status': 'done' }, 'to': fcmId, }, ), ); } static Future readMotorStatus() async { var uri = Uri.parse(readMotorStatusUrl); uri = uri.replace(query: 'motor_id=12345'); try { var response = await http.get(uri, headers: await buildRequestHeaders1()); if (response.statusCode == 200) { return response.body; } else { return ''; } } catch (e) { print(e); return ''; } } static Future changeMotorStatus(payload) async { var uri = Uri.parse(changeMotorStatusUrl); try { var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders1()); if (response.statusCode == 200) { return response.body; } else { return ''; } } catch (e) { print(e); return ''; } } static Future getMinMaxLevelsOfAllTanks() async { var uri = Uri.parse(getMinMaxLevelsOfAllTanksUrl+ '/' + customerId); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future removeFavourites(supplierId) async { var uri = Uri.parse(removeFavouritesUrl + '/' + customerId); uri = uri.replace(query: 'supplierId=$supplierId'); try { var response = await http.delete(uri, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { var _response = json.decode(response.body); return true; } else { return false; } } catch (e) { print(e); return false; } } static Future addFavourites(supplierId) async { var uri = Uri.parse(addFavouriteUrl + '/' + customerId); uri = uri.replace(query: 'supplierId=$supplierId'); try { var response = await http.put(uri, headers: await buildPutRequestHeaders()); if (response.statusCode == 200) { var _response = json.decode(response.body); return true; } else { return false; } } catch (e) { print(e); return false; } } static Future getAllFavourites() async { var uri = Uri.parse(getAllFavouritesDataUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future getSuppliersForBooking(payload) async { var uri = Uri.parse(getSuppliersForBookingUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future requestOrder(payload) async { var uri = Uri.parse(requestOrderUrl); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future requestPlan(payload) async { var uri = Uri.parse(requestPlanUrl); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { try { var _response = json.decode(response.body); 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, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future getSuppliersForPlan(payload) async { var uri = Uri.parse(getSuppliersForPlanUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future acceptOrderRequests(payload,dbId) async { var uri = Uri.parse(acceptOrderRequestsUrl+'/'+dbId+'/supplier/advance'); 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,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future acceptPlanRequestsWithPayment(payload,dbId) async { var uri = Uri.parse(acceptPlanRequestsWithPaymentUrl+'/'+dbId); 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,body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return true; } else { return false; } } else { return false; } } else { return false; } } static Future> acceptPlanRequests(payload, dbId) async { var uri = Uri.parse(acceptPlanRequestsUrl + '/' + dbId); var response = await http.post( uri, body: json.encode(payload), headers: await buildRequestHeaders(), ); if (response.statusCode == 200) { return jsonDecode(response.body); } // If unauthorized, refresh token if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.post( uri, body: json.encode(payload), headers: await buildRequestHeaders(), ); if (response.statusCode == 200) { return jsonDecode(response.body); } } } // Default fallback return {"status_code": 0}; } static Future getAcceptedOrders() async { var uri = Uri.parse(getAcceptedOrdersUrl+'/'+customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future updateTankNameWhileDelivery(dbId,payload) async { var uri = Uri.parse(updateTankNamehileDeliveryUrl + '/' + dbId); try { var response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri, body: json.encode(payload), headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ""; } } else { return ""; } } else { return ""; } } catch (e) { print(e); return ""; } } static Future updateBookingDetailsById(dbId) async { var uri = Uri.parse(updateBookingDetailsByIdUrl + '/' + dbId); try { var response = await http.get(uri,headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ""; } } else { return ""; } } else { return ""; } } catch (e) { print(e); return ""; } } static Future rescheduleOrder(dbId,payload) async { var uri = Uri.parse(rescheduleOrderUrl + '/' + customerId+ '/' + dbId); try { var response = await http.put(uri,body: json.encode(payload),headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.put(uri,body: json.encode(payload),headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ""; } } else { return ""; } } else { return ""; } } catch (e) { print(e); return ""; } } static Future cancelPlanOrder(String dbId) async { final uri = Uri.parse('$cancelPlanOrderUrl/$customerId/$dbId'); try { print("CANCEL PLAN URL => $uri"); var response = await http.patch( uri, ); if (response.statusCode == 200) { return response.body; } print("CANCEL ERROR ${response.statusCode} => ${response.body}"); return ""; } catch (e) { print("CANCEL EXCEPTION => $e"); return ""; } } static Future getAdvanceTransactionsByCustomer() async { var uri = Uri.parse(getAdvanceTransactionsByCustomerUrl + '/' + customerId); //uri = uri.replace(query: 'customerId=$customerId'); var response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else if (response.statusCode == 401) { bool status = await AppSettings.resetToken(); if (status) { response = await http.get(uri, headers: await buildRequestHeaders()); if (response.statusCode == 200) { return response.body; } else { return ''; } } else { return ''; } } else { return ''; } } static Future payAdvance({ required String transactionId, required Map payload, }) async { var uri = Uri.parse(payAdvanceUrl + '/' + transactionId); var response = await http.put( uri, body: json.encode(payload), headers: await buildRequestHeaders(), ); if (response.statusCode == 200) { return true; } // 🔁 Retry on token expiry if (response.statusCode == 401) { final refreshed = await resetToken(); if (refreshed) { response = await http.put( uri, body: json.encode(payload), headers: await buildRequestHeaders(), ); return response.statusCode == 200; } } return false; } static Future getAdvanceTransactionsBySupplierAndCustomer( String supplierId, String customerId, ) async { var uri = Uri.parse("$getAdvanceTransactionsBySupplierAndCustomerUrl/$supplierId/$customerId"); final response = await http.get( uri, headers: await buildRequestHeaders(), ); if (response.statusCode == 200) { return response.body; } else { throw Exception("Failed to fetch transactions"); } } static Future addAdvanceTopUp( String supplierId, String customerId, double amount, String paymentType, { String gatewayTxnId = "", }) async { var uri = Uri.parse(addAdvanceTopUpUrl); final response = await http.post( uri, headers: await buildRequestHeaders(), body: jsonEncode({ "supplierId": supplierId, "customerId": customerId, "advance_amount": amount, "payment_type": paymentType, "gateway_txn_id": gatewayTxnId, }), ); if (response.statusCode == 200) { return response.body; } else { throw Exception("Failed to top up credit"); } } static Future createRazorpayOrder({ required double amount, required String supplierId, required String customerId, }) async { var uri = Uri.parse(createRazorpayOrderUrl); final response = await http.post( uri, headers: await buildRequestHeaders(), body: jsonEncode({ "amount": amount, "supplierId": supplierId, "customerId": customerId, }), ); if (response.statusCode == 200) { return response.body; // must return: { "order_id": "...", "key_id": "rzp_test..." } } else { throw Exception("Failed to create Razorpay order"); } } static Future verifyRazorpayPayment({ required String razorpayPaymentId, required String razorpayOrderId, required String razorpaySignature, }) async { var uri = Uri.parse(verifyRazorpayPaymentUrl); final response = await http.post( uri, headers: await buildRequestHeaders(), body: jsonEncode({ "razorpay_payment_id": razorpayPaymentId, "razorpay_order_id": razorpayOrderId, "razorpay_signature": razorpaySignature, }), ); if (response.statusCode == 200) { return response.body; } else { throw Exception("Failed to verify Razorpay payment"); } } static Future cancelTankerBooking( String bookingId, String status, String reason, ) async { try { var uri = Uri.parse("$cancelTankerBookingUrl/$bookingId"); var payload = json.encode({ "status": status, // "cancelled" "reason": reason, }); var response = await http.put( uri, body: payload, headers: await buildRequestHeaders(), ); if (response.statusCode == 200) { return true; } // 🔁 Token expired → retry if (response.statusCode == 401) { bool refreshed = await resetToken(); if (!refreshed) return false; response = await http.put( uri, body: payload, headers: await buildRequestHeaders(), ); return response.statusCode == 200; } return false; } catch (e) { debugPrint("❌ cancelTankerBooking error: $e"); return false; } } static Future getSupplierBookings() async { var uri = Uri.parse("$getSupplierBookingsUrl/${AppSettings.customerId}"); final response = await http.get( uri, headers: await buildRequestHeaders(), ); if (response.statusCode == 200) { return response.body; } else { throw Exception("Failed to fetch transactions"); } } static Future recurringDateAction( String bookingId, Map payload, ) async { final url = Uri.parse("$recurringDateActionUrl/${bookingId}"); final response = await http.post( url, headers: await buildRequestHeaders(), body: jsonEncode(payload), ); if (response.statusCode != 200) { throw Exception( "Recurring date action failed: ${response.body}", ); } } /*Apis ends here*/ //save data local static Future saveAvailableReportAndLocationsInMemory( dynamic input) async { // save login name information await saveData('username', input['simplydata']['username'], 'STRING'); await saveData('logintype', input['simplydata']['loginType'], 'STRING'); await saveData('all_motor_access', input['simplydata']['all_motor_access'], 'STRING'); await saveData('buildingname', input['simplydata']['buildingName'], 'STRING'); await saveData( 'access_token', input['simplydata']['access_token'], 'STRING'); await saveData('phone', input['simplydata']['phone'], 'STRING'); await saveData('email', input['simplydata']['email'][0]['email'], 'STRING'); await saveData('customerId', input['simplydata']['customerId'], 'STRING'); await saveData('profile', input['simplydata']['picture'], 'STRING'); await saveData('user_address', input['simplydata']['address1'], 'STRING'); if(input['simplydata']['latitude']==0){ input['simplydata']['latitude']=0.0; } if(input['simplydata']['longitude']==0){ input['simplydata']['longitude']=0.0; } await saveData('latitude', input['simplydata']['latitude'], 'DOUBLE'); await saveData('longitude', input['simplydata']['longitude'], 'DOUBLE'); await saveData('fcmId', input['simplydata']['fcmId'], 'STRING'); //latitude,longitude await loadDataFromMemory(); } static Future saveProfile(dynamic image) async { // save login name information await saveData('profile', image.toString(), 'STRING'); //await loadDataFromMemory(); } static Uint8List convertBase64Image(String base64String) { return Base64Decoder().convert(base64String.split(',').last); } static Future loadDataFromMemory() async { userName = await getData('username', 'STRING'); loginType = await getData('logintype', 'STRING'); accessType = await getData('all_motor_access', 'STRING'); buildingName = await getData('buildingname', 'STRING'); accessToken = await getData('access_token', 'STRING'); email = await getData('email', 'STRING'); userAddress = await getData('user_address', 'STRING'); phoneNumber = await getData('phone', 'STRING'); customerId = await getData('customerId', 'STRING'); userLatitude = await getData('latitude', 'DOUBLE'); userLongitude = await getData('longitude', 'DOUBLE'); profilePictureUrl = await getData('profile', 'STRING'); fcmId = await getData('fcmId', 'STRING'); //profileImage=await getData('profile', 'STRING'); getProfile(); } static String getStringFromBytes(var data) { final buffer = data.buffer; var list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); var bufferdata = utf8.decode(list); String bs4str = base64.encode(list); Uint8List decodedbytes = base64.decode(bs4str); //OR // String bs4str1 = base64Encode(imgbytes); String s = new String.fromCharCodes(list); var outputAsUint8List = new Uint8List.fromList(s.codeUnits); return bufferdata; } static Uint8List image1(dynamicList) { List intList = dynamicList.cast().toList(); //This is the magical line. Uint8List data = Uint8List.fromList(intList); return data; } static Future getProfile() async { final image1 = await getData('profile', 'STRING'); //Io.File.fromUri(imageFile.uri) var x = image1; if (image1 == null) return; if (image1 == '') { updatedImage = null; } else if (image1 == 'null') { updatedImage = null; } else { final imageTemp = File(image1); updatedImage = imageTemp; } print(updatedImage); } //assign saved values to variables static Future saveProfilePic(dynamic input) async { SharedPreferences prefs = await SharedPreferences.getInstance(); // your custom int list List mList = input['simplydata']['picture']['data']; print(mList.length); //input['simplydata']['picture']['data'];[0,1,2,3] // convert your custom list to string list List stringsList = mList.map((i) => i.toString()).toList(); // store your string list in shared prefs prefs.setStringList("stringList", stringsList); // String bar = utf8.decode(bytes); //String convertedValue = utf8.decode(mList); } static Widget noDataUI(String _tabName) { _tabName = _tabName ?? ''; return Container( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image( image: AssetImage('images/no_data.png'), width: 200, ), SizedBox( height: 8, ), Text( 'There is no data to show you right now.', style: TextStyle( fontSize: 12, color: Colors.grey[600], fontFamily: 'Swis2', ), ), SizedBox( height: 5, ), Text( _tabName, style: TextStyle(fontSize: 15, fontFamily: 'Swis1'), ), ], ), ); } static appBar(String title) { title = title ?? ''; return AppBar( backgroundColor: Colors.white, elevation: 0, scrolledUnderElevation: 0, titleSpacing: 0, title: Text(title,style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w500),), iconTheme: IconThemeData(color: Color(0XFF2A2A2A)), actions: [ Row( children: [ Padding(padding: EdgeInsets.fromLTRB(10,10,0,10), child: IconButton( icon: Image( image: AssetImage('images/customercare_appbar.png') ), onPressed: (){ }, ), ), Padding(padding: EdgeInsets.fromLTRB(0,10,10,10), child: IconButton( icon: Image.asset( 'images/notification_appbar.png', // Example URL image ), onPressed: (){ }, ), ) ], ) ], ); } static SupplierAppBar(String title,context) { title = title ?? ''; return AppBar( backgroundColor: Colors.white, elevation: 0, scrolledUnderElevation: 0, titleSpacing: 0, title: Text( title, style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w500), ), iconTheme: IconThemeData(color: Color(0XFF2A2A2A)), actions: [ Row( children: [ Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 10), child: IconButton( icon: Image( image: AssetImage('images/calender_supplier_landing.png')), onPressed: () {}, ), ), Padding( padding: EdgeInsets.fromLTRB(0, 10, 10, 10), child: IconButton( icon: Image.asset( 'images/notification_appbar.png', // Example URL image ), onPressed: () {}, ), ) ], ) ], leading: GestureDetector( onTap: () { Navigator.pop(context); }, child: Padding( padding: const EdgeInsets.fromLTRB(8, 8, 8, 8), // Add padding if needed child: Image.asset( 'images/backbutton_appbar.png', // Replace with your image path fit: BoxFit.contain, color: Color(0XFF2A2A2A), height: 24, width: 24, ), ), ), ); } static appBarWithoutActions(String title) { title = title ?? ''; return AppBar( backgroundColor: Colors.white, elevation: 0, scrolledUnderElevation: 0, titleSpacing: 0, title: Text( title, style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w500), ), iconTheme: IconThemeData(color: Color(0XFF2A2A2A)), ); } static supplierAppBarWithoutActions(String title,context) { title = title ?? ''; return AppBar( backgroundColor: Colors.white, elevation: 0, scrolledUnderElevation: 0, titleSpacing: 0, title: Text( title, style: fontTextStyle(14, Color(0XFF101214), FontWeight.w500), ), iconTheme: IconThemeData(color: Color(0XFF2A2A2A)), leading: GestureDetector( onTap: () { Navigator.pop(context); }, child: Padding( padding: const EdgeInsets.fromLTRB( 8, 8, 8, 8), // Add padding if needed child: Image.asset( 'images/backbutton_appbar.png', height: 24, width: 24,// Replace with your image path fit: BoxFit.contain, // Adjust the fit ), ), ), ); } static supplierAppBarWithActionsText(String title,context) { title = title ?? ''; return AppBar( backgroundColor: Colors.white, elevation: 0, scrolledUnderElevation: 0, titleSpacing: 0, title: Text( title, style: fontTextStyle(14, Color(0XFF101214), FontWeight.w500), ), iconTheme: IconThemeData(color: Color(0XFF2A2A2A)), leading: GestureDetector( onTap: () { Navigator.pop(context); }, child: Padding( padding: const EdgeInsets.fromLTRB( 8, 8, 8, 8), // Add padding if needed child: Image.asset( 'images/backbutton_appbar.png', height: 24, width: 24,// Replace with your image path fit: BoxFit.contain, // Adjust the fit ), ), ), actions: [ Padding(padding: EdgeInsets.all(8), child: TextButton( onPressed: () async { }, child: Text('HELP', style: fontTextStyle(14,Color(0XFF1D7AFC),FontWeight.w600),), ),) ], ); } static void longFailedToast(String message) { Fluttertoast.showToast( msg: message, toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, backgroundColor: Colors.red, textColor: Colors.white, fontSize: 16.0); } static void longSuccessToast(String message) { Fluttertoast.showToast( msg: message, toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, backgroundColor: Colors.green, textColor: Colors.white, fontSize: 16.0); } /*location*/ static checkGps() async { servicestatus = await Geolocator.isLocationServiceEnabled(); if (servicestatus) { permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { print('Location permissions are denied'); } else if (permission == LocationPermission.deniedForever) { print("'Location permissions are permanently denied"); } else { haspermission = true; } } else { haspermission = true; } if (haspermission) { /*setState(() { //refresh the UI });*/ await getLocation(); } } else { print("GPS Service is not enabled, turn on GPS location"); } } static getLocation() async { position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); /*print(position.longitude); //Output: 80.24599079 print(position.latitude);*/ //Output: 29.6593457 long = await position.longitude.toString(); lat = await position.latitude.toString(); /*setState(() { //refresh UI });*/ LocationSettings locationSettings = LocationSettings( accuracy: LocationAccuracy.high, //accuracy of the location data distanceFilter: 100, //minimum distance (measured in meters) a //device must move horizontally before an update event is generated; ); StreamSubscription positionStream = Geolocator.getPositionStream(locationSettings: locationSettings) .listen((Position position) { print(position.longitude); //Output: 80.24599079 print(position.latitude); //Output: 29.6593457 long = position.longitude.toString(); lat = position.latitude.toString(); /*setState(() { //refresh UI on update });*/ }); } }