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.
122 lines
4.6 KiB
Dart
122 lines
4.6 KiB
Dart
import 'package:car_customer_app/theme/colors.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
extension EmailValidator on String {
|
|
Widget toText({Color? color, bool isBold = false, double? fontSize, bool isUnderLine = false, TextDecoration? textDecoration, double letterSpacing = -0.4, TextAlign? textAlign, double? height}) =>
|
|
Text(
|
|
this,
|
|
textAlign: textAlign,
|
|
style: TextStyle(
|
|
height: height,
|
|
decoration: textDecoration ?? TextDecoration.none,
|
|
fontSize: fontSize ?? 10,
|
|
fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
|
|
color: color ?? MyColors.darkTextColor,
|
|
letterSpacing: letterSpacing,
|
|
),
|
|
);
|
|
|
|
// Widget toText12({Color? color, bool isUnderLine = false, bool isBold = false, bool isCenter = false, int maxLine = 0}) => Text(
|
|
// this,
|
|
// textAlign: isCenter ? TextAlign.center : null,
|
|
// maxLines: (maxLine > 0) ? maxLine : null,
|
|
// style: TextStyle(
|
|
// fontSize: 12,
|
|
// fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
|
|
// color: color ?? MyColors.darkTextColor,
|
|
// letterSpacing: -0.72,
|
|
// decoration: isUnderLine ? TextDecoration.underline : null),
|
|
// );
|
|
|
|
// Widget toText13({Color? color, bool isUnderLine = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: color ?? MyColors.darkTextColor, letterSpacing: -0.52, decoration: isUnderLine ? TextDecoration.underline : null),
|
|
// );
|
|
|
|
// Widget toText14({
|
|
// Color? color,
|
|
// bool isBold = false,
|
|
// TextAlign? textAlign,
|
|
// }) =>
|
|
// Text(
|
|
// this,
|
|
// textAlign: textAlign,
|
|
// style: TextStyle(color: color ?? MyColors.darkTextColor, fontSize: 14, letterSpacing: -0.48, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
// Widget toText16({Color? color, bool isBold = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(color: color ?? MyColors.darkTextColor, fontSize: 16, letterSpacing: -0.64, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
// Widget toText17({Color? color, bool isBold = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(color: color ?? MyColors.darkTextColor, fontSize: 17, letterSpacing: -0.68, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
// Widget toText20({Color? color, bool isBold = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(height: 23 / 24, color: color ?? MyColors.darkTextColor, fontSize: 20, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
// Widget toText22({Color? color, bool isBold = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(height: 1, color: color ?? MyColors.darkTextColor, fontSize: 22, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
// Widget toText24({Color? color, bool isBold = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(height: 23 / 24, fontSize: 24, letterSpacing: -1.44, color: color ?? MyColors.darkTextColor, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
// Widget toText32({Color? color, bool isBold = false}) => Text(
|
|
// this,
|
|
// style: TextStyle(height: 32 / 32, color: color ?? MyColors.darkTextColor, fontSize: 32, letterSpacing: -1.92, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
|
|
// );
|
|
|
|
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);
|
|
}
|
|
|
|
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').format(DateFormat('hh:mm:ss').parse(time))}";
|
|
}
|
|
|
|
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";
|
|
}
|
|
}
|
|
}
|