优化
This commit is contained in:
@@ -1,25 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
/// UI 常量整合导出
|
||||
///
|
||||
/// 统一导出所有设计 token,方便使用
|
||||
/// 使用方式: import 'ui/shared/ui_constants.dart';
|
||||
|
||||
/// 应用颜色常量
|
||||
class AppColors {
|
||||
AppColors._();
|
||||
// 导出颜色系统
|
||||
export '../../core/constants/app_colors.dart';
|
||||
|
||||
static const Color up = Color(0xFF00C853);
|
||||
static const Color down = Color(0xFFFF5252);
|
||||
static const Color deposit = Color(0xFF00C853);
|
||||
static const Color withdraw = Color(0xFFFF9800);
|
||||
static const Color trade = Color(0xFF2196F3);
|
||||
|
||||
static const List<Color> gradientColors = [
|
||||
Color(0xFF00D4AA),
|
||||
Color(0xFF00B894),
|
||||
];
|
||||
}
|
||||
// 导出主题配置 (包含 AppTextStyles, AppSpacing, AppRadius, AppBreakpoints)
|
||||
export '../../core/theme/app_theme.dart';
|
||||
|
||||
/// 表单验证器
|
||||
///
|
||||
/// 提供常用的表单验证方法
|
||||
class Validators {
|
||||
Validators._();
|
||||
|
||||
/// 金额验证
|
||||
static String? amount(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
@@ -31,6 +27,7 @@ class Validators {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 价格验证
|
||||
static String? price(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入价格';
|
||||
@@ -42,6 +39,7 @@ class Validators {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 数量验证
|
||||
static String? quantity(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入数量';
|
||||
@@ -53,10 +51,45 @@ class Validators {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user