150 lines
4.3 KiB
Dart
150 lines
4.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../constants/app_colors.dart';
|
|
import '../constants/app_typography.dart';
|
|
|
|
/// 빈 상태 위젯
|
|
///
|
|
/// 데이터가 없을 때 표시하는 공통 위젯
|
|
class EmptyStateWidget extends StatelessWidget {
|
|
/// 제목
|
|
final String title;
|
|
|
|
/// 설명 메시지 (선택사항)
|
|
final String? message;
|
|
|
|
/// 아이콘 (선택사항)
|
|
final IconData? icon;
|
|
|
|
/// 아이콘 크기
|
|
final double iconSize;
|
|
|
|
/// 액션 버튼 텍스트 (선택사항)
|
|
final String? actionText;
|
|
|
|
/// 액션 버튼 콜백 (선택사항)
|
|
final VoidCallback? onAction;
|
|
|
|
/// 커스텀 위젯 (아이콘 대신 사용할 수 있음)
|
|
final Widget? customWidget;
|
|
|
|
const EmptyStateWidget({
|
|
super.key,
|
|
required this.title,
|
|
this.message,
|
|
this.icon,
|
|
this.iconSize = 80.0,
|
|
this.actionText,
|
|
this.onAction,
|
|
this.customWidget,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// 아이콘 또는 커스텀 위젯
|
|
if (customWidget != null)
|
|
customWidget!
|
|
else if (icon != null)
|
|
Container(
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
color:
|
|
(isDark ? AppColors.darkPrimary : AppColors.lightPrimary)
|
|
.withValues(alpha: 0.1),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(
|
|
icon,
|
|
size: iconSize,
|
|
color: isDark
|
|
? AppColors.darkTextSecondary
|
|
: AppColors.lightTextSecondary,
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
|
|
// 제목
|
|
Text(
|
|
title,
|
|
style: AppTypography.heading2(isDark),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
|
|
// 설명 메시지 (있을 경우)
|
|
if (message != null) ...[
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
message!,
|
|
style: AppTypography.body2(isDark),
|
|
textAlign: TextAlign.center,
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
|
|
// 액션 버튼 (있을 경우)
|
|
if (actionText != null && onAction != null) ...[
|
|
const SizedBox(height: 32),
|
|
ElevatedButton(
|
|
onPressed: onAction,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: isDark
|
|
? AppColors.darkPrimary
|
|
: AppColors.lightPrimary,
|
|
foregroundColor: Colors.white,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 32,
|
|
vertical: 12,
|
|
),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
child: Text(
|
|
actionText!,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 리스트 빈 상태 위젯
|
|
///
|
|
/// 리스트나 그리드가 비어있을 때 사용하는 특화된 위젯
|
|
class ListEmptyStateWidget extends StatelessWidget {
|
|
/// 아이템 유형 (예: "식당", "기록" 등)
|
|
final String itemType;
|
|
|
|
/// 추가 액션 콜백 (선택사항)
|
|
final VoidCallback? onAdd;
|
|
|
|
const ListEmptyStateWidget({super.key, required this.itemType, this.onAdd});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return EmptyStateWidget(
|
|
icon: Icons.inbox_outlined,
|
|
title: '$itemType이(가) 없습니다',
|
|
message: '새로운 $itemType을(를) 추가해보세요',
|
|
actionText: onAdd != null ? '$itemType 추가' : null,
|
|
onAction: onAdd,
|
|
);
|
|
}
|
|
}
|