/// UI 常量整合導出 /// /// 統一導出所有設計 token,方便使用 /// 使用方式: import 'ui/shared/ui_constants.dart'; // 導出顏色系統 export '../../core/theme/app_color_scheme.dart'; // 導出主題配置 (包含 AppTextStyles, AppSpacing, AppRadius, AppBreakpoints) export '../../core/theme/app_theme.dart'; /// 表單驗證器 /// /// 提供常用的表單驗證方法 class Validators { Validators._(); /// 金額驗證 static String? amount(String? value) { if (value == null || value.isEmpty) { return '請輸入金額'; } final amount = double.tryParse(value); if (amount == null || amount <= 0) { return '請輸入有效金額'; } return null; } /// 價格驗證 static String? price(String? value) { if (value == null || value.isEmpty) { return '請輸入價格'; } final price = double.tryParse(value); if (price == null || price <= 0) { return '請輸入有效價格'; } return null; } /// 數量驗證 static String? quantity(String? value) { if (value == null || value.isEmpty) { return '請輸入數量'; } final quantity = double.tryParse(value); if (quantity == null || quantity <= 0) { return '請輸入有效數量'; } return null; } /// 必填字段驗證 static String? required(String? value, String fieldName) { if (value == null || value.isEmpty) { return '請輸入$fieldName'; } return null; } /// 用戶名驗證 static String? username(String? value) { if (value == null || value.isEmpty) { return '請輸入用戶名'; } if (value.length < 3) { return '用戶名至少 3 個字符'; } return null; } /// 密碼驗證 static String? password(String? value) { if (value == null || value.isEmpty) { return '請輸入密碼'; } if (value.length < 6) { return '密碼至少 6 個字符'; } return null; } /// 郵箱驗證 static String? email(String? value) { if (value == null || value.isEmpty) { return '請輸入郵箱'; } final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$'); if (!emailRegex.hasMatch(value)) { return '請輸入有效的郵箱地址'; } return null; } }