save before flutter upgrade

This commit is contained in:
Abraham
2025-07-15 16:40:14 -07:00
commit 813c586a1c
197 changed files with 11144 additions and 0 deletions

View 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;
}

View 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;
}

View 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);
}

View 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';
}

View 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);
}
}

View 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;
}

View 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));
}

View 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('.');
}

View 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('.');
}

View 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;
}

View 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 ?? [],
);
}

View 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
View 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;
}