chore(project): 初始化项目基础配置文件
- 添加 CodeGraph、Android 和通用 gitignore 配置 - 创建项目元数据文件跟踪 Flutter 项目属性 - 添加 Codex AI 指导文档 AGENTS.md 说明项目架构 - 配置代码分析选项 analysis_options.yaml - 设置 Android 应用清单权限和 Kiosk 模式配置 - 实现中英文国际化支持 AppLocalizations - 配置 GoRouter 应用路由导航 - 创建明亮工业控制风格的主题配置 AppTheme
This commit is contained in:
103
lib/shared/widgets/common_button.dart
Normal file
103
lib/shared/widgets/common_button.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
|
||||
/// 通用按钮组件 - 明亮工业风格
|
||||
class CommonButton extends StatelessWidget {
|
||||
final String text;
|
||||
final VoidCallback? onPressed;
|
||||
final bool enabled;
|
||||
final Color? backgroundColor;
|
||||
final Color? textColor;
|
||||
final IconData? icon;
|
||||
final bool isLoading;
|
||||
final ButtonType type;
|
||||
|
||||
const CommonButton({
|
||||
super.key,
|
||||
required this.text,
|
||||
this.onPressed,
|
||||
this.enabled = true,
|
||||
this.backgroundColor,
|
||||
this.textColor,
|
||||
this.icon,
|
||||
this.isLoading = false,
|
||||
this.type = ButtonType.primary,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bgColor = backgroundColor ?? _getDefaultBackgroundColor();
|
||||
final fgColor = textColor ?? _getDefaultTextColor();
|
||||
|
||||
Widget content;
|
||||
if (isLoading) {
|
||||
content = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: fgColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(text, style: TextStyle(fontWeight: FontWeight.w500)),
|
||||
],
|
||||
);
|
||||
} else if (icon != null) {
|
||||
content = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(text, style: TextStyle(fontWeight: FontWeight.w500)),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
content = Text(text, style: TextStyle(fontWeight: FontWeight.w500));
|
||||
}
|
||||
|
||||
return ElevatedButton(
|
||||
onPressed: enabled && !isLoading ? onPressed : null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: bgColor,
|
||||
foregroundColor: fgColor,
|
||||
disabledBackgroundColor: AppTheme.statusStopped.withValues(alpha: 0.3),
|
||||
disabledForegroundColor: AppTheme.textTertiary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusSm),
|
||||
),
|
||||
),
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
|
||||
Color _getDefaultBackgroundColor() {
|
||||
switch (type) {
|
||||
case ButtonType.primary:
|
||||
return AppTheme.primaryColor;
|
||||
case ButtonType.success:
|
||||
return AppTheme.successColor;
|
||||
case ButtonType.warning:
|
||||
return AppTheme.warningColor;
|
||||
case ButtonType.danger:
|
||||
return AppTheme.errorColor;
|
||||
case ButtonType.secondary:
|
||||
return AppTheme.bgSurface;
|
||||
}
|
||||
}
|
||||
|
||||
Color _getDefaultTextColor() {
|
||||
switch (type) {
|
||||
case ButtonType.secondary:
|
||||
return AppTheme.textPrimary;
|
||||
default:
|
||||
return AppTheme.textOnPrimary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ButtonType { primary, success, warning, danger, secondary }
|
||||
Reference in New Issue
Block a user