TDD 작성
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// PrimeVue 스타일의 뱃지 위젯
|
||||
///
|
||||
/// [label] - 뱃지에 표시할 텍스트
|
||||
/// [color] - 뱃지의 배경색
|
||||
/// [icon] - 뱃지 앞에 표시할 아이콘 (선택사항)
|
||||
/// [severity] - 미리 정의된 색상 스타일 (info, success, warning, danger)
|
||||
/// [size] - 뱃지 크기 (small, normal, large)
|
||||
/// [outlined] - 외곽선 스타일 적용 여부
|
||||
/// [rounded] - 둥근 모서리 적용 여부
|
||||
class PrimeBadge extends StatelessWidget {
|
||||
final String label;
|
||||
final Color? color;
|
||||
final IconData? icon;
|
||||
final String? severity;
|
||||
final String size;
|
||||
final bool outlined;
|
||||
final bool rounded;
|
||||
|
||||
const PrimeBadge({
|
||||
Key? key,
|
||||
required this.label,
|
||||
this.color,
|
||||
this.icon,
|
||||
this.severity,
|
||||
this.size = 'normal',
|
||||
this.outlined = false,
|
||||
this.rounded = true,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 색상 결정 (severity 또는 직접 지정된 색상)
|
||||
Color backgroundColor = _getBackgroundColor();
|
||||
Color textColor = _getTextColor(backgroundColor);
|
||||
|
||||
// 크기에 따른 패딩 및 폰트 크기 설정
|
||||
EdgeInsets padding = _getPadding();
|
||||
double fontSize = _getFontSize();
|
||||
double iconSize = _getIconSize();
|
||||
|
||||
// 테두리 반경 설정
|
||||
double borderRadius = rounded ? 16.0 : 4.0;
|
||||
|
||||
return Container(
|
||||
padding: padding,
|
||||
decoration: BoxDecoration(
|
||||
color: outlined ? Colors.transparent : backgroundColor,
|
||||
border: outlined ? Border.all(color: backgroundColor) : null,
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (icon != null) ...[
|
||||
Icon(
|
||||
icon,
|
||||
size: iconSize,
|
||||
color: outlined ? backgroundColor : textColor,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: outlined ? backgroundColor : textColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getBackgroundColor() {
|
||||
if (color != null) {
|
||||
return color!;
|
||||
}
|
||||
|
||||
switch (severity) {
|
||||
case 'info':
|
||||
return Colors.blue;
|
||||
case 'success':
|
||||
return Colors.green;
|
||||
case 'warning':
|
||||
return Colors.orange;
|
||||
case 'danger':
|
||||
return Colors.red;
|
||||
default:
|
||||
return Colors.blue;
|
||||
}
|
||||
}
|
||||
|
||||
Color _getTextColor(Color backgroundColor) {
|
||||
// 배경색의 밝기에 따라 텍스트 색상 결정 (밝은 배경 -> 어두운 텍스트, 어두운 배경 -> 밝은 텍스트)
|
||||
final brightness = ThemeData.estimateBrightnessForColor(backgroundColor);
|
||||
return brightness == Brightness.dark ? Colors.white : Colors.black87;
|
||||
}
|
||||
|
||||
EdgeInsets _getPadding() {
|
||||
switch (size) {
|
||||
case 'small':
|
||||
return const EdgeInsets.symmetric(horizontal: 8, vertical: 2);
|
||||
case 'large':
|
||||
return const EdgeInsets.symmetric(horizontal: 16, vertical: 8);
|
||||
case 'normal':
|
||||
default:
|
||||
return const EdgeInsets.symmetric(horizontal: 12, vertical: 6);
|
||||
}
|
||||
}
|
||||
|
||||
double _getFontSize() {
|
||||
switch (size) {
|
||||
case 'small':
|
||||
return 10.0;
|
||||
case 'large':
|
||||
return 16.0;
|
||||
case 'normal':
|
||||
default:
|
||||
return 12.0;
|
||||
}
|
||||
}
|
||||
|
||||
double _getIconSize() {
|
||||
switch (size) {
|
||||
case 'small':
|
||||
return 12.0;
|
||||
case 'large':
|
||||
return 20.0;
|
||||
case 'normal':
|
||||
default:
|
||||
return 16.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user