feat: API 통합 2차 작업 완료
- 자동 로그인 구현: 앱 시작 시 토큰 확인 후 적절한 화면으로 라우팅 - AuthInterceptor 개선: AuthService와 통합하여 토큰 관리 일원화 - 로그아웃 기능 개선: AuthService를 사용한 API 로그아웃 처리 - 대시보드 API 연동: MockDataService에서 실제 API로 완전 전환 - Dashboard DTO 모델 생성 (OverviewStats, RecentActivity 등) - DashboardRemoteDataSource 및 DashboardService 구현 - OverviewController를 ChangeNotifier 패턴으로 개선 - OverviewScreenRedesign에 Provider 패턴 적용 - API 통합 진행 상황 문서 업데이트
This commit is contained in:
@@ -14,41 +14,45 @@ class OverviewScreenRedesign extends StatefulWidget {
|
||||
|
||||
class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
late final OverviewController _controller;
|
||||
bool _isLoading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = OverviewController(dataService: MockDataService());
|
||||
_controller = OverviewController();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
Future<void> _loadData() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
await _controller.loadDashboardData();
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 800));
|
||||
_controller.loadData();
|
||||
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isLoading) {
|
||||
return _buildLoadingState();
|
||||
}
|
||||
return ChangeNotifierProvider.value(
|
||||
value: _controller,
|
||||
child: Consumer<OverviewController>(
|
||||
builder: (context, controller, child) {
|
||||
if (controller.isLoading) {
|
||||
return _buildLoadingState();
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: ShadcnTheme.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (controller.error != null) {
|
||||
return _buildErrorState(controller.error!);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: ShadcnTheme.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 환영 섹션
|
||||
ShadcnCard(
|
||||
padding: const EdgeInsets.all(32),
|
||||
@@ -164,6 +168,9 @@ class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -183,6 +190,34 @@ class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorState(String error) {
|
||||
return Container(
|
||||
color: ShadcnTheme.background,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: ShadcnTheme.error,
|
||||
),
|
||||
const SizedBox(height: ShadcnTheme.spacing4),
|
||||
Text('오류가 발생했습니다', style: ShadcnTheme.headingH4),
|
||||
const SizedBox(height: ShadcnTheme.spacing2),
|
||||
Text(error, style: ShadcnTheme.bodyMuted),
|
||||
const SizedBox(height: ShadcnTheme.spacing4),
|
||||
ShadcnButton(
|
||||
text: '다시 시도',
|
||||
onPressed: _loadData,
|
||||
variant: ShadcnButtonVariant.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLeftColumn() {
|
||||
return Column(
|
||||
children: [
|
||||
@@ -261,7 +296,27 @@ class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
...List.generate(5, (index) => _buildActivityItem(index)),
|
||||
Consumer<OverviewController>(
|
||||
builder: (context, controller, child) {
|
||||
final activities = controller.recentActivities ?? [];
|
||||
if (activities.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'최근 활동이 없습니다',
|
||||
style: ShadcnTheme.bodyMuted,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
children: activities.take(5).map((activity) =>
|
||||
_buildActivityItem(activity),
|
||||
).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -376,41 +431,41 @@ class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActivityItem(int index) {
|
||||
final activities = [
|
||||
{
|
||||
'icon': Icons.inventory,
|
||||
'title': '장비 입고 처리',
|
||||
'subtitle': '크레인 #CR-001 입고 완료',
|
||||
'time': '2분 전',
|
||||
},
|
||||
{
|
||||
'icon': Icons.local_shipping,
|
||||
'title': '장비 출고 처리',
|
||||
'subtitle': '포클레인 #FK-005 출고 완료',
|
||||
'time': '5분 전',
|
||||
},
|
||||
{
|
||||
'icon': Icons.business,
|
||||
'title': '회사 등록',
|
||||
'subtitle': '새로운 회사 "ABC건설" 등록',
|
||||
'time': '10분 전',
|
||||
},
|
||||
{
|
||||
'icon': Icons.person_add,
|
||||
'title': '사용자 추가',
|
||||
'subtitle': '신규 사용자 계정 생성',
|
||||
'time': '15분 전',
|
||||
},
|
||||
{
|
||||
'icon': Icons.settings,
|
||||
'title': '시스템 점검',
|
||||
'subtitle': '정기 시스템 점검 완료',
|
||||
'time': '30분 전',
|
||||
},
|
||||
];
|
||||
Widget _buildActivityItem(dynamic activity) {
|
||||
// 아이콘 매핑
|
||||
IconData getActivityIcon(String type) {
|
||||
switch (type) {
|
||||
case 'equipment_in':
|
||||
return Icons.inventory;
|
||||
case 'equipment_out':
|
||||
return Icons.local_shipping;
|
||||
case 'company':
|
||||
return Icons.business;
|
||||
case 'user':
|
||||
return Icons.person_add;
|
||||
default:
|
||||
return Icons.settings;
|
||||
}
|
||||
}
|
||||
|
||||
final activity = activities[index];
|
||||
// 색상 매핑
|
||||
Color getActivityColor(String type) {
|
||||
switch (type) {
|
||||
case 'equipment_in':
|
||||
return ShadcnTheme.success;
|
||||
case 'equipment_out':
|
||||
return ShadcnTheme.warning;
|
||||
case 'company':
|
||||
return ShadcnTheme.info;
|
||||
case 'user':
|
||||
return ShadcnTheme.primary;
|
||||
default:
|
||||
return ShadcnTheme.mutedForeground;
|
||||
}
|
||||
}
|
||||
|
||||
final color = getActivityColor(activity.type);
|
||||
final dateFormat = DateFormat('MM/dd HH:mm');
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
@@ -419,12 +474,12 @@ class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.success.withOpacity(0.1),
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Icon(
|
||||
activity['icon'] as IconData,
|
||||
color: ShadcnTheme.success,
|
||||
getActivityIcon(activity.type),
|
||||
color: color,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
@@ -434,17 +489,20 @@ class _OverviewScreenRedesignState extends State<OverviewScreenRedesign> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
activity['title'] as String,
|
||||
activity.title,
|
||||
style: ShadcnTheme.bodyMedium,
|
||||
),
|
||||
Text(
|
||||
activity['subtitle'] as String,
|
||||
activity.description,
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(activity['time'] as String, style: ShadcnTheme.bodySmall),
|
||||
Text(
|
||||
dateFormat.format(activity.createdAt),
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user