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.
mohemm-flutter-app/lib/extensions/string_extensions.dart

127 lines
3.7 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
extension EmailValidator on String {
Widget get toWidget => Text(this);
Widget toText10({Color? color, bool isBold = false}) => Text(
this,
style: TextStyle(
fontSize: 10,
fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
color: color ?? MyColors.darkTextColor,
letterSpacing: -0.4),
);
Widget toText11(
{Color? color, bool isUnderLine = false, bool isBold = false}) =>
Text(
this,
style: TextStyle(
fontSize: 11,
fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
color: color ?? MyColors.darkTextColor,
letterSpacing: -0.33,
decoration: isUnderLine ? TextDecoration.underline : null),
);
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}) => Text(
this,
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 toText24({bool isBold = false, Color? textColor}) => Text(
this,
style: TextStyle(
height: 23 / 24,
color: textColor ?? MyColors.darkTextColor,
fontSize: 24,
letterSpacing: -1.44,
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);
}
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";
}
}
}