BASE: Update Icons & Name Of The App.
This commit is contained in:
@@ -8,7 +8,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide Trans;
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart' as latlong;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
@@ -23,26 +23,39 @@ import '../themes/show_toast_dialog.dart';
|
||||
|
||||
class BookParcelController extends GetxController {
|
||||
// Sender details
|
||||
final Rx<TextEditingController> senderLocationController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> senderNameController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> senderMobileController = TextEditingController().obs;
|
||||
final Rx<SingleValueDropDownController> senderWeightController = SingleValueDropDownController().obs;
|
||||
final Rx<TextEditingController> senderNoteController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> senderCountryCodeController = TextEditingController(text: Constant.defaultCountryCode).obs;
|
||||
final Rx<TextEditingController> senderLocationController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> senderNameController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> senderMobileController =
|
||||
TextEditingController().obs;
|
||||
final Rx<SingleValueDropDownController> senderWeightController =
|
||||
SingleValueDropDownController().obs;
|
||||
final Rx<TextEditingController> senderNoteController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> senderCountryCodeController =
|
||||
TextEditingController(text: Constant.defaultCountryCode).obs;
|
||||
|
||||
// Receiver details
|
||||
final Rx<TextEditingController> receiverLocationController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverNameController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverMobileController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverNoteController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverCountryCodeController = TextEditingController(text: Constant.defaultCountryCode).obs;
|
||||
final Rx<TextEditingController> receiverLocationController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverNameController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverMobileController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverNoteController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> receiverCountryCodeController =
|
||||
TextEditingController(text: Constant.defaultCountryCode).obs;
|
||||
|
||||
// Delivery type
|
||||
final RxString selectedDeliveryType = 'now'.obs;
|
||||
|
||||
// Scheduled delivery fields
|
||||
final Rx<TextEditingController> scheduledDateController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> scheduledTimeController = TextEditingController().obs;
|
||||
final Rx<TextEditingController> scheduledDateController =
|
||||
TextEditingController().obs;
|
||||
final Rx<TextEditingController> scheduledTimeController =
|
||||
TextEditingController().obs;
|
||||
final RxString scheduledDate = ''.obs;
|
||||
final RxString scheduledTime = ''.obs;
|
||||
|
||||
@@ -83,7 +96,12 @@ class BookParcelController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> pickScheduledDate(BuildContext context) async {
|
||||
final DateTime? picked = await showDatePicker(context: context, initialDate: DateTime.now(), firstDate: DateTime.now(), lastDate: DateTime.now().add(const Duration(days: 365)));
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
);
|
||||
if (picked != null) {
|
||||
final formattedDate = "${picked.day}/${picked.month}/${picked.year}";
|
||||
scheduledDate.value = formattedDate;
|
||||
@@ -92,7 +110,10 @@ class BookParcelController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> pickScheduledTime(BuildContext context) async {
|
||||
final TimeOfDay? picked = await showTimePicker(context: context, initialTime: TimeOfDay.now());
|
||||
final TimeOfDay? picked = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
);
|
||||
if (picked != null) {
|
||||
final formattedTime = picked.format(context);
|
||||
scheduledTime.value = formattedTime;
|
||||
@@ -102,7 +123,10 @@ class BookParcelController extends GetxController {
|
||||
|
||||
void onCameraClick(BuildContext context) {
|
||||
final action = CupertinoActionSheet(
|
||||
message: Text('Add your parcel image.'.tr(), style: const TextStyle(fontSize: 15.0)),
|
||||
message: Text(
|
||||
'Add your parcel image.'.tr(),
|
||||
style: const TextStyle(fontSize: 15.0),
|
||||
),
|
||||
actions: <Widget>[
|
||||
CupertinoActionSheetAction(
|
||||
child: Text('Choose image from gallery'.tr()),
|
||||
@@ -118,14 +142,19 @@ class BookParcelController extends GetxController {
|
||||
child: Text('Take a picture'.tr()),
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
final XFile? photo = await _picker.pickImage(source: ImageSource.camera);
|
||||
final XFile? photo = await _picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
);
|
||||
if (photo != null) {
|
||||
images.add(photo);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(child: Text('Cancel'.tr()), onPressed: () => Navigator.pop(context)),
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
child: Text('Cancel'.tr()),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
);
|
||||
showCupertinoModalPopup(context: context, builder: (context) => action);
|
||||
}
|
||||
@@ -134,11 +163,18 @@ class BookParcelController extends GetxController {
|
||||
try {
|
||||
await Geolocator.requestPermission();
|
||||
final position = await Geolocator.getCurrentPosition();
|
||||
final placemarks = await placemarkFromCoordinates(position.latitude, position.longitude);
|
||||
final placemarks = await placemarkFromCoordinates(
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
);
|
||||
final place = placemarks.first;
|
||||
final address = "${place.name}, ${place.subLocality}, ${place.locality}, ${place.administrativeArea}, ${place.postalCode}, ${place.country}";
|
||||
final address =
|
||||
"${place.name}, ${place.subLocality}, ${place.locality}, ${place.administrativeArea}, ${place.postalCode}, ${place.country}";
|
||||
|
||||
final userLocation = UserLocation(latitude: position.latitude, longitude: position.longitude);
|
||||
final userLocation = UserLocation(
|
||||
latitude: position.latitude,
|
||||
longitude: position.longitude,
|
||||
);
|
||||
senderLocation.value = userLocation;
|
||||
senderLocationController.value.text = address;
|
||||
} catch (e) {
|
||||
@@ -179,7 +215,9 @@ class BookParcelController extends GetxController {
|
||||
ShowToastDialog.showToast("Please select parcel weight".tr());
|
||||
return false;
|
||||
} else if (senderLocation.value == null || receiverLocation.value == null) {
|
||||
ShowToastDialog.showToast("Please select both sender and receiver locations".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"Please select both sender and receiver locations".tr(),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -193,22 +231,37 @@ class BookParcelController extends GetxController {
|
||||
|
||||
if (Constant.selectedMapType == 'osm') {
|
||||
print("Fetching route using OSM");
|
||||
print("Sender Location: ${senderLocation.value?.latitude}, ${senderLocation.value?.longitude}");
|
||||
print("Receiver Location: ${receiverLocation.value?.latitude}, ${receiverLocation.value?.longitude}");
|
||||
print(
|
||||
"Sender Location: ${senderLocation.value?.latitude}, ${senderLocation.value?.longitude}",
|
||||
);
|
||||
print(
|
||||
"Receiver Location: ${receiverLocation.value?.latitude}, ${receiverLocation.value?.longitude}",
|
||||
);
|
||||
await fetchRouteWithWaypoints([
|
||||
latlong.LatLng(senderLocation.value?.latitude ?? 0.0, senderLocation.value?.longitude ?? 0.0),
|
||||
latlong.LatLng(receiverLocation.value?.latitude ?? 0.0, receiverLocation.value?.longitude ?? 0.0),
|
||||
latlong.LatLng(
|
||||
senderLocation.value?.latitude ?? 0.0,
|
||||
senderLocation.value?.longitude ?? 0.0,
|
||||
),
|
||||
latlong.LatLng(
|
||||
receiverLocation.value?.latitude ?? 0.0,
|
||||
receiverLocation.value?.longitude ?? 0.0,
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
await fetchGoogleRouteWithWaypoints();
|
||||
}
|
||||
|
||||
if (distance.value < 0.5) {
|
||||
ShowToastDialog.showToast("Sender's location to receiver's location should be more than 1 km.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"Sender's location to receiver's location should be more than 1 km."
|
||||
.tr(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
subTotal.value = (distance.value * double.parse(selectedWeight!.deliveryCharge.toString()));
|
||||
subTotal.value =
|
||||
(distance.value *
|
||||
double.parse(selectedWeight!.deliveryCharge.toString()));
|
||||
goToCart();
|
||||
} catch (e) {
|
||||
ShowToastDialog.showToast("Something went wrong while booking.".tr());
|
||||
@@ -217,7 +270,10 @@ class BookParcelController extends GetxController {
|
||||
}
|
||||
|
||||
void goToCart() {
|
||||
DateTime senderPickup = isScheduled.value ? parseScheduledDateTime(scheduledDate.value, scheduledTime.value) : DateTime.now();
|
||||
DateTime senderPickup =
|
||||
isScheduled.value
|
||||
? parseScheduledDateTime(scheduledDate.value, scheduledTime.value)
|
||||
: DateTime.now();
|
||||
|
||||
print("Sender Pickup: $distance");
|
||||
ParcelOrderModel order = ParcelOrderModel(
|
||||
@@ -236,22 +292,42 @@ class BookParcelController extends GetxController {
|
||||
taxSetting: Constant.taxList,
|
||||
isSchedule: isScheduled.value,
|
||||
sourcePoint: G(
|
||||
geopoint: GeoPoint(senderLocation.value!.latitude ?? 0.0, senderLocation.value!.longitude ?? 0.0),
|
||||
geohash: Geoflutterfire().point(latitude: senderLocation.value!.latitude ?? 0.0, longitude: senderLocation.value!.longitude ?? 0.0).hash,
|
||||
geopoint: GeoPoint(
|
||||
senderLocation.value!.latitude ?? 0.0,
|
||||
senderLocation.value!.longitude ?? 0.0,
|
||||
),
|
||||
geohash:
|
||||
Geoflutterfire()
|
||||
.point(
|
||||
latitude: senderLocation.value!.latitude ?? 0.0,
|
||||
longitude: senderLocation.value!.longitude ?? 0.0,
|
||||
)
|
||||
.hash,
|
||||
),
|
||||
destinationPoint: G(
|
||||
geopoint: GeoPoint(receiverLocation.value!.latitude ?? 0.0, receiverLocation.value!.longitude ?? 0.0),
|
||||
geohash: Geoflutterfire().point(latitude: receiverLocation.value!.latitude ?? 0.0, longitude: receiverLocation.value!.longitude ?? 0.0).hash,
|
||||
geopoint: GeoPoint(
|
||||
receiverLocation.value!.latitude ?? 0.0,
|
||||
receiverLocation.value!.longitude ?? 0.0,
|
||||
),
|
||||
geohash:
|
||||
Geoflutterfire()
|
||||
.point(
|
||||
latitude: receiverLocation.value!.latitude ?? 0.0,
|
||||
longitude: receiverLocation.value!.longitude ?? 0.0,
|
||||
)
|
||||
.hash,
|
||||
),
|
||||
sender: LocationInformation(
|
||||
address: senderLocationController.value.text,
|
||||
name: senderNameController.value.text,
|
||||
phone: "(${senderCountryCodeController.value.text}) ${senderMobileController.value.text}",
|
||||
phone:
|
||||
"(${senderCountryCodeController.value.text}) ${senderMobileController.value.text}",
|
||||
),
|
||||
receiver: LocationInformation(
|
||||
address: receiverLocationController.value.text,
|
||||
name: receiverNameController.value.text,
|
||||
phone: "(${receiverCountryCodeController.value.text}) ${receiverMobileController.value.text}",
|
||||
phone:
|
||||
"(${receiverCountryCodeController.value.text}) ${receiverMobileController.value.text}",
|
||||
),
|
||||
receiverLatLong: receiverLocation.value,
|
||||
senderLatLong: senderLocation.value,
|
||||
@@ -262,7 +338,10 @@ class BookParcelController extends GetxController {
|
||||
debugPrint("Subtotal: ${subTotal.value}");
|
||||
debugPrint("Order JSON: ${order.toJson()}");
|
||||
|
||||
Get.to(() => ParcelOrderConfirmationScreen(), arguments: {'parcelOrder': order, 'images': images});
|
||||
Get.to(
|
||||
() => ParcelOrderConfirmationScreen(),
|
||||
arguments: {'parcelOrder': order, 'images': images},
|
||||
);
|
||||
}
|
||||
|
||||
DateTime parseScheduledDateTime(String dateStr, String timeStr) {
|
||||
@@ -272,7 +351,10 @@ class BookParcelController extends GetxController {
|
||||
final month = int.parse(dateParts[1]);
|
||||
final year = int.parse(dateParts[2]);
|
||||
|
||||
final time = TimeOfDay(hour: int.parse(timeStr.split(':')[0]), minute: int.parse(timeStr.split(':')[1].split(' ')[0]));
|
||||
final time = TimeOfDay(
|
||||
hour: int.parse(timeStr.split(':')[0]),
|
||||
minute: int.parse(timeStr.split(':')[1].split(' ')[0]),
|
||||
);
|
||||
final isPM = timeStr.toLowerCase().contains('pm');
|
||||
final hour24 = isPM && time.hour < 12 ? time.hour + 12 : time.hour;
|
||||
|
||||
@@ -284,9 +366,13 @@ class BookParcelController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> fetchGoogleRouteWithWaypoints() async {
|
||||
final origin = '${senderLocation.value!.latitude},${senderLocation.value!.longitude}';
|
||||
final destination = '${receiverLocation.value!.latitude},${receiverLocation.value!.longitude}';
|
||||
final url = Uri.parse('https://maps.googleapis.com/maps/api/directions/json?origin=$origin&destination=$destination&mode=driving&key=${Constant.mapAPIKey}');
|
||||
final origin =
|
||||
'${senderLocation.value!.latitude},${senderLocation.value!.longitude}';
|
||||
final destination =
|
||||
'${receiverLocation.value!.latitude},${receiverLocation.value!.longitude}';
|
||||
final url = Uri.parse(
|
||||
'https://maps.googleapis.com/maps/api/directions/json?origin=$origin&destination=$destination&mode=driving&key=${Constant.mapAPIKey}',
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await http.get(url);
|
||||
@@ -315,8 +401,12 @@ class BookParcelController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> fetchRouteWithWaypoints(List<latlong.LatLng> points) async {
|
||||
final coordinates = points.map((p) => '${p.longitude},${p.latitude}').join(';');
|
||||
final url = Uri.parse('https://router.project-osrm.org/route/v1/driving/$coordinates?overview=full&geometries=geojson');
|
||||
final coordinates = points
|
||||
.map((p) => '${p.longitude},${p.latitude}')
|
||||
.join(';');
|
||||
final url = Uri.parse(
|
||||
'https://router.project-osrm.org/route/v1/driving/$coordinates?overview=full&geometries=geojson',
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await http.get(url);
|
||||
|
||||
Reference in New Issue
Block a user