Files
monisuo/flutter_monisuo/lib/ui/shared/ui_constants.dart

96 lines
2.3 KiB
Dart
Raw Normal View History

2026-03-23 02:43:35 +08:00
/// UI 常量整合导出
///
/// 统一导出所有设计 token方便使用
/// 使用方式: import 'ui/shared/ui_constants.dart';
// 导出颜色系统
export '../../core/constants/app_colors.dart';
// 导出主题配置 (包含 AppTextStyles, AppSpacing, AppRadius, AppBreakpoints)
export '../../core/theme/app_theme.dart';
2026-03-23 00:43:19 +08:00
/// 表单验证器
2026-03-23 02:43:35 +08:00
///
/// 提供常用的表单验证方法
2026-03-23 00:43:19 +08:00
class Validators {
Validators._();
2026-03-23 02:43:35 +08:00
/// 金额验证
2026-03-23 00:43:19 +08:00
static String? amount(String? value) {
if (value == null || value.isEmpty) {
return '请输入金额';
}
final amount = double.tryParse(value);
if (amount == null || amount <= 0) {
return '请输入有效金额';
}
return null;
}
2026-03-23 02:43:35 +08:00
/// 价格验证
2026-03-23 00:43:19 +08:00
static String? price(String? value) {
if (value == null || value.isEmpty) {
return '请输入价格';
}
final price = double.tryParse(value);
if (price == null || price <= 0) {
return '请输入有效价格';
}
return null;
}
2026-03-23 02:43:35 +08:00
/// 数量验证
2026-03-23 00:43:19 +08:00
static String? quantity(String? value) {
if (value == null || value.isEmpty) {
return '请输入数量';
}
final quantity = double.tryParse(value);
if (quantity == null || quantity <= 0) {
return '请输入有效数量';
}
return null;
}
2026-03-23 02:43:35 +08:00
/// 必填字段验证
2026-03-23 00:43:19 +08:00
static String? required(String? value, String fieldName) {
if (value == null || value.isEmpty) {
return '请输入$fieldName';
}
return null;
}
2026-03-23 02:43:35 +08:00
/// 用户名验证
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;
}
2026-03-23 00:43:19 +08:00
}