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.
cloudsolutions-atoms/lib/extensions/string_extensions.dart

93 lines
2.4 KiB
Dart

import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
extension StringExtensions on String {
String get addTranslation => this;
void get showToast => Fluttertoast.showToast(msg: this);
String get toServiceRequestCardFormat {
DateTime dateTime = DateTime.parse(this);
return "${DateFormat('dd MMM, yyyy').format(dateTime)}\n${DateFormat('hh:mm a').format(dateTime)}";
}
String get toDragAbleTimerFormat {
DateTime dateTime = DateTime.parse(this);
return DateFormat('HH:mm:ss').format(dateTime);
}
String get toInitialVisitCardFormat {
DateTime dateTime = DateTime.parse(this);
return "${DateFormat('dd MMM, yyyy').format(dateTime)} at ${DateFormat('hh:mm a').format(dateTime)}";
}
String get toServiceRequestDetailsFormat {
try {
DateTime dateTime = DateTime.parse(this);
return "${DateFormat('dd MMM, yyyy').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}";
} catch (e) {
return "";
}
}
String get toServiceRequestDetailsFormatWithSS {
try {
DateTime dateTime = DateTime.parse(this);
return "${DateFormat('dd MMM, yyyy').format(dateTime)} ${DateFormat('hh:mm:ss a').format(dateTime)}";
} catch (e) {
return "";
}
}
String get toFirstActionFormat {
try {
DateTime dateTime = DateTime.parse(this);
return "${DateFormat('yyyy-MM-dd').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}";
} catch (e) {
return "";
}
}
String get toYMDHMSA {
try {
DateTime dateTime = DateTime.parse(this);
return "${DateFormat('yyyy-MM-dd').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}";
} catch (e) {
return "";
}
}
String get toMonthYearFormat {
try {
DateTime dateTime = DateTime.parse(this);
String formattedDate = DateFormat('MMMM d, y').format(dateTime);
return formattedDate;
} catch (e) {
return "";
}
}
String get toAssetDetailsFormat {
try {
DateTime dateTime = DateTime.parse(this);
return DateFormat('dd MMM, yyyy').format(dateTime);
} catch (e) {
return "-";
}
}
String get getFileName {
try {
if (contains("fileName=")) {
String sub = substring(indexOf("fileName="), length);
sub = sub.replaceAll("fileName=", "");
return sub;
} else {
return this;
}
} catch (e) {
return this;
}
}
}