82 lines
2.0 KiB
Dart
82 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../app/theme/app_colors.dart';
|
|
import '../../app/theme/app_typography.dart';
|
|
import '../../app/theme/app_spacing.dart';
|
|
|
|
/// 信用等级徽章组件
|
|
///
|
|
/// AAA/AA/A/BBB/BB 颜色标识
|
|
/// 使用场景:券详情、发行方信息、发行方列表
|
|
class CreditBadge extends StatelessWidget {
|
|
final String rating;
|
|
final CreditBadgeSize size;
|
|
|
|
const CreditBadge({
|
|
super.key,
|
|
required this.rating,
|
|
this.size = CreditBadgeSize.medium,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: size == CreditBadgeSize.large ? 10 : 6,
|
|
vertical: size == CreditBadgeSize.large ? 4 : 2,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: _color.withValues(alpha: 0.1),
|
|
borderRadius: AppSpacing.borderRadiusFull,
|
|
border: Border.all(
|
|
color: _color.withValues(alpha: 0.3),
|
|
width: 1,
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(
|
|
Icons.verified_rounded,
|
|
size: size == CreditBadgeSize.large ? 14 : 10,
|
|
color: _color,
|
|
),
|
|
SizedBox(width: size == CreditBadgeSize.large ? 4 : 2),
|
|
Text(
|
|
rating,
|
|
style: _textStyle,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Color get _color {
|
|
switch (rating.toUpperCase()) {
|
|
case 'AAA':
|
|
return AppColors.creditAAA;
|
|
case 'AA':
|
|
return AppColors.creditAA;
|
|
case 'A':
|
|
return AppColors.creditA;
|
|
case 'BBB':
|
|
return AppColors.creditBBB;
|
|
case 'BB':
|
|
default:
|
|
return AppColors.creditBB;
|
|
}
|
|
}
|
|
|
|
TextStyle get _textStyle {
|
|
final baseStyle = size == CreditBadgeSize.large
|
|
? AppTypography.labelSmall
|
|
: AppTypography.caption;
|
|
return baseStyle.copyWith(
|
|
color: _color,
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: size == CreditBadgeSize.large ? 13 : 10,
|
|
);
|
|
}
|
|
}
|
|
|
|
enum CreditBadgeSize { small, medium, large }
|