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,141 @@
/// API configuration constants for the Retail POS application
class ApiConstants {
// Private constructor to prevent instantiation
ApiConstants._();
// ===== Base URL Configuration =====
/// Base URL for the API
/// TODO: Replace with actual production URL
static const String baseUrl = 'https://api.retailpos.example.com';
/// API version prefix
static const String apiVersion = '/api/v1';
/// Full base URL with version
static String get fullBaseUrl => '$baseUrl$apiVersion';
// ===== Timeout Configuration =====
/// Connection timeout in milliseconds (30 seconds)
static const int connectTimeout = 30000;
/// Receive timeout in milliseconds (30 seconds)
static const int receiveTimeout = 30000;
/// Send timeout in milliseconds (30 seconds)
static const int sendTimeout = 30000;
// ===== Retry Configuration =====
/// Maximum number of retry attempts for failed requests
static const int maxRetries = 3;
/// Delay between retry attempts in milliseconds (1 second)
static const int retryDelay = 1000;
// ===== Endpoint Paths =====
// Products Endpoints
/// GET - Fetch all products
static const String products = '/products';
/// GET - Fetch single product by ID
/// Use: '${ApiConstants.products}/:id'
static String productById(String id) => '$products/$id';
/// GET - Fetch products by category
/// Use: '${ApiConstants.products}/category/:categoryId'
static String productsByCategory(String categoryId) =>
'$products/category/$categoryId';
/// GET - Search products
/// Query params: ?q=searchTerm
static const String searchProducts = '$products/search';
/// POST - Sync products (bulk update/create)
static const String syncProducts = '$products/sync';
// Categories Endpoints
/// GET - Fetch all categories
static const String categories = '/categories';
/// GET - Fetch single category by ID
/// Use: '${ApiConstants.categories}/:id'
static String categoryById(String id) => '$categories/$id';
/// POST - Sync categories (bulk update/create)
static const String syncCategories = '$categories/sync';
// Transactions Endpoints (for future use)
/// POST - Create new transaction
static const String transactions = '/transactions';
/// GET - Fetch transaction history
static const String transactionHistory = '$transactions/history';
// Settings Endpoints (for future use)
/// GET - Fetch app settings
static const String settings = '/settings';
/// PUT - Update app settings
static const String updateSettings = settings;
// ===== Request Headers =====
/// Content-Type header key
static const String contentType = 'Content-Type';
/// Content-Type value for JSON
static const String applicationJson = 'application/json';
/// Authorization header key
static const String authorization = 'Authorization';
/// Accept header key
static const String accept = 'Accept';
// ===== API Keys and Authentication =====
/// API key header name (if using API key authentication)
static const String apiKeyHeader = 'X-API-Key';
/// TODO: Store API key securely (use flutter_secure_storage in production)
static const String apiKey = 'your-api-key-here';
// ===== Status Codes =====
/// Success status codes
static const int statusOk = 200;
static const int statusCreated = 201;
static const int statusNoContent = 204;
/// Client error status codes
static const int statusBadRequest = 400;
static const int statusUnauthorized = 401;
static const int statusForbidden = 403;
static const int statusNotFound = 404;
static const int statusUnprocessableEntity = 422;
static const int statusTooManyRequests = 429;
/// Server error status codes
static const int statusInternalServerError = 500;
static const int statusBadGateway = 502;
static const int statusServiceUnavailable = 503;
static const int statusGatewayTimeout = 504;
// ===== Cache Configuration =====
/// Cache duration for products (in hours)
static const int productsCacheDuration = 24;
/// Cache duration for categories (in hours)
static const int categoriesCacheDuration = 24;
// ===== Pagination =====
/// Default page size for paginated requests
static const int defaultPageSize = 20;
/// Maximum page size
static const int maxPageSize = 100;
// ===== Mock/Development Configuration =====
/// Use mock data instead of real API (for development/testing)
static const bool useMockData = false;
/// Mock API delay in milliseconds
static const int mockApiDelay = 500;
}

View File

@@ -0,0 +1,26 @@
/// Application-wide configuration constants
class AppConstants {
AppConstants._();
// App Info
static const String appName = 'Retail POS';
static const String appVersion = '1.0.0';
// Defaults
static const String defaultCurrency = 'USD';
static const String defaultLanguage = 'en';
static const double defaultTaxRate = 0.0;
// Pagination
static const int defaultPageSize = 20;
static const int maxPageSize = 100;
// Cache
static const Duration cacheExpiration = Duration(hours: 24);
static const int maxCacheSize = 100;
// Business Rules
static const int minStockThreshold = 5;
static const int maxCartItemQuantity = 999;
static const double minTransactionAmount = 0.01;
}

View File

@@ -0,0 +1,230 @@
/// Performance-related constants for the retail POS app
///
/// This file contains all performance tuning parameters:
/// - List/Grid performance settings
/// - Cache configurations
/// - Debounce/Throttle timings
/// - Memory limits
/// - Scroll performance settings
class PerformanceConstants {
// Private constructor to prevent instantiation
PerformanceConstants._();
// ==================== List/Grid Performance ====================
/// Cache extent for ListView/GridView (pixels to preload)
static const double listCacheExtent = 500.0;
/// Number of items to preload in infinite scroll
static const int preloadItemThreshold = 5;
/// Maximum items to render at once in very large lists
static const int maxVisibleItems = 100;
/// Grid crossAxisCount for different screen widths
static int getGridColumnCount(double screenWidth) {
if (screenWidth < 600) return 2; // Mobile portrait
if (screenWidth < 900) return 3; // Mobile landscape / Small tablet
if (screenWidth < 1200) return 4; // Tablet
return 5; // Desktop
}
/// Grid childAspectRatio for product cards
static const double productCardAspectRatio = 0.75;
/// Grid childAspectRatio for category cards
static const double categoryCardAspectRatio = 1.0;
/// Grid spacing
static const double gridSpacing = 12.0;
// ==================== Debounce/Throttle Timings ====================
/// Search input debounce (ms) - wait before executing search
static const int searchDebounceDuration = 300;
/// Filter input debounce (ms)
static const int filterDebounceDuration = 200;
/// Auto-save debounce (ms)
static const int autoSaveDebounceDuration = 1000;
/// Scroll position throttle (ms)
static const int scrollThrottleDuration = 100;
/// Network retry debounce (ms)
static const int retryDebounceDuration = 500;
// ==================== Animation Durations ====================
/// Standard animation duration
static const int animationDuration = 300;
/// Fast animation duration
static const int fastAnimationDuration = 150;
/// Image fade-in duration
static const int imageFadeDuration = 300;
/// Shimmer animation duration
static const int shimmerDuration = 1500;
// ==================== Memory Management ====================
/// Maximum image cache size in memory (MB)
static const int maxImageMemoryCacheMB = 50;
/// Maximum image cache count in memory
static const int maxImageMemoryCacheCount = 100;
/// Maximum disk cache size (MB)
static const int maxDiskCacheMB = 200;
/// Database cache size limit (number of items)
static const int maxDatabaseCacheItems = 1000;
// ==================== Network Performance ====================
/// Network request timeout (seconds)
static const int networkTimeoutSeconds = 30;
/// Network connect timeout (seconds)
static const int networkConnectTimeoutSeconds = 15;
/// Network receive timeout (seconds)
static const int networkReceiveTimeoutSeconds = 30;
/// Maximum concurrent image downloads
static const int maxConcurrentImageDownloads = 3;
/// Retry attempts for failed requests
static const int maxRetryAttempts = 3;
/// Retry delay (seconds)
static const int retryDelaySeconds = 2;
// ==================== Batch Operations ====================
/// Batch size for database operations
static const int databaseBatchSize = 50;
/// Batch size for image preloading
static const int imagePreloadBatchSize = 10;
/// Pagination page size
static const int paginationPageSize = 20;
// ==================== Build Optimization ====================
/// Whether to use RepaintBoundary for grid items
static const bool useRepaintBoundaryForGridItems = true;
/// Whether to use const constructors aggressively
static const bool useConstConstructors = true;
/// Whether to enable performance overlay in debug mode
static const bool enablePerformanceOverlay = false;
// ==================== Hive Database Performance ====================
/// Compact database after this many operations
static const int databaseCompactThreshold = 100;
/// Use lazy box for large datasets
static const bool useLazyBoxForProducts = true;
/// Cache database queries
static const bool cacheQueries = true;
/// Maximum database file size (MB) before warning
static const int maxDatabaseSizeMB = 100;
// ==================== Scroll Performance ====================
/// Physics for better scroll performance
static const bool useBouncingScrollPhysics = true;
/// Scroll controller jump threshold (prevent jarring jumps)
static const double scrollJumpThreshold = 1000.0;
/// Enable scroll momentum
static const bool enableScrollMomentum = true;
// ==================== State Management Performance ====================
/// Provider auto-dispose delay (seconds)
static const int providerAutoDisposeDelay = 60;
/// Keep alive duration for cached providers (seconds)
static const int providerKeepAliveDuration = 300;
/// Use provider.select() for granular rebuilds
static const bool useGranularRebuild = true;
// ==================== Image Loading Performance ====================
/// Image loading placeholder height
static const double placeholderHeight = 200.0;
/// Use progressive JPEG loading
static const bool useProgressiveLoading = true;
/// Preload images for next page
static const bool preloadNextPageImages = true;
/// Maximum image resolution (width x height)
static const int maxImageWidth = 1920;
static const int maxImageHeight = 1920;
// ==================== Frame Rate Targets ====================
/// Target frame rate
static const int targetFPS = 60;
/// Budget per frame (milliseconds)
static const double frameBudgetMs = 16.67; // 60 FPS
/// Warning threshold for long frames (ms)
static const double longFrameThresholdMs = 32.0;
// ==================== Cart Performance ====================
/// Maximum cart items before pagination
static const int maxCartItemsBeforePagination = 50;
/// Cart calculation debounce (ms)
static const int cartCalculationDebounce = 100;
// ==================== Responsive Breakpoints ====================
/// Mobile breakpoint
static const double mobileBreakpoint = 600.0;
/// Tablet breakpoint
static const double tabletBreakpoint = 900.0;
/// Desktop breakpoint
static const double desktopBreakpoint = 1200.0;
// ==================== Helper Methods ====================
/// Get appropriate cache extent based on device
static double getCacheExtent(double screenHeight) {
// Cache 1.5x screen height
return screenHeight * 1.5;
}
/// Get appropriate batch size based on memory
static int getDynamicBatchSize(int totalItems) {
if (totalItems < 100) return 20;
if (totalItems < 500) return 50;
if (totalItems < 1000) return 100;
return 200;
}
/// Check if device can handle high performance mode
static bool shouldUseHighPerformanceMode(double screenWidth) {
return screenWidth >= tabletBreakpoint;
}
}

View File

@@ -0,0 +1,28 @@
/// Storage-related constants for Hive database
class StorageConstants {
StorageConstants._();
// Hive Box Names
static const String productsBox = 'products';
static const String categoriesBox = 'categories';
static const String cartBox = 'cart';
static const String settingsBox = 'settings';
static const String transactionsBox = 'transactions';
// Hive Type IDs
static const int productTypeId = 0;
static const int categoryTypeId = 1;
static const int cartItemTypeId = 2;
static const int transactionTypeId = 3;
static const int appSettingsTypeId = 4;
// Storage Keys
static const String settingsKey = 'app_settings';
static const String themeKey = 'theme_mode';
static const String languageKey = 'language';
static const String currencyKey = 'currency';
static const String taxRateKey = 'tax_rate';
static const String storeNameKey = 'store_name';
static const String lastSyncKey = 'last_sync';
static const String firstLaunchKey = 'first_launch';
}

View File

@@ -0,0 +1,52 @@
/// UI-related constants for consistent design
class UIConstants {
UIConstants._();
// Spacing
static const double spacingXS = 4.0;
static const double spacingS = 8.0;
static const double spacingM = 16.0;
static const double spacingL = 24.0;
static const double spacingXL = 32.0;
// Border Radius
static const double borderRadiusS = 8.0;
static const double borderRadiusM = 12.0;
static const double borderRadiusL = 16.0;
// Icon Sizes
static const double iconSizeS = 16.0;
static const double iconSizeM = 24.0;
static const double iconSizeL = 32.0;
static const double iconSizeXL = 48.0;
// Button Heights
static const double buttonHeightS = 36.0;
static const double buttonHeightM = 48.0;
static const double buttonHeightL = 56.0;
// Grid
static const int gridCrossAxisCountMobile = 2;
static const int gridCrossAxisCountTablet = 4;
static const double gridChildAspectRatio = 0.75;
static const double gridSpacing = 12.0;
// Animation Durations
static const Duration animationDurationShort = Duration(milliseconds: 200);
static const Duration animationDurationMedium = Duration(milliseconds: 300);
static const Duration animationDurationLong = Duration(milliseconds: 500);
// Debounce
static const Duration searchDebounce = Duration(milliseconds: 300);
// Image
static const double productImageHeight = 200.0;
static const double thumbnailSize = 60.0;
static const double categoryIconSize = 64.0;
// Elevation
static const double elevationLow = 2.0;
static const double elevationMedium = 4.0;
static const double elevationHigh = 8.0;
}