save before flutter upgrade
This commit is contained in:
12
lib/functions/check_password.dart
Normal file
12
lib/functions/check_password.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
String? checkPassword(String password) {
|
||||
if (password.length < 8) {
|
||||
return 'La contraseña debe tener al menos 8 caracteres';
|
||||
}
|
||||
final RegExp regex =
|
||||
RegExp(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$');
|
||||
final RegExpMatch? match = regex.firstMatch(password);
|
||||
if (match == null) {
|
||||
return 'La contraseña debe tener al menos un número, una letra mayúscula, una letra minúscula, un caracter especial y no debe tener números ni letras consecutivas';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
104
lib/functions/date_format.dart
Normal file
104
lib/functions/date_format.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String dateFormat(
|
||||
dynamic x, // Acepta DateTime o String
|
||||
[
|
||||
bool includeTime = false,
|
||||
bool includeDayName = true,
|
||||
bool includeTimeAgo = false,
|
||||
String language = 'es_MX',
|
||||
]) {
|
||||
DateTime? date;
|
||||
|
||||
// Verifica si es una cadena de fecha y conviértela a DateTime
|
||||
if (x is String) {
|
||||
date = DateTime.tryParse(x);
|
||||
} else if (x is DateTime) {
|
||||
date = x;
|
||||
}
|
||||
|
||||
if (date == null) return '-';
|
||||
|
||||
// Convierte a hora local
|
||||
date = date.toLocal();
|
||||
|
||||
String formattedDate;
|
||||
|
||||
// Formatea la fecha
|
||||
if (!includeTime) {
|
||||
if (includeDayName) {
|
||||
|
||||
formattedDate = DateFormat('EEE. dd/MMM/yyyy', language).format(date);
|
||||
}
|
||||
else{
|
||||
formattedDate = DateFormat('dd/MMM/yyyy', language).format(date);
|
||||
}
|
||||
} else {
|
||||
formattedDate = DateFormat('EEE. dd/MMM/yyyy HH:mm', language).format(date);
|
||||
}
|
||||
|
||||
// Capitaliza la primera letra del día
|
||||
List<String> parts = formattedDate.split(' ');
|
||||
|
||||
if (parts.isNotEmpty) {
|
||||
parts[0] = parts[0][0].toUpperCase() + parts[0].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
// Capitaliza la primera letra del mes
|
||||
if (parts.length >= 2) {
|
||||
String datePart = parts[1]; // "dd/MMM/yyyy" o "dd/MMM/yyyy HH:mm"
|
||||
List<String> dateComponents = datePart.split('/');
|
||||
|
||||
if (dateComponents.length >= 2) {
|
||||
// Capitaliza el mes
|
||||
dateComponents[1] = dateComponents[1][0].toUpperCase() +
|
||||
dateComponents[1].substring(1).toLowerCase();
|
||||
parts[1] = dateComponents.join('/');
|
||||
}
|
||||
}
|
||||
|
||||
formattedDate = parts.join(' ');
|
||||
|
||||
// Manejo de includeTimeAgo
|
||||
if (includeTimeAgo) {
|
||||
final Duration difference = DateTime.now().difference(date);
|
||||
String timeAgo = '';
|
||||
|
||||
if (difference.isNegative) {
|
||||
timeAgo = '\n(hace 0 segundos)';
|
||||
} else {
|
||||
if (difference.inSeconds < 60) {
|
||||
timeAgo = '\n(hace ${difference.inSeconds} segundos)';
|
||||
} else if (difference.inMinutes < 60) {
|
||||
timeAgo = '\n(hace ${difference.inMinutes} minutos)';
|
||||
} else if (difference.inHours < 48) {
|
||||
timeAgo = '\n(hace ${difference.inHours} horas)';
|
||||
} else if (difference.inDays <= 30) {
|
||||
timeAgo = '\n(hace ${difference.inDays} días)';
|
||||
} else if (difference.inDays > 30) {
|
||||
timeAgo = '\n(hace ${difference.inDays ~/ 30} meses)';
|
||||
}
|
||||
}
|
||||
|
||||
formattedDate = '$formattedDate $timeAgo';
|
||||
}
|
||||
|
||||
return formattedDate;
|
||||
}
|
||||
|
||||
// Definir una lista de nombres de los días de la semana
|
||||
List<String> daysOfWeek = [
|
||||
'Lunes',
|
||||
'Martes',
|
||||
'Miércoles',
|
||||
'Jueves',
|
||||
'Viernes',
|
||||
'Sábado',
|
||||
'Domingo'
|
||||
];
|
||||
|
||||
// Obtener el nombre del día de la semana
|
||||
String getDayName(DateTime now) {
|
||||
String dayName = daysOfWeek[now.weekday - 1];
|
||||
return dayName;
|
||||
}
|
||||
9
lib/functions/date_time_format.dart
Normal file
9
lib/functions/date_time_format.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String dateTimeFormat(DateTime? date) {
|
||||
if (date == null) {
|
||||
return '-';
|
||||
}
|
||||
final formato = DateFormat('MM-dd-yyyy HH:mm:ss');
|
||||
return formato.format(date);
|
||||
}
|
||||
11
lib/functions/day_month_format.dart
Normal file
11
lib/functions/day_month_format.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String dayMothFormat(DateTime fecha) {
|
||||
String dia = DateFormat('d').format(fecha);
|
||||
|
||||
String mes = DateFormat('MMM', 'es').format(fecha);
|
||||
mes = mes[0].toUpperCase() + mes.substring(1);
|
||||
mes = mes.replaceAll('.', '');
|
||||
|
||||
return '$dia $mes';
|
||||
}
|
||||
8
lib/functions/double_extensions.dart
Normal file
8
lib/functions/double_extensions.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'dart:math';
|
||||
|
||||
extension Precision on double {
|
||||
double toPrecision(int fractionDigits) {
|
||||
var mod = pow(10, fractionDigits.toDouble()).toDouble();
|
||||
return ((this * mod).round().toDouble() / mod);
|
||||
}
|
||||
}
|
||||
13
lib/functions/extract_number_from_text.dart
Normal file
13
lib/functions/extract_number_from_text.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
int? extractNumberFromText(String text) {
|
||||
// Expresión regular para encontrar el primer número en el texto
|
||||
RegExp regExp = RegExp(r'\d+');
|
||||
Match? match = regExp.firstMatch(text);
|
||||
|
||||
// Si se encuentra un número, devolverlo como un entero
|
||||
if (match != null) {
|
||||
return int.tryParse(match.group(0) ?? '');
|
||||
}
|
||||
|
||||
// Si no se encuentra ningún número, devolver null
|
||||
return null;
|
||||
}
|
||||
4
lib/functions/form_textfield_width.dart
Normal file
4
lib/functions/form_textfield_width.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
double formTextFieldWidth(double anchoPantalla, double anchoMin, double anchoMax, double valorMin, double valorMax) {
|
||||
// Fórmula de interpolación lineal para calcular tamaños adaptativos.
|
||||
return valorMin + (valorMax - valorMin) * ((anchoPantalla - anchoMin) / (anchoMax - anchoMin));
|
||||
}
|
||||
12
lib/functions/money_format.dart
Normal file
12
lib/functions/money_format.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
String moneyFormat(double x) {
|
||||
List<String> parts = x.toString().split('.');
|
||||
RegExp re = RegExp(r'\B(?=(\d{3})+(?!\d))');
|
||||
|
||||
parts[0] = parts[0].replaceAll(re, ',');
|
||||
if (parts.length == 1) {
|
||||
parts.add('00');
|
||||
} else {
|
||||
parts[1] = parts[1].padRight(2, '0').substring(0, 2);
|
||||
}
|
||||
return parts.join('.');
|
||||
}
|
||||
12
lib/functions/money_format_3_decimals.dart
Normal file
12
lib/functions/money_format_3_decimals.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
String moneyFormat3Decimals(double x) {
|
||||
List<String> parts = x.toString().split('.');
|
||||
RegExp re = RegExp(r'\B(?=(\d{3})+(?!\d))');
|
||||
|
||||
parts[0] = parts[0].replaceAll(re, ',');
|
||||
if (parts.length == 1) {
|
||||
parts.add('00');
|
||||
} else {
|
||||
parts[1] = parts[1].padRight(3, '0').substring(0, 3);
|
||||
}
|
||||
return parts.join('.');
|
||||
}
|
||||
11
lib/functions/month_name.dart
Normal file
11
lib/functions/month_name.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String monthName(int mes) {
|
||||
DateTime dateTime = DateTime(DateTime.now().year, mes);
|
||||
|
||||
String value = DateFormat('MMMM', 'es').format(dateTime);
|
||||
|
||||
value = value[0].toUpperCase() + value.substring(1);
|
||||
|
||||
return value;
|
||||
}
|
||||
15
lib/functions/no_transition_route.dart
Normal file
15
lib/functions/no_transition_route.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
GoRoute noTransitionRoute(String path, String name, Widget Function(BuildContext, GoRouterState) builder, {List<GoRoute>? subroutes}) {
|
||||
return GoRoute(
|
||||
path: path,
|
||||
name: name,
|
||||
pageBuilder: (context, state) {
|
||||
return NoTransitionPage(
|
||||
child: builder(context, state),
|
||||
);
|
||||
},
|
||||
routes: subroutes ?? [],
|
||||
);
|
||||
}
|
||||
4
lib/functions/phone_format.dart
Normal file
4
lib/functions/phone_format.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
String formatPhone(String phone) {
|
||||
if (phone.length != 10) return phone;
|
||||
return '(${phone.substring(0, 3)}) ${phone.substring(3, 6)} ${phone.substring(6, 8)} ${phone.substring(8, 10)}';
|
||||
}
|
||||
20
lib/functions/tokens.dart
Normal file
20
lib/functions/tokens.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
import 'package:nethive_neo/models/models.dart';
|
||||
|
||||
Token? parseToken(String token) {
|
||||
try {
|
||||
// Verify a token
|
||||
final jwt = JWT.verify(token, SecretKey('secret'));
|
||||
return Token.fromJson(json.encode(jwt.payload), token);
|
||||
} on JWTExpiredException {
|
||||
log('JWT expirada');
|
||||
} on JWTException catch (ex) {
|
||||
log('Error en checkToken - $ex');
|
||||
} on Exception {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user