This commit is contained in:
Phuoc Nguyen
2025-10-10 16:38:07 +07:00
parent e5b247d622
commit b94c158004
177 changed files with 25080 additions and 152 deletions

View File

@@ -0,0 +1,43 @@
import 'package:intl/intl.dart';
/// Utility class for formatting values
class Formatters {
Formatters._();
/// Format price with currency symbol
static String formatPrice(double price, {String currency = 'USD'}) {
final formatter = NumberFormat.currency(symbol: '\$', decimalDigits: 2);
return formatter.format(price);
}
/// Format date
static String formatDate(DateTime date) {
return DateFormat('MMM dd, yyyy').format(date);
}
/// Format date and time
static String formatDateTime(DateTime dateTime) {
return DateFormat('MMM dd, yyyy hh:mm a').format(dateTime);
}
/// Format time only
static String formatTime(DateTime time) {
return DateFormat('hh:mm a').format(time);
}
/// Format number with thousand separators
static String formatNumber(int number) {
final formatter = NumberFormat('#,###');
return formatter.format(number);
}
/// Format percentage
static String formatPercentage(double value, {int decimals = 0}) {
return '${value.toStringAsFixed(decimals)}%';
}
/// Format quantity (e.g., "5 items")
static String formatQuantity(int quantity) {
return '$quantity ${quantity == 1 ? 'item' : 'items'}';
}
}