add auth, format

This commit is contained in:
Phuoc Nguyen
2025-11-07 11:52:06 +07:00
parent 24a8508fce
commit 3803bd26e0
173 changed files with 8505 additions and 7116 deletions

View File

@@ -423,16 +423,14 @@ extension BuildContextExtensions on BuildContext {
/// Navigate to route
Future<T?> push<T>(Widget page) {
return Navigator.of(this).push<T>(
MaterialPageRoute(builder: (_) => page),
);
return Navigator.of(this).push<T>(MaterialPageRoute(builder: (_) => page));
}
/// Navigate and replace current route
Future<T?> pushReplacement<T>(Widget page) {
return Navigator.of(this).pushReplacement<T, void>(
MaterialPageRoute(builder: (_) => page),
);
return Navigator.of(
this,
).pushReplacement<T, void>(MaterialPageRoute(builder: (_) => page));
}
/// Pop current route

View File

@@ -313,15 +313,21 @@ class TextFormatter {
}
/// Truncate text with ellipsis
static String truncate(String text, int maxLength, {String ellipsis = '...'}) {
static String truncate(
String text,
int maxLength, {
String ellipsis = '...',
}) {
if (text.length <= maxLength) return text;
return text.substring(0, maxLength - ellipsis.length) + ellipsis;
}
/// Remove diacritics from Vietnamese text
static String removeDiacritics(String text) {
const withDiacritics = 'àáạảãâầấậẩẫăằắặẳẵèéẹẻẽêềếệểễìíịỉĩòóọỏõôồốộổỗơờớợởỡùúụủũưừứựửữỳýỵỷỹđ';
const withoutDiacritics = 'aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiioooooooooooooooooouuuuuuuuuuuyyyyyd';
const withDiacritics =
'àáạảãâầấậẩẫăằắặẳẵèéẹẻẽêềếệểễìíịỉĩòóọỏõôồốộổỗơờớợởỡùúụủũưừứựửữỳýỵỷỹđ';
const withoutDiacritics =
'aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiioooooooooooooooooouuuuuuuuuuuyyyyyd';
var result = text.toLowerCase();
for (var i = 0; i < withDiacritics.length; i++) {

View File

@@ -241,8 +241,11 @@ class L10nHelper {
/// final pointsText = L10nHelper.formatPoints(context, 100);
/// // Returns: "+100 điểm" (Vietnamese) or "+100 points" (English)
/// ```
static String formatPoints(BuildContext context, int points,
{bool showSign = true}) {
static String formatPoints(
BuildContext context,
int points, {
bool showSign = true,
}) {
if (showSign && points > 0) {
return context.l10n.earnedPoints(points);
} else if (showSign && points < 0) {

View File

@@ -66,9 +66,7 @@ class QRGenerator {
),
padding: const EdgeInsets.all(16),
gapless: true,
embeddedImageStyle: const QrEmbeddedImageStyle(
size: Size(48, 48),
),
embeddedImageStyle: const QrEmbeddedImageStyle(size: Size(48, 48)),
);
}
@@ -189,9 +187,7 @@ class QRGenerator {
embeddedImage: embeddedImage is AssetImage
? (embeddedImage as AssetImage).assetName as ImageProvider
: null,
embeddedImageStyle: QrEmbeddedImageStyle(
size: embeddedImageSize,
),
embeddedImageStyle: QrEmbeddedImageStyle(size: embeddedImageSize),
);
}
@@ -203,18 +199,12 @@ class QRGenerator {
if (data.contains(':')) {
final parts = data.split(':');
if (parts.length == 2) {
return {
'type': parts[0].toUpperCase(),
'value': parts[1],
};
return {'type': parts[0].toUpperCase(), 'value': parts[1]};
}
}
// If no type prefix, return as generic data
return {
'type': 'GENERIC',
'value': data,
};
return {'type': 'GENERIC', 'value': data};
} catch (e) {
return null;
}

View File

@@ -244,9 +244,7 @@ class Validators {
}
if (double.tryParse(value) == null) {
return fieldName != null
? '$fieldName phải là số'
: 'Giá trị phải là số';
return fieldName != null ? '$fieldName phải là số' : 'Giá trị phải là số';
}
return null;
@@ -351,7 +349,8 @@ class Validators {
);
final today = DateTime.now();
final age = today.year -
final age =
today.year -
birthDate.year -
(today.month > birthDate.month ||
(today.month == birthDate.month && today.day >= birthDate.day)
@@ -456,11 +455,7 @@ class Validators {
// ========================================================================
/// Validate against custom regex pattern
static String? pattern(
String? value,
RegExp pattern,
String errorMessage,
) {
static String? pattern(String? value, RegExp pattern, String errorMessage) {
if (value == null || value.trim().isEmpty) {
return 'Trường này là bắt buộc';
}
@@ -491,12 +486,7 @@ class Validators {
}
/// Password strength enum
enum PasswordStrength {
weak,
medium,
strong,
veryStrong,
}
enum PasswordStrength { weak, medium, strong, veryStrong }
/// Password strength calculator
class PasswordStrengthCalculator {