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

62 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
extension StringExtension on String {
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);
}
String toFormattedDate() {
String date = this.split("T")[0];
String time = this.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";
}
}
Widget toText(double fontSize, {Color color, bool isBold = false, int maxLines, FontStyle fontStyle, TextAlign textAlign, double height, bool fontFamily = true}) {
double heightVal = height ?? ((fontSize == 13) ? 16 : ((fontSize == 18 || fontSize == 30) ? 22 : 14));
return Text(
this,
maxLines: maxLines,
textAlign: textAlign,
style: TextStyle(
fontSize: fontSize ?? 14,
fontStyle: fontStyle ?? FontStyle.normal,
fontWeight: isBold ? FontWeight.bold : FontWeight.w400,
color: color ?? Colors.white,
fontFamily: fontFamily ? "Montserrat" : null,
height: heightVal / fontSize,
),
);
}
}