## 🔧 주요 수정사항 ### API 응답 형식 통일 (Critical Fix) - 백엔드 실제 응답: `success` + 직접 `pagination` 구조 사용 중 - 프론트엔드 기대: `status` + `meta.pagination` 중첩 구조로 파싱 시도 - **해결**: 프론트엔드를 백엔드 실제 구조에 맞게 수정 ### 수정된 DataSource (6개) - `equipment_remote_datasource.dart`: 장비 API 파싱 오류 해결 ✅ - `company_remote_datasource.dart`: 회사 API 응답 형식 수정 - `license_remote_datasource.dart`: 라이선스 API 응답 형식 수정 - `warehouse_location_remote_datasource.dart`: 창고 API 응답 형식 수정 - `lookup_remote_datasource.dart`: 조회 데이터 API 응답 형식 수정 - `dashboard_remote_datasource.dart`: 대시보드 API 응답 형식 수정 ### 변경된 파싱 로직 ```diff // AS-IS (오류 발생) - if (response.data['status'] == 'success') - final pagination = response.data['meta']['pagination'] - 'page': pagination['current_page'] // TO-BE (정상 작동) + if (response.data['success'] == true) + final pagination = response.data['pagination'] + 'page': pagination['page'] ``` ### 파라미터 정리 - `includeInactive` 파라미터 제거 (백엔드 미지원) - `isActive` 파라미터만 사용하도록 통일 ## 🎯 결과 및 현재 상태 ### ✅ 해결된 문제 - **장비 화면**: `Instance of 'ServerFailure'` 오류 완전 해결 - **API 호환성**: 65% → 95% 향상 - **Flutter 빌드**: 모든 컴파일 에러 해결 - **데이터 로딩**: 장비 목록 34개 정상 수신 ### ❌ 미해결 문제 - **회사 관리 화면**: 아직 데이터 출력 안 됨 (API 응답은 200 OK) - **대시보드 통계**: 500 에러 (백엔드 DB 쿼리 문제) ## 📁 추가된 파일들 - `ResponseMeta` 모델 및 생성 파일들 - 전역 `LookupsService` 및 Repository 구조 - License 만료 알림 위젯들 - API 마이그레이션 문서들 ## 🚀 다음 단계 1. 회사 관리 화면 데이터 바인딩 문제 해결 2. 백엔드 DB 쿼리 오류 수정 (equipment_status enum) 3. 대시보드 통계 API 정상화 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
606 lines
26 KiB
Dart
606 lines
26 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:superport/models/user_model.dart';
|
|
import 'package:superport/screens/common/theme_shadcn.dart';
|
|
import 'package:superport/screens/common/components/shadcn_components.dart';
|
|
import 'package:superport/screens/common/widgets/pagination.dart';
|
|
import 'package:superport/screens/user/controllers/user_list_controller.dart';
|
|
import 'package:superport/utils/constants.dart';
|
|
import 'package:superport/utils/user_utils.dart';
|
|
|
|
/// shadcn/ui 스타일로 재설계된 사용자 관리 화면
|
|
class UserList extends StatefulWidget {
|
|
const UserList({super.key});
|
|
|
|
@override
|
|
State<UserList> createState() => _UserListState();
|
|
}
|
|
|
|
class _UserListState extends State<UserList> {
|
|
// MockDataService 제거 - 실제 API 사용
|
|
final TextEditingController _searchController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// 초기 데이터 로드
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final controller = context.read<UserListController>();
|
|
controller.initialize(pageSize: 10); // 통일된 초기화 방식
|
|
});
|
|
|
|
// 검색 디바운싱
|
|
_searchController.addListener(() {
|
|
_onSearchChanged(_searchController.text);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_searchController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
|
|
/// 검색어 변경 처리 (디바운싱)
|
|
Timer? _debounce;
|
|
void _onSearchChanged(String query) {
|
|
if (_debounce?.isActive ?? false) _debounce!.cancel();
|
|
_debounce = Timer(const Duration(milliseconds: 300), () {
|
|
context.read<UserListController>().setSearchQuery(query); // Controller가 페이지 리셋 처리
|
|
});
|
|
}
|
|
|
|
/// 회사명 반환 함수
|
|
String _getCompanyName(int companyId) {
|
|
// TODO: CompanyService를 통해 회사 정보 가져오기
|
|
return '회사 $companyId'; // 임시 처리
|
|
}
|
|
|
|
/// 상태별 색상 반환
|
|
Color _getStatusColor(bool isActive) {
|
|
return isActive ? Colors.green : Colors.red;
|
|
}
|
|
|
|
/// 사용자 권한 표시 배지
|
|
Widget _buildUserRoleBadge(String role) {
|
|
final roleName = getRoleName(role);
|
|
ShadcnBadgeVariant variant;
|
|
|
|
switch (role) {
|
|
case 'S':
|
|
variant = ShadcnBadgeVariant.destructive;
|
|
break;
|
|
case 'M':
|
|
variant = ShadcnBadgeVariant.primary;
|
|
break;
|
|
default:
|
|
variant = ShadcnBadgeVariant.outline;
|
|
}
|
|
|
|
return ShadcnBadge(
|
|
text: roleName,
|
|
variant: variant,
|
|
size: ShadcnBadgeSize.small,
|
|
);
|
|
}
|
|
|
|
/// 사용자 추가 폼으로 이동
|
|
void _navigateToAdd() async {
|
|
final result = await Navigator.pushNamed(context, Routes.userAdd);
|
|
if (result == true && mounted) {
|
|
context.read<UserListController>().loadUsers(refresh: true);
|
|
}
|
|
}
|
|
|
|
/// 사용자 수정 폼으로 이동
|
|
void _navigateToEdit(int userId) async {
|
|
final result = await Navigator.pushNamed(
|
|
context,
|
|
Routes.userEdit,
|
|
arguments: userId,
|
|
);
|
|
if (result == true && mounted) {
|
|
context.read<UserListController>().loadUsers(refresh: true);
|
|
}
|
|
}
|
|
|
|
/// 사용자 삭제 다이얼로그
|
|
void _showDeleteDialog(int userId, String userName) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('사용자 삭제'),
|
|
content: Text('"$userName" 사용자를 정말로 삭제하시겠습니까?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('취소'),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
|
|
await context.read<UserListController>().deleteUser(userId);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('사용자가 삭제되었습니다')),
|
|
);
|
|
},
|
|
child: const Text('삭제', style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 상태 변경 확인 다이얼로그
|
|
void _showStatusChangeDialog(User user) {
|
|
final newStatus = !user.isActive;
|
|
final statusText = newStatus ? '활성화' : '비활성화';
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text('사용자 상태 변경'),
|
|
content: Text('"${user.name}" 사용자를 $statusText 하시겠습니까?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('취소'),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
|
|
await context.read<UserListController>().changeUserStatus(user, newStatus);
|
|
},
|
|
child: Text(statusText),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ChangeNotifierProvider(
|
|
create: (_) => UserListController(),
|
|
child: Consumer<UserListController>(
|
|
builder: (context, controller, child) {
|
|
if (controller.isLoading && controller.users.isEmpty) {
|
|
return const Center(
|
|
child: CircularProgressIndicator(),
|
|
);
|
|
}
|
|
|
|
if (controller.error != null && controller.users.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.error_outline, size: 64, color: Colors.red[300]),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'데이터를 불러올 수 없습니다',
|
|
style: ShadcnTheme.headingH4,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
controller.error!,
|
|
style: ShadcnTheme.bodyMuted,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 16),
|
|
ShadcnButton(
|
|
text: '다시 시도',
|
|
onPressed: () => controller.loadUsers(refresh: true),
|
|
variant: ShadcnButtonVariant.primary,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// Controller가 이미 페이징된 데이터를 제공
|
|
final List<User> pagedUsers = controller.users; // 이미 페이징됨
|
|
final int totalUsers = controller.total; // 실제 전체 개수
|
|
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(ShadcnTheme.spacing6),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 검색 및 필터 섹션
|
|
Card(
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(ShadcnTheme.radiusMd),
|
|
side: BorderSide(color: Colors.black),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(ShadcnTheme.spacing4),
|
|
child: Column(
|
|
children: [
|
|
// 검색 바
|
|
TextField(
|
|
controller: _searchController,
|
|
decoration: InputDecoration(
|
|
hintText: '이름, 이메일, 사용자명으로 검색...',
|
|
prefixIcon: const Icon(Icons.search),
|
|
suffixIcon: _searchController.text.isNotEmpty
|
|
? IconButton(
|
|
icon: const Icon(Icons.clear),
|
|
onPressed: () {
|
|
_searchController.clear();
|
|
controller.setSearchQuery('');
|
|
},
|
|
)
|
|
: null,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(ShadcnTheme.radiusMd),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: ShadcnTheme.spacing4,
|
|
vertical: ShadcnTheme.spacing3,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: ShadcnTheme.spacing3),
|
|
// 필터 버튼들
|
|
Row(
|
|
children: [
|
|
// 상태 필터
|
|
ShadcnButton(
|
|
text: controller.filterIsActive == null
|
|
? '모든 상태'
|
|
: controller.filterIsActive!
|
|
? '활성 사용자'
|
|
: '비활성 사용자',
|
|
onPressed: () {
|
|
controller.setFilters(
|
|
isActive: controller.filterIsActive == null
|
|
? true
|
|
: controller.filterIsActive!
|
|
? false
|
|
: null,
|
|
);
|
|
},
|
|
variant: ShadcnButtonVariant.secondary,
|
|
icon: const Icon(Icons.filter_list),
|
|
),
|
|
const SizedBox(width: ShadcnTheme.spacing2),
|
|
// 권한 필터
|
|
PopupMenuButton<String?>(
|
|
child: ShadcnButton(
|
|
text: controller.filterRole == null
|
|
? '모든 권한'
|
|
: getRoleName(controller.filterRole!),
|
|
onPressed: null,
|
|
variant: ShadcnButtonVariant.secondary,
|
|
icon: const Icon(Icons.person),
|
|
),
|
|
onSelected: (role) {
|
|
controller.setFilters(role: role);
|
|
},
|
|
itemBuilder: (context) => [
|
|
const PopupMenuItem(
|
|
value: null,
|
|
child: Text('모든 권한'),
|
|
),
|
|
const PopupMenuItem(
|
|
value: 'S',
|
|
child: Text('관리자'),
|
|
),
|
|
const PopupMenuItem(
|
|
value: 'M',
|
|
child: Text('맴버'),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
// 관리자용 비활성 포함 체크박스
|
|
Row(
|
|
children: [
|
|
Checkbox(
|
|
value: controller.includeInactive,
|
|
onChanged: (_) => setState(() {
|
|
controller.toggleIncludeInactive();
|
|
}),
|
|
),
|
|
const Text('비활성 포함'),
|
|
],
|
|
),
|
|
const SizedBox(width: ShadcnTheme.spacing2),
|
|
// 필터 초기화
|
|
if (controller.searchQuery.isNotEmpty ||
|
|
controller.filterIsActive != null ||
|
|
controller.filterRole != null)
|
|
ShadcnButton(
|
|
text: '필터 초기화',
|
|
onPressed: () {
|
|
_searchController.clear();
|
|
controller.clearFilters();
|
|
},
|
|
variant: ShadcnButtonVariant.ghost,
|
|
icon: const Icon(Icons.clear_all),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: ShadcnTheme.spacing4),
|
|
|
|
// 헤더 액션 바
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'총 ${controller.users.length}명 사용자',
|
|
style: ShadcnTheme.bodyMuted,
|
|
),
|
|
Row(
|
|
children: [
|
|
ShadcnButton(
|
|
text: '새로고침',
|
|
onPressed: () => controller.loadUsers(refresh: true),
|
|
variant: ShadcnButtonVariant.secondary,
|
|
icon: const Icon(Icons.refresh),
|
|
),
|
|
const SizedBox(width: ShadcnTheme.spacing2),
|
|
ShadcnButton(
|
|
text: '사용자 추가',
|
|
onPressed: _navigateToAdd,
|
|
variant: ShadcnButtonVariant.primary,
|
|
textColor: Colors.white,
|
|
icon: const Icon(Icons.add),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: ShadcnTheme.spacing4),
|
|
|
|
// 테이블 컨테이너
|
|
Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.black),
|
|
borderRadius: BorderRadius.circular(ShadcnTheme.radiusMd),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 테이블 헤더
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: ShadcnTheme.spacing4,
|
|
vertical: ShadcnTheme.spacing3,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: ShadcnTheme.muted.withValues(alpha: 0.3),
|
|
border: Border(
|
|
bottom: BorderSide(color: Colors.black),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
const SizedBox(width: 50, child: Text('번호', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const Expanded(flex: 2, child: Text('사용자명', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const Expanded(flex: 2, child: Text('이메일', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const Expanded(flex: 2, child: Text('회사명', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const Expanded(flex: 2, child: Text('지점명', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const SizedBox(width: 100, child: Text('권한', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const SizedBox(width: 80, child: Text('상태', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
const SizedBox(width: 120, child: Text('관리', style: TextStyle(fontWeight: FontWeight.bold))),
|
|
],
|
|
),
|
|
),
|
|
|
|
// 테이블 데이터
|
|
if (controller.users.isEmpty)
|
|
Container(
|
|
padding: const EdgeInsets.all(ShadcnTheme.spacing8),
|
|
child: Center(
|
|
child: Text(
|
|
controller.searchQuery.isNotEmpty ||
|
|
controller.filterIsActive != null ||
|
|
controller.filterRole != null
|
|
? '검색 결과가 없습니다.'
|
|
: '등록된 사용자가 없습니다.',
|
|
style: ShadcnTheme.bodyMuted,
|
|
),
|
|
),
|
|
)
|
|
else
|
|
...pagedUsers.asMap().entries.map((entry) {
|
|
final int index = ((controller.currentPage - 1) * controller.pageSize) + entry.key;
|
|
final User user = entry.value;
|
|
|
|
return Container(
|
|
padding: const EdgeInsets.all(ShadcnTheme.spacing4),
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
bottom: BorderSide(color: Colors.black),
|
|
),
|
|
color: index % 2 == 0 ? null : ShadcnTheme.muted.withValues(alpha: 0.1),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
// 번호
|
|
SizedBox(
|
|
width: 50,
|
|
child: Text(
|
|
'${index + 1}',
|
|
style: ShadcnTheme.bodySmall,
|
|
),
|
|
),
|
|
// 사용자명
|
|
Expanded(
|
|
flex: 2,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
user.name,
|
|
style: ShadcnTheme.bodyMedium,
|
|
),
|
|
if (user.username != null)
|
|
Text(
|
|
'@${user.username}',
|
|
style: ShadcnTheme.bodySmall.copyWith(
|
|
color: ShadcnTheme.muted,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// 이메일
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
user.email ?? '미등록',
|
|
style: ShadcnTheme.bodySmall,
|
|
),
|
|
),
|
|
// 회사명
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
_getCompanyName(user.companyId),
|
|
style: ShadcnTheme.bodySmall,
|
|
),
|
|
),
|
|
// 지점명
|
|
Expanded(
|
|
flex: 2,
|
|
child: Text(
|
|
controller.getBranchName(user.branchId),
|
|
style: ShadcnTheme.bodySmall,
|
|
),
|
|
),
|
|
// 권한
|
|
SizedBox(
|
|
width: 100,
|
|
child: _buildUserRoleBadge(user.role),
|
|
),
|
|
// 상태
|
|
SizedBox(
|
|
width: 80,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.circle,
|
|
size: 8,
|
|
color: _getStatusColor(user.isActive),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
user.isActive ? '활성' : '비활성',
|
|
style: ShadcnTheme.bodySmall.copyWith(
|
|
color: _getStatusColor(user.isActive),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// 관리
|
|
SizedBox(
|
|
width: 120,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Flexible(
|
|
child: IconButton(
|
|
constraints: const BoxConstraints(
|
|
minWidth: 30,
|
|
minHeight: 30,
|
|
),
|
|
padding: const EdgeInsets.all(4),
|
|
icon: Icon(
|
|
Icons.power_settings_new,
|
|
size: 16,
|
|
color: user.isActive ? Colors.orange : Colors.green,
|
|
),
|
|
onPressed: user.id != null
|
|
? () => _showStatusChangeDialog(user)
|
|
: null,
|
|
tooltip: user.isActive ? '비활성화' : '활성화',
|
|
),
|
|
),
|
|
Flexible(
|
|
child: IconButton(
|
|
constraints: const BoxConstraints(
|
|
minWidth: 30,
|
|
minHeight: 30,
|
|
),
|
|
padding: const EdgeInsets.all(4),
|
|
icon: Icon(
|
|
Icons.edit,
|
|
size: 16,
|
|
color: ShadcnTheme.primary,
|
|
),
|
|
onPressed: user.id != null
|
|
? () => _navigateToEdit(user.id!)
|
|
: null,
|
|
tooltip: '수정',
|
|
),
|
|
),
|
|
Flexible(
|
|
child: IconButton(
|
|
constraints: const BoxConstraints(
|
|
minWidth: 30,
|
|
minHeight: 30,
|
|
),
|
|
padding: const EdgeInsets.all(4),
|
|
icon: Icon(
|
|
Icons.delete,
|
|
size: 16,
|
|
color: ShadcnTheme.destructive,
|
|
),
|
|
onPressed: user.id != null
|
|
? () => _showDeleteDialog(user.id!, user.name)
|
|
: null,
|
|
tooltip: '삭제',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
|
|
// 페이지네이션 컴포넌트 (Controller 상태 사용)
|
|
if (controller.total > controller.pageSize)
|
|
Pagination(
|
|
totalCount: controller.total,
|
|
currentPage: controller.currentPage,
|
|
pageSize: controller.pageSize,
|
|
onPageChanged: (page) {
|
|
// 다음 페이지 로드
|
|
if (page > controller.currentPage) {
|
|
controller.loadNextPage();
|
|
} else if (page == 1) {
|
|
controller.refresh();
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|