111
This commit is contained in:
@@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import '../../core/theme/app_spacing.dart';
|
||||
|
||||
/// 现代底部抽屉模板 - 基于 modernization-v2.md 规范
|
||||
/// 現代底部抽屜模板 - 基於 modernization-v2.md 規範
|
||||
///
|
||||
/// 使用方法:
|
||||
/// ```dart
|
||||
/// ModernBottomSheet.show(
|
||||
/// context: context,
|
||||
/// title: '选择币种',
|
||||
/// title: '選擇幣種',
|
||||
/// child: YourContentWidget(),
|
||||
/// );
|
||||
/// ```
|
||||
@@ -32,7 +32,7 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
this.onClose,
|
||||
});
|
||||
|
||||
/// 显示底部抽屉
|
||||
/// 顯示底部抽屜
|
||||
static Future<T?> show<T>({
|
||||
required BuildContext context,
|
||||
String? title,
|
||||
@@ -62,7 +62,7 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示操作列表
|
||||
/// 顯示操作列表
|
||||
static Future<T?> showActions<T>({
|
||||
required BuildContext context,
|
||||
String? title,
|
||||
@@ -75,12 +75,12 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示确认操作
|
||||
/// 顯示確認操作
|
||||
static Future<bool> confirmAction({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
String? description,
|
||||
String confirmText = '确认',
|
||||
String confirmText = '確認',
|
||||
String cancelText = '取消',
|
||||
bool isDestructive = false,
|
||||
}) async {
|
||||
@@ -150,12 +150,12 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 拖动指示器
|
||||
// 拖動指示器
|
||||
if (showDragHandle) _buildDragHandle(theme),
|
||||
// 标题行
|
||||
// 標題行
|
||||
if (title != null || titleWidget != null || showCloseButton)
|
||||
_buildHeader(context, theme),
|
||||
// 内容
|
||||
// 內容
|
||||
child,
|
||||
],
|
||||
),
|
||||
@@ -183,7 +183,7 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
child: Row(
|
||||
children: [
|
||||
// 标题
|
||||
// 標題
|
||||
Expanded(
|
||||
child: titleWidget ?? Text(
|
||||
title!,
|
||||
@@ -192,7 +192,7 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
// 关闭按钮
|
||||
// 關閉按鈕
|
||||
if (showCloseButton)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
@@ -238,7 +238,7 @@ class _ActionList extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 操作项
|
||||
/// 操作項
|
||||
class _ActionTile extends StatelessWidget {
|
||||
final ModernSheetAction action;
|
||||
|
||||
@@ -289,7 +289,7 @@ class _ActionTile extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 底部抽屉操作配置
|
||||
/// 底部抽屜操作配置
|
||||
class ModernSheetAction {
|
||||
final String label;
|
||||
final IconData? icon;
|
||||
|
||||
@@ -2,17 +2,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import '../../core/theme/app_spacing.dart';
|
||||
|
||||
/// 现代弹窗模板 - 基于 modernization-v2.md 规范
|
||||
/// 現代彈窗模板 - 基於 modernization-v2.md 規範
|
||||
///
|
||||
/// 使用方法:
|
||||
/// ```dart
|
||||
/// ModernDialog.show(
|
||||
/// context: context,
|
||||
/// title: '确认操作',
|
||||
/// description: '确定要执行此操作吗?',
|
||||
/// title: '確認操作',
|
||||
/// description: '確定要執行此操作嗎?',
|
||||
/// actions: [
|
||||
/// ModernDialogAction(label: '取消', isDestructive: false),
|
||||
/// ModernDialogAction(label: '确认', isPrimary: true),
|
||||
/// ModernDialogAction(label: '確認', isPrimary: true),
|
||||
/// ],
|
||||
/// );
|
||||
/// ```
|
||||
@@ -34,7 +34,7 @@ class ModernDialog extends StatelessWidget {
|
||||
this.onClose,
|
||||
});
|
||||
|
||||
/// 显示现代弹窗
|
||||
/// 顯示現代彈窗
|
||||
static Future<T?> show<T>({
|
||||
required BuildContext context,
|
||||
String? title,
|
||||
@@ -57,12 +57,12 @@ class ModernDialog extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示确认弹窗
|
||||
/// 顯示確認彈窗
|
||||
static Future<bool> confirm({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
String? description,
|
||||
String confirmText = '确认',
|
||||
String confirmText = '確認',
|
||||
String cancelText = '取消',
|
||||
bool isDestructive = false,
|
||||
}) async {
|
||||
@@ -83,7 +83,7 @@ class ModernDialog extends StatelessWidget {
|
||||
return result ?? false;
|
||||
}
|
||||
|
||||
/// 显示信息弹窗
|
||||
/// 顯示信息彈窗
|
||||
static Future<void> info({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
@@ -116,7 +116,7 @@ class ModernDialog extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题
|
||||
// 標題
|
||||
if (titleWidget != null)
|
||||
titleWidget!
|
||||
else if (title != null)
|
||||
@@ -136,12 +136,12 @@ class ModernDialog extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
],
|
||||
// 自定义内容
|
||||
// 自定義內容
|
||||
if (content != null) ...[
|
||||
content!,
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
// 按钮
|
||||
// 按鈕
|
||||
if (actions != null && actions!.isNotEmpty)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
@@ -189,7 +189,7 @@ class ModernDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 弹窗按钮配置
|
||||
/// 彈窗按鈕配置
|
||||
class ModernDialogAction {
|
||||
final String label;
|
||||
final dynamic returnValue;
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
/// UI 常量整合导出
|
||||
/// UI 常量整合導出
|
||||
///
|
||||
/// 统一导出所有设计 token,方便使用
|
||||
/// 統一導出所有設計 token,方便使用
|
||||
/// 使用方式: import 'ui/shared/ui_constants.dart';
|
||||
|
||||
// 导出颜色系统
|
||||
// 導出顏色系統
|
||||
export '../../core/theme/app_color_scheme.dart';
|
||||
|
||||
// 导出主题配置 (包含 AppTextStyles, AppSpacing, AppRadius, AppBreakpoints)
|
||||
// 導出主題配置 (包含 AppTextStyles, AppSpacing, AppRadius, AppBreakpoints)
|
||||
export '../../core/theme/app_theme.dart';
|
||||
|
||||
/// 表单验证器
|
||||
/// 表單驗證器
|
||||
///
|
||||
/// 提供常用的表单验证方法
|
||||
/// 提供常用的表單驗證方法
|
||||
class Validators {
|
||||
Validators._();
|
||||
|
||||
/// 金额验证
|
||||
/// 金額驗證
|
||||
static String? amount(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
return '請輸入金額';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
return '請輸入有效金額';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 价格验证
|
||||
/// 價格驗證
|
||||
static String? price(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入价格';
|
||||
return '請輸入價格';
|
||||
}
|
||||
final price = double.tryParse(value);
|
||||
if (price == null || price <= 0) {
|
||||
return '请输入有效价格';
|
||||
return '請輸入有效價格';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 数量验证
|
||||
/// 數量驗證
|
||||
static String? quantity(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入数量';
|
||||
return '請輸入數量';
|
||||
}
|
||||
final quantity = double.tryParse(value);
|
||||
if (quantity == null || quantity <= 0) {
|
||||
return '请输入有效数量';
|
||||
return '請輸入有效數量';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 必填字段验证
|
||||
/// 必填字段驗證
|
||||
static String? required(String? value, String fieldName) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入$fieldName';
|
||||
return '請輸入$fieldName';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 用户名验证
|
||||
/// 用戶名驗證
|
||||
static String? username(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入用户名';
|
||||
return '請輸入用戶名';
|
||||
}
|
||||
if (value.length < 3) {
|
||||
return '用户名至少 3 个字符';
|
||||
return '用戶名至少 3 個字符';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 密码验证
|
||||
/// 密碼驗證
|
||||
static String? password(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入密码';
|
||||
return '請輸入密碼';
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return '密码至少 6 个字符';
|
||||
return '密碼至少 6 個字符';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 邮箱验证
|
||||
/// 郵箱驗證
|
||||
static String? email(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入邮箱';
|
||||
return '請輸入郵箱';
|
||||
}
|
||||
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
|
||||
if (!emailRegex.hasMatch(value)) {
|
||||
return '请输入有效的邮箱地址';
|
||||
return '請輸入有效的郵箱地址';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user