214 lines
5.0 KiB
Dart
214 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mobile_monitoring/core/constants/colors.dart';
|
|
|
|
/// Status Badge - Badge untuk menampilkan status
|
|
class StatusBadge extends StatelessWidget {
|
|
final String label;
|
|
final Color? backgroundColor;
|
|
final Color? textColor;
|
|
final IconData? icon;
|
|
final BadgeSize size;
|
|
|
|
const StatusBadge({
|
|
super.key,
|
|
required this.label,
|
|
this.backgroundColor,
|
|
this.textColor,
|
|
this.icon,
|
|
this.size = BadgeSize.medium,
|
|
});
|
|
|
|
// Factory constructors untuk status umum
|
|
factory StatusBadge.success(String label, {BadgeSize size = BadgeSize.medium}) {
|
|
return StatusBadge(
|
|
label: label,
|
|
backgroundColor: AppColors.success,
|
|
textColor: AppColors.white,
|
|
icon: Icons.check_circle,
|
|
size: size,
|
|
);
|
|
}
|
|
|
|
factory StatusBadge.warning(String label, {BadgeSize size = BadgeSize.medium}) {
|
|
return StatusBadge(
|
|
label: label,
|
|
backgroundColor: AppColors.warning,
|
|
textColor: AppColors.white,
|
|
icon: Icons.warning,
|
|
size: size,
|
|
);
|
|
}
|
|
|
|
factory StatusBadge.error(String label, {BadgeSize size = BadgeSize.medium}) {
|
|
return StatusBadge(
|
|
label: label,
|
|
backgroundColor: AppColors.error,
|
|
textColor: AppColors.white,
|
|
icon: Icons.error,
|
|
size: size,
|
|
);
|
|
}
|
|
|
|
factory StatusBadge.info(String label, {BadgeSize size = BadgeSize.medium}) {
|
|
return StatusBadge(
|
|
label: label,
|
|
backgroundColor: AppColors.info,
|
|
textColor: AppColors.white,
|
|
icon: Icons.info,
|
|
size: size,
|
|
);
|
|
}
|
|
|
|
factory StatusBadge.neutral(String label, {BadgeSize size = BadgeSize.medium}) {
|
|
return StatusBadge(
|
|
label: label,
|
|
backgroundColor: AppColors.lightGray,
|
|
textColor: AppColors.textPrimary,
|
|
size: size,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: _getPadding(),
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor ?? AppColors.primary,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (icon != null) ...[
|
|
Icon(
|
|
icon,
|
|
size: _getIconSize(),
|
|
color: textColor ?? AppColors.white,
|
|
),
|
|
SizedBox(width: _getSpacing()),
|
|
],
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: _getFontSize(),
|
|
fontWeight: FontWeight.w600,
|
|
color: textColor ?? AppColors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
EdgeInsets _getPadding() {
|
|
switch (size) {
|
|
case BadgeSize.small:
|
|
return const EdgeInsets.symmetric(horizontal: 8, vertical: 4);
|
|
case BadgeSize.medium:
|
|
return const EdgeInsets.symmetric(horizontal: 12, vertical: 6);
|
|
case BadgeSize.large:
|
|
return const EdgeInsets.symmetric(horizontal: 16, vertical: 8);
|
|
}
|
|
}
|
|
|
|
double _getFontSize() {
|
|
switch (size) {
|
|
case BadgeSize.small:
|
|
return 10;
|
|
case BadgeSize.medium:
|
|
return 12;
|
|
case BadgeSize.large:
|
|
return 14;
|
|
}
|
|
}
|
|
|
|
double _getIconSize() {
|
|
switch (size) {
|
|
case BadgeSize.small:
|
|
return 12;
|
|
case BadgeSize.medium:
|
|
return 14;
|
|
case BadgeSize.large:
|
|
return 16;
|
|
}
|
|
}
|
|
|
|
double _getSpacing() {
|
|
switch (size) {
|
|
case BadgeSize.small:
|
|
return 4;
|
|
case BadgeSize.medium:
|
|
return 6;
|
|
case BadgeSize.large:
|
|
return 8;
|
|
}
|
|
}
|
|
}
|
|
|
|
enum BadgeSize { small, medium, large }
|
|
|
|
/// Notification Badge - Badge untuk menampilkan notifikasi count
|
|
class NotificationBadge extends StatelessWidget {
|
|
final int count;
|
|
final Color? backgroundColor;
|
|
final Color? textColor;
|
|
|
|
const NotificationBadge({
|
|
super.key,
|
|
required this.count,
|
|
this.backgroundColor,
|
|
this.textColor,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (count <= 0) return const SizedBox.shrink();
|
|
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor ?? AppColors.error,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
constraints: const BoxConstraints(
|
|
minWidth: 20,
|
|
minHeight: 20,
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
count > 99 ? '99+' : count.toString(),
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
fontWeight: FontWeight.bold,
|
|
color: textColor ?? AppColors.white,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Dot Badge - Badge berbentuk dot
|
|
class DotBadge extends StatelessWidget {
|
|
final Color? color;
|
|
final double size;
|
|
|
|
const DotBadge({
|
|
super.key,
|
|
this.color,
|
|
this.size = 8,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: size,
|
|
height: size,
|
|
decoration: BoxDecoration(
|
|
color: color ?? AppColors.error,
|
|
shape: BoxShape.circle,
|
|
),
|
|
);
|
|
}
|
|
}
|