You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
614 lines
15 KiB
Dart
614 lines
15 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
extension EmailValidator on String {
|
|
Widget toText(
|
|
{Color? color,
|
|
bool isBold = false,
|
|
double? fontSize,
|
|
bool isUnderLine = false,
|
|
bool isItalic = false,
|
|
TextDecoration? textDecoration,
|
|
double letterSpacing = -0.4,
|
|
TextAlign? textAlign,
|
|
FontWeight? fontWeight,
|
|
double? height,
|
|
int? maxLines}) =>
|
|
AutoSizeText(
|
|
this,
|
|
textAlign: textAlign,
|
|
maxLines: maxLines,
|
|
style: TextStyle(
|
|
fontStyle: isItalic ? FontStyle.italic : null,
|
|
height: height,
|
|
decoration: isUnderLine ? TextDecoration.underline : textDecoration ?? TextDecoration.none,
|
|
fontSize: fontSize ?? 10,
|
|
fontWeight: isBold ? FontWeight.bold : fontWeight ?? FontWeight.w600,
|
|
color: color ?? MyColors.darkTextColor,
|
|
letterSpacing: letterSpacing,
|
|
),
|
|
);
|
|
|
|
bool isValidEmail() {
|
|
return RegExp(r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').hasMatch(this);
|
|
}
|
|
|
|
bool isNum() {
|
|
return RegExp(r'^[0-9]+$').hasMatch(this);
|
|
}
|
|
|
|
getMonth(int month) {
|
|
switch (month) {
|
|
case 1:
|
|
return "January";
|
|
case 2:
|
|
return "February";
|
|
case 3:
|
|
return "March";
|
|
case 4:
|
|
return "April";
|
|
case 5:
|
|
return "May";
|
|
case 6:
|
|
return "June";
|
|
case 7:
|
|
return "July";
|
|
case 8:
|
|
return "August";
|
|
case 9:
|
|
return "September";
|
|
case 10:
|
|
return "October";
|
|
case 11:
|
|
return "November";
|
|
case 12:
|
|
return "December";
|
|
}
|
|
}
|
|
}
|
|
|
|
extension FormatDate on String {
|
|
/// get month by
|
|
/// [month] convert month number in to month name
|
|
/// get month by
|
|
/// [month] convert month number in to month name in Arabic
|
|
static String getMonthArabic(int month) {
|
|
switch (month) {
|
|
case 1:
|
|
return "يناير";
|
|
case 2:
|
|
return " فبراير";
|
|
case 3:
|
|
return "مارس";
|
|
case 4:
|
|
return "أبريل";
|
|
case 5:
|
|
return "مايو";
|
|
case 6:
|
|
return "يونيو";
|
|
case 7:
|
|
return "يوليو";
|
|
case 8:
|
|
return "أغسطس";
|
|
case 9:
|
|
return "سبتمبر";
|
|
case 10:
|
|
return " اكتوبر";
|
|
case 11:
|
|
return " نوفمبر";
|
|
case 12:
|
|
return "ديسمبر";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
static String getMonth(int month) {
|
|
switch (month) {
|
|
case 1:
|
|
return "January";
|
|
case 2:
|
|
return "February";
|
|
case 3:
|
|
return "March";
|
|
case 4:
|
|
return "April";
|
|
case 5:
|
|
return "May";
|
|
case 6:
|
|
return "June";
|
|
case 7:
|
|
return "July";
|
|
case 8:
|
|
return "August";
|
|
case 9:
|
|
return "September";
|
|
case 10:
|
|
return "October";
|
|
case 11:
|
|
return "November";
|
|
case 12:
|
|
return "December";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
String toFormattedDate() {
|
|
String date = split("T")[0];
|
|
String time = split("T")[1];
|
|
var dates = date.split("-");
|
|
return "${dates[2]} ${getMonth(int.parse(dates[1]))} ${dates[0]} ${DateFormat('hh:mm a', "en_US").format(DateFormat('hh:mm:ss', "en_US").parse(time))}";
|
|
}
|
|
|
|
String toFormattedDateWithoutTime() {
|
|
String date = split("T")[0];
|
|
var dates = date.split("-");
|
|
return "${dates[2]} ${getMonth(int.parse(dates[1]))}, ${dates[0]}";
|
|
}
|
|
}
|
|
|
|
extension RequestEnum on int {
|
|
RequestStatus toRequestStatusEnum() {
|
|
if (this == 1) {
|
|
return RequestStatus.submitted;
|
|
} else if (this == 2) {
|
|
return RequestStatus.inProgress;
|
|
} else if (this == 3) {
|
|
return RequestStatus.completed;
|
|
} else if (this == 4) {
|
|
return RequestStatus.cancelled;
|
|
} else if (this == 5) {
|
|
return RequestStatus.paid;
|
|
} else if (this == 6) {
|
|
return RequestStatus.expired;
|
|
} else if (this == 7) {
|
|
return RequestStatus.shipping;
|
|
} else {
|
|
return RequestStatus.pending;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AdPostEnum on int {
|
|
AdPostStatus toAdPostEnum() {
|
|
if (this == 1) {
|
|
return AdPostStatus.pendingForReview;
|
|
} else if (this == 2) {
|
|
return AdPostStatus.pendingForPayment;
|
|
} else if (this == 3) {
|
|
return AdPostStatus.rejected;
|
|
} else if (this == 4) {
|
|
return AdPostStatus.cancelled;
|
|
} else if (this == 5) {
|
|
return AdPostStatus.pendingForPost;
|
|
} else if (this == 6) {
|
|
return AdPostStatus.active;
|
|
} else if (this == 7) {
|
|
return AdPostStatus.expired;
|
|
} else if (this == 8) {
|
|
return AdPostStatus.sold;
|
|
} else if (this == 9) {
|
|
return AdPostStatus.reserved;
|
|
} else if (this == 10) {
|
|
return AdPostStatus.buyingService;
|
|
} else if (this == 11) {
|
|
return AdPostStatus.reserveCancel;
|
|
} else if (this == 0) {
|
|
return AdPostStatus.allAds;
|
|
} else {
|
|
return AdPostStatus.pendingForPost;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AppointmentEnum on int {
|
|
AppointmentStatusEnum toAppointmentStatusEnum() {
|
|
if (this == 1) {
|
|
return AppointmentStatusEnum.booked;
|
|
} else if (this == 2) {
|
|
return AppointmentStatusEnum.confirmed;
|
|
} else if (this == 3) {
|
|
return AppointmentStatusEnum.arrived;
|
|
} else if (this == 4) {
|
|
return AppointmentStatusEnum.cancelled;
|
|
} else if (this == 5) {
|
|
return AppointmentStatusEnum.rescheduled;
|
|
} else {
|
|
return AppointmentStatusEnum.allAppointments;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension RequestTypeTypeEnum on int {
|
|
RequestsTypeEnum toRequestTypeStatusEnum() {
|
|
if (this == 1) {
|
|
return RequestsTypeEnum.specialCarRequest;
|
|
} else if (this == 2) {
|
|
return RequestsTypeEnum.serviceRequest;
|
|
}
|
|
return RequestsTypeEnum.specialCarRequest;
|
|
}
|
|
}
|
|
|
|
extension RequestTypeStatusToInt on RequestsTypeEnum {
|
|
int getIdFromRequestTypeStatusEnum() {
|
|
switch (this) {
|
|
case RequestsTypeEnum.specialCarRequest:
|
|
return 1;
|
|
|
|
case RequestsTypeEnum.serviceRequest:
|
|
return 2;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AdPostStatusToInt on AdPostStatus {
|
|
int getIdFromAdPostStatusEnum() {
|
|
switch (this) {
|
|
case AdPostStatus.pendingForReview:
|
|
return 1;
|
|
case AdPostStatus.pendingForPayment:
|
|
return 2;
|
|
|
|
case AdPostStatus.rejected:
|
|
return 3;
|
|
|
|
case AdPostStatus.cancelled:
|
|
return 4;
|
|
|
|
case AdPostStatus.pendingForPost:
|
|
return 5;
|
|
|
|
case AdPostStatus.active:
|
|
return 6;
|
|
|
|
case AdPostStatus.expired:
|
|
return 7;
|
|
|
|
case AdPostStatus.sold:
|
|
return 8;
|
|
|
|
case AdPostStatus.reserved:
|
|
return 9;
|
|
|
|
case AdPostStatus.buyingService:
|
|
return 10;
|
|
|
|
case AdPostStatus.reserveCancel:
|
|
return 11;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension PaymentTypesToInt on PaymentTypes {
|
|
int getIdFromPaymentTypesEnum() {
|
|
switch (this) {
|
|
case PaymentTypes.subscription:
|
|
return 1;
|
|
|
|
case PaymentTypes.appointment:
|
|
return 2;
|
|
|
|
case PaymentTypes.adReserve:
|
|
return 4;
|
|
|
|
case PaymentTypes.ads:
|
|
return 3;
|
|
|
|
case PaymentTypes.request:
|
|
return 5;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AppointmentStatusToInt on AppointmentStatusEnum {
|
|
int getIdFromAppointmentStatusEnum() {
|
|
switch (this) {
|
|
case AppointmentStatusEnum.booked:
|
|
return 1;
|
|
|
|
case AppointmentStatusEnum.confirmed:
|
|
return 2;
|
|
|
|
case AppointmentStatusEnum.arrived:
|
|
return 3;
|
|
|
|
case AppointmentStatusEnum.cancelled:
|
|
return 4;
|
|
|
|
case AppointmentStatusEnum.rescheduled:
|
|
return 5;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension CreatedByRoleEnumToInt on CreatedByRoleEnum {
|
|
int getIdFromCreatedByRoleEnum() {
|
|
switch (this) {
|
|
case CreatedByRoleEnum.admin:
|
|
return 1;
|
|
case CreatedByRoleEnum.customer:
|
|
return 2;
|
|
case CreatedByRoleEnum.provider:
|
|
return 3;
|
|
case CreatedByRoleEnum.allAds:
|
|
return 0;
|
|
default:
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AdReserveStatusEnum on int {
|
|
AdReserveStatus toAdRserveStatusEnum() {
|
|
if (this == 0) {
|
|
return AdReserveStatus.defaultStatus;
|
|
} else if (this == 1) {
|
|
return AdReserveStatus.reserved;
|
|
} else if (this == 2) {
|
|
return AdReserveStatus.cancelledByOwner;
|
|
} else if (this == 3) {
|
|
return AdReserveStatus.cancelledByAdmin;
|
|
} else {
|
|
return AdReserveStatus.defaultStatus;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AdOwnerEnum on int {
|
|
CreatedByRoleEnum toCreatedByRoleEnum() {
|
|
if (this == 0) {
|
|
return CreatedByRoleEnum.allAds;
|
|
} else if (this == 1) {
|
|
return CreatedByRoleEnum.admin;
|
|
} else if (this == 2) {
|
|
return CreatedByRoleEnum.customer;
|
|
} else if (this == 3) {
|
|
return CreatedByRoleEnum.provider;
|
|
}
|
|
return CreatedByRoleEnum.customer;
|
|
}
|
|
}
|
|
|
|
extension BranchsEnum on int {
|
|
BranchStatusEnum toBranchStatusEnum() {
|
|
if (this == 1) {
|
|
return BranchStatusEnum.pending;
|
|
} else if (this == 2) {
|
|
return BranchStatusEnum.review;
|
|
} else if (this == 3) {
|
|
return BranchStatusEnum.approvedOrActive;
|
|
} else if (this == 4) {
|
|
return BranchStatusEnum.rejected;
|
|
} else if (this == 5) {
|
|
return BranchStatusEnum.blocked;
|
|
} else if (this == 6) {
|
|
return BranchStatusEnum.deactivated;
|
|
} else {
|
|
return BranchStatusEnum.pending;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension ServiceEnum on int {
|
|
ServiceStatusEnum toServiceStatusEnum() {
|
|
if (this == 1) {
|
|
return ServiceStatusEnum.pending;
|
|
} else if (this == 2) {
|
|
return ServiceStatusEnum.review;
|
|
} else if (this == 3) {
|
|
return ServiceStatusEnum.approvedOrActive;
|
|
} else if (this == 4) {
|
|
return ServiceStatusEnum.rejected;
|
|
} else if (this == 5) {
|
|
return ServiceStatusEnum.blocked;
|
|
} else if (this == 6) {
|
|
return ServiceStatusEnum.deactivated;
|
|
} else {
|
|
return ServiceStatusEnum.pending;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension DateTimeConversions on DateTime {
|
|
String getTimeAgo({bool numericDates = true}) {
|
|
final date2 = DateTime.now();
|
|
final difference = date2.difference(this);
|
|
|
|
if ((difference.inDays / 7).floor() >= 1) {
|
|
return (numericDates) ? '1 week ago' : 'Last week';
|
|
} else if (difference.inDays >= 2) {
|
|
return '${difference.inDays} days ago';
|
|
} else if (difference.inDays >= 1) {
|
|
return (numericDates) ? '1 day ago' : 'Yesterday';
|
|
} else if (difference.inHours >= 2) {
|
|
return '${difference.inHours} hours ago';
|
|
} else if (difference.inHours >= 1) {
|
|
return (numericDates) ? '1 hour ago' : 'An hour ago';
|
|
} else if (difference.inMinutes >= 2) {
|
|
return '${difference.inMinutes} minutes ago';
|
|
} else if (difference.inMinutes >= 1) {
|
|
return (numericDates) ? '1 minute ago' : 'A minute ago';
|
|
} else if (difference.inSeconds >= 3) {
|
|
return '${difference.inSeconds} seconds ago';
|
|
} else {
|
|
return 'Just now';
|
|
}
|
|
}
|
|
}
|
|
|
|
extension VehicleAdTypeEnum on int {
|
|
VehicleType toVehicleTypeEnum() {
|
|
if (this == 1) {
|
|
return VehicleType.car;
|
|
} else if (this == 2) {
|
|
return VehicleType.motorCycle;
|
|
} else if (this == 3) {
|
|
return VehicleType.golfCart;
|
|
} else if (this == 4) {
|
|
return VehicleType.buggy;
|
|
} else {
|
|
return VehicleType.car;
|
|
}
|
|
}
|
|
|
|
String toVehicleTypeString() {
|
|
if (this == 1) {
|
|
return "Car";
|
|
} else if (this == 2) {
|
|
return "Motorcycle";
|
|
} else if (this == 3) {
|
|
return "Golf Cart";
|
|
} else if (this == 4) {
|
|
return "Buggy";
|
|
} else {
|
|
return "Car";
|
|
}
|
|
}
|
|
}
|
|
|
|
extension FormatMonthByName on int {
|
|
String getMonthNameByNumber() {
|
|
switch (this) {
|
|
case 1:
|
|
return "January";
|
|
case 2:
|
|
return "February";
|
|
case 3:
|
|
return "March";
|
|
case 4:
|
|
return "April";
|
|
case 5:
|
|
return "May";
|
|
case 6:
|
|
return "June";
|
|
case 7:
|
|
return "July";
|
|
case 8:
|
|
return "August";
|
|
case 9:
|
|
return "September";
|
|
case 10:
|
|
return "October";
|
|
case 11:
|
|
return "November";
|
|
case 12:
|
|
return "December";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
extension FormatMonthByNumber on String {
|
|
int getMonthNumberByName() {
|
|
switch (this) {
|
|
case "January":
|
|
return 1;
|
|
case "February":
|
|
return 2;
|
|
case "March":
|
|
return 3;
|
|
case "April":
|
|
return 4;
|
|
case "May":
|
|
return 5;
|
|
case "June":
|
|
return 6;
|
|
case "July":
|
|
return 7;
|
|
case "August":
|
|
return 8;
|
|
case "September":
|
|
return 9;
|
|
case "October":
|
|
return 10;
|
|
case "November":
|
|
return 11;
|
|
case "December":
|
|
return 12;
|
|
default:
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension ChatMessageTypeEnumExt on int {
|
|
ChatMessageTypeEnum toChatMessageTypeEnum() {
|
|
if (this == 1) {
|
|
return ChatMessageTypeEnum.freeText;
|
|
} else if (this == 2) {
|
|
return ChatMessageTypeEnum.freeText;
|
|
}
|
|
return ChatMessageTypeEnum.freeText;
|
|
}
|
|
}
|
|
|
|
extension ChatMessageTypeToInt on ChatMessageTypeEnum {
|
|
int getIdFromChatMessageTypeEnum() {
|
|
switch (this) {
|
|
case ChatMessageTypeEnum.freeText:
|
|
return 1;
|
|
|
|
case ChatMessageTypeEnum.offer:
|
|
return 2;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
extension RequestOfferStatusEnumExt on int {
|
|
RequestOfferStatusEnum toChatMessageTypeEnum() {
|
|
if (this == 1) {
|
|
return RequestOfferStatusEnum.offer;
|
|
} else if (this == 2) {
|
|
return RequestOfferStatusEnum.negotiate;
|
|
} else if (this == 3) {
|
|
return RequestOfferStatusEnum.accepted;
|
|
} else if (this == 4) {
|
|
return RequestOfferStatusEnum.rejected;
|
|
} else if (this == 5) {
|
|
return RequestOfferStatusEnum.cancel;
|
|
}
|
|
return RequestOfferStatusEnum.cancel;
|
|
}
|
|
}
|
|
|
|
extension RequestOfferStatusEnumToInt on RequestOfferStatusEnum {
|
|
int getIdFromRequestOfferStatusEnum() {
|
|
switch (this) {
|
|
case RequestOfferStatusEnum.offer:
|
|
return 1;
|
|
case RequestOfferStatusEnum.negotiate:
|
|
return 2;
|
|
case RequestOfferStatusEnum.accepted:
|
|
return 3;
|
|
case RequestOfferStatusEnum.rejected:
|
|
return 4;
|
|
case RequestOfferStatusEnum.cancel:
|
|
return 5;
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
}
|