refactor: 批量替换 shadcn_ui 为 Material Design 组件
## 样式主题重点优化 ### 颜色映射(注重主题一致性) - mutedForeground → onSurfaceVariant - border → outline - card → surfaceContainer - destructive → error - 保留所有 AppColorScheme 自定义颜色 ### 文本样式映射 - theme.textTheme.h1/muted/large → AppTextStyles.xxx(context) - 统一使用项目定义的文本样式系统 ### 组件替换(20个文件) - ShadApp → MaterialApp(移除 ShadThemeData) - ShadButton → ElevatedButton/OutlinedButton - ShadDialog → AlertDialog - ShadInputFormField → MaterialInput - ShadSelect → DropdownButtonFormField - ShadCard → Card - showShadDialog → showDialog ### 依赖变更 - 移除:shadcn_ui: ^0.52.1 - 添加:lucide_icons_flutter: ^2.0.0 ### 业务逻辑保护 ✅ 所有 onPressed/onChanged/validator 回调保持不变 ✅ 所有 controller/focusNode 数据绑定保持不变 ✅ 所有布局结构(Column/Row/Padding)保持不变 ✅ 仅替换 UI 组件层,业务逻辑完全保留
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
||||
import '../../core/theme/app_spacing.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
|
||||
/// 現代底部抽屜模板 - 基於 modernization-v2.md 規範
|
||||
///
|
||||
@@ -100,17 +101,19 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadButton.outline(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => Navigator.of(context).pop(0),
|
||||
child: Text(cancelText),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: ShadButton(
|
||||
backgroundColor: isDestructive
|
||||
? ShadTheme.of(context).colorScheme.destructive
|
||||
: null,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: isDestructive
|
||||
? Theme.of(context).colorScheme.error
|
||||
: null,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(1),
|
||||
child: Text(confirmText),
|
||||
),
|
||||
@@ -125,12 +128,12 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final theme = Theme.of(context);
|
||||
final bottomPadding = MediaQuery.of(context).padding.bottom;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.card,
|
||||
color: theme.colorScheme.surfaceContainer,
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(AppRadius.xxl),
|
||||
),
|
||||
@@ -164,21 +167,21 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDragHandle(ShadThemeData theme) {
|
||||
Widget _buildDragHandle(ThemeData theme) {
|
||||
return Center(
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.muted,
|
||||
color: theme.colorScheme.outline,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader(BuildContext context, ShadThemeData theme) {
|
||||
Widget _buildHeader(BuildContext context, ThemeData theme) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
child: Row(
|
||||
@@ -187,7 +190,7 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
Expanded(
|
||||
child: titleWidget ?? Text(
|
||||
title!,
|
||||
style: theme.textTheme.h3.copyWith(
|
||||
style: AppTextStyles.headlineSmall(context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -202,7 +205,7 @@ class ModernBottomSheet extends StatelessWidget {
|
||||
child: Icon(
|
||||
LucideIcons.x,
|
||||
size: 20,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -219,7 +222,7 @@ class _ActionList extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Column(
|
||||
children: actions.asMap().entries.map((entry) {
|
||||
@@ -229,7 +232,7 @@ class _ActionList extends StatelessWidget {
|
||||
return Column(
|
||||
children: [
|
||||
if (index > 0 && actions[index - 1].isDivider)
|
||||
Divider(color: theme.colorScheme.border, height: 1),
|
||||
Divider(color: theme.colorScheme.outline, height: 1),
|
||||
_ActionTile(action: action),
|
||||
],
|
||||
);
|
||||
@@ -246,7 +249,7 @@ class _ActionTile extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
@@ -266,8 +269,8 @@ class _ActionTile extends StatelessWidget {
|
||||
action.icon,
|
||||
size: 20,
|
||||
color: action.isDestructive
|
||||
? theme.colorScheme.destructive
|
||||
: theme.colorScheme.foreground,
|
||||
? theme.colorScheme.error
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
],
|
||||
@@ -277,8 +280,8 @@ class _ActionTile extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: action.isDestructive
|
||||
? theme.colorScheme.destructive
|
||||
: theme.colorScheme.foreground,
|
||||
? theme.colorScheme.error
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import '../../core/theme/app_spacing.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
|
||||
/// 現代彈窗模板 - 基於 modernization-v2.md 規範
|
||||
///
|
||||
@@ -102,13 +102,13 @@ class ModernDialog extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
),
|
||||
backgroundColor: theme.colorScheme.card,
|
||||
backgroundColor: theme.colorScheme.surfaceContainer,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
@@ -122,7 +122,7 @@ class ModernDialog extends StatelessWidget {
|
||||
else if (title != null)
|
||||
Text(
|
||||
title!,
|
||||
style: theme.textTheme.h3.copyWith(
|
||||
style: AppTextStyles.headlineSmall(context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -132,7 +132,7 @@ class ModernDialog extends StatelessWidget {
|
||||
if (description != null) ...[
|
||||
Text(
|
||||
description!,
|
||||
style: theme.textTheme.muted,
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(color: theme.colorScheme.onSurfaceVariant),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
],
|
||||
@@ -166,11 +166,13 @@ class ModernDialog extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildActionButton(BuildContext context, ModernDialogAction action) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
if (action.isPrimary) {
|
||||
return ShadButton(
|
||||
backgroundColor: action.isDestructive ? theme.colorScheme.destructive : theme.colorScheme.primary,
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: action.isDestructive ? theme.colorScheme.error : theme.colorScheme.primary,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(action.returnValue);
|
||||
action.onPressed?.call();
|
||||
@@ -179,7 +181,7 @@ class ModernDialog extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
return ShadButton.outline(
|
||||
return OutlinedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(action.returnValue);
|
||||
action.onPressed?.call();
|
||||
|
||||
Reference in New Issue
Block a user