feat: 대규모 코드베이스 개선 - 백엔드 통합성 강화 및 UI 일관성 완성
- CLAUDE.md 대폭 개선: 개발 가이드라인 및 프로젝트 상태 문서화 - 백엔드 API 통합: 모든 엔티티 간 Foreign Key 관계 완벽 구현 - UI 일관성 강화: shadcn_ui 컴포넌트 표준화 적용 - 데이터 모델 개선: DTO 및 모델 클래스 백엔드 스키마와 100% 일치 - 사용자 관리: 회사 연결, 중복 검사, 입력 검증 기능 추가 - 창고 관리: 우편번호 연결, 중복 검사 기능 강화 - 회사 관리: 우편번호 연결, 중복 검사 로직 구현 - 장비 관리: 불필요한 카테고리 필드 제거, 벤더-모델 관계 정리 - 우편번호 시스템: 검색 다이얼로그 Provider 버그 수정 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
final LookupsService _lookupsService = GetIt.instance<LookupsService>();
|
||||
final int? equipmentInId; // 실제로는 장비 ID (입고 ID가 아님)
|
||||
int? actualEquipmentId; // API 호출용 실제 장비 ID
|
||||
EquipmentDto? preloadedEquipment; // 사전 로드된 장비 데이터
|
||||
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
@@ -60,9 +61,6 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
// Legacy 필드 (UI 호환성 유지용)
|
||||
String _manufacturer = ''; // 제조사 (Legacy) - ModelDto에서 가져옴
|
||||
String _name = ''; // 모델명 (Legacy) - ModelDto에서 가져옴
|
||||
String _category1 = ''; // 대분류 (Legacy)
|
||||
String _category2 = ''; // 중분류 (Legacy)
|
||||
String _category3 = ''; // 소분류 (Legacy)
|
||||
|
||||
// Getters and Setters for reactive fields
|
||||
String get serialNumber => _serialNumber;
|
||||
@@ -92,29 +90,6 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
String get category1 => _category1;
|
||||
set category1(String value) {
|
||||
if (_category1 != value) {
|
||||
_category1 = value;
|
||||
_updateCanSave(); // canSave 상태 업데이트
|
||||
}
|
||||
}
|
||||
|
||||
String get category2 => _category2;
|
||||
set category2(String value) {
|
||||
if (_category2 != value) {
|
||||
_category2 = value;
|
||||
_updateCanSave(); // canSave 상태 업데이트
|
||||
}
|
||||
}
|
||||
|
||||
String get category3 => _category3;
|
||||
set category3(String value) {
|
||||
if (_category3 != value) {
|
||||
_category3 = value;
|
||||
_updateCanSave(); // canSave 상태 업데이트
|
||||
}
|
||||
}
|
||||
|
||||
// 새로운 필드 getters/setters
|
||||
int? get modelsId => _modelsId;
|
||||
@@ -209,6 +184,7 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
DateTime warrantyEndDate = DateTime.now().add(const Duration(days: 365));
|
||||
|
||||
final TextEditingController remarkController = TextEditingController();
|
||||
final TextEditingController warrantyNumberController = TextEditingController();
|
||||
|
||||
EquipmentInFormController({this.equipmentInId}) {
|
||||
isEditMode = equipmentInId != null;
|
||||
@@ -216,13 +192,68 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
_updateCanSave(); // 초기 canSave 상태 설정
|
||||
// 수정 모드일 때 초기 데이터 로드는 initializeForEdit() 메서드로 이동
|
||||
}
|
||||
|
||||
// 사전 로드된 데이터로 초기화하는 생성자
|
||||
EquipmentInFormController.withPreloadedData({
|
||||
required Map<String, dynamic> preloadedData,
|
||||
}) : equipmentInId = preloadedData['equipmentId'] as int?,
|
||||
actualEquipmentId = preloadedData['equipmentId'] as int? {
|
||||
isEditMode = equipmentInId != null;
|
||||
|
||||
// 전달받은 데이터로 즉시 초기화
|
||||
preloadedEquipment = preloadedData['equipment'] as EquipmentDto?;
|
||||
final dropdownData = preloadedData['dropdownData'] as Map<String, dynamic>?;
|
||||
|
||||
if (dropdownData != null) {
|
||||
_processDropdownData(dropdownData);
|
||||
}
|
||||
|
||||
if (preloadedEquipment != null) {
|
||||
_loadFromEquipment(preloadedEquipment!);
|
||||
}
|
||||
|
||||
_updateCanSave();
|
||||
}
|
||||
|
||||
// 수정 모드 초기화 (외부에서 호출)
|
||||
Future<void> initializeForEdit() async {
|
||||
if (!isEditMode || equipmentInId == null) return;
|
||||
await _loadEquipmentIn();
|
||||
|
||||
// 드롭다운 데이터와 장비 데이터를 병렬로 로드
|
||||
await Future.wait([
|
||||
_waitForDropdownData(),
|
||||
_loadEquipmentIn(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 드롭다운 데이터 로드 대기
|
||||
Future<void> _waitForDropdownData() async {
|
||||
int retryCount = 0;
|
||||
while ((companies.isEmpty || warehouses.isEmpty) && retryCount < 10) {
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
retryCount++;
|
||||
if (retryCount % 3 == 0) {
|
||||
print('DEBUG [_waitForDropdownData] Waiting for dropdown data... retry: $retryCount');
|
||||
}
|
||||
}
|
||||
print('DEBUG [_waitForDropdownData] Dropdown data loaded - companies: ${companies.length}, warehouses: ${warehouses.length}');
|
||||
}
|
||||
|
||||
// 드롭다운 데이터 처리 (사전 로드된 데이터에서)
|
||||
void _processDropdownData(Map<String, dynamic> data) {
|
||||
manufacturers = data['manufacturers'] as List<String>? ?? [];
|
||||
equipmentNames = data['equipment_names'] as List<String>? ?? [];
|
||||
companies = data['companies'] as Map<int, String>? ?? {};
|
||||
warehouses = data['warehouses'] as Map<int, String>? ?? {};
|
||||
|
||||
DebugLogger.log('드롭다운 데이터 처리 완료', tag: 'EQUIPMENT_IN', data: {
|
||||
'manufacturers_count': manufacturers.length,
|
||||
'equipment_names_count': equipmentNames.length,
|
||||
'companies_count': companies.length,
|
||||
'warehouses_count': warehouses.length,
|
||||
});
|
||||
}
|
||||
|
||||
// 드롭다운 데이터 로드 (매번 API 호출)
|
||||
void _loadDropdownData() async {
|
||||
try {
|
||||
@@ -268,6 +299,24 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
// 기존의 개별 로드 메서드들은 _loadDropdownData()로 통합됨
|
||||
// warehouseLocations, partnerCompanies 리스트 변수들도 제거됨
|
||||
|
||||
// 전달받은 장비 데이터로 폼 초기화
|
||||
void _loadFromEquipment(EquipmentDto equipment) {
|
||||
serialNumber = equipment.serialNumber;
|
||||
modelsId = equipment.modelsId;
|
||||
// vendorId는 ModelDto에서 가져와야 함 (필요 시)
|
||||
purchasePrice = equipment.purchasePrice.toDouble();
|
||||
initialStock = 1; // EquipmentDto에는 initialStock 필드가 없음
|
||||
selectedCompanyId = equipment.companiesId;
|
||||
// selectedWarehouseId는 현재 위치를 추적해야 함 (EquipmentHistory에서)
|
||||
remarkController.text = equipment.remark ?? '';
|
||||
warrantyNumberController.text = equipment.warrantyNumber;
|
||||
|
||||
warrantyStartDate = equipment.warrantyStartedAt;
|
||||
warrantyEndDate = equipment.warrantyEndedAt;
|
||||
|
||||
_updateCanSave();
|
||||
}
|
||||
|
||||
// 기존 데이터 로드(수정 모드)
|
||||
Future<void> _loadEquipmentIn() async {
|
||||
if (equipmentInId == null) return;
|
||||
@@ -303,18 +352,29 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
print('DEBUG [_loadEquipmentIn] equipment.serialNumber="${equipment.serialNumber}"');
|
||||
|
||||
// 백엔드 실제 필드로 매핑
|
||||
_serialNumber = equipment.serialNumber ?? '';
|
||||
_serialNumber = equipment.serialNumber;
|
||||
_modelsId = equipment.modelsId; // 백엔드 실제 필드
|
||||
selectedCompanyId = equipment.companiesId; // companyId → companiesId
|
||||
purchasePrice = equipment.purchasePrice.toDouble(); // int → double 변환
|
||||
purchasePrice = equipment.purchasePrice > 0 ? equipment.purchasePrice.toDouble() : null; // int → double 변환, 0이면 null
|
||||
remarkController.text = equipment.remark ?? '';
|
||||
|
||||
// Legacy 필드들은 기본값으로 설정 (UI 호환성)
|
||||
manufacturer = ''; // 더 이상 백엔드에서 제공안함
|
||||
name = '';
|
||||
category1 = '';
|
||||
category2 = '';
|
||||
category3 = '';
|
||||
// Legacy 필드들 - 백엔드에서 제공하는 정보 사용
|
||||
manufacturer = equipment.vendorName ?? ''; // vendor_name 사용
|
||||
name = equipment.modelName ?? ''; // model_name 사용
|
||||
|
||||
// 날짜 필드 설정
|
||||
if (equipment.purchasedAt != null) {
|
||||
purchaseDate = equipment.purchasedAt;
|
||||
}
|
||||
|
||||
// 보증 정보 설정
|
||||
if (equipment.warrantyStartedAt != null) {
|
||||
warrantyStartDate = equipment.warrantyStartedAt;
|
||||
}
|
||||
if (equipment.warrantyEndedAt != null) {
|
||||
warrantyEndDate = equipment.warrantyEndedAt;
|
||||
}
|
||||
warrantyNumberController.text = equipment.warrantyNumber;
|
||||
|
||||
print('DEBUG [_loadEquipmentIn] After setting - serialNumber="$_serialNumber", manufacturer="$_manufacturer", name="$_name"');
|
||||
// 🔧 [DEBUG] UI 업데이트를 위한 중요 필드들 로깅
|
||||
@@ -426,19 +486,44 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
});
|
||||
|
||||
// Equipment 객체를 EquipmentUpdateRequestDto로 변환
|
||||
// 수정 시에는 실제로 값이 있는 필드만 전송
|
||||
// companies가 로드되었고 selectedCompanyId가 유효한 경우에만 포함
|
||||
final validCompanyId = companies.isNotEmpty && companies.containsKey(selectedCompanyId)
|
||||
? selectedCompanyId
|
||||
: null;
|
||||
|
||||
// 보증 번호가 비어있으면 원본 값 사용 또는 기본값
|
||||
final validWarrantyNumber = warrantyNumberController.text.trim().isNotEmpty
|
||||
? warrantyNumberController.text.trim()
|
||||
: 'WR-${DateTime.now().millisecondsSinceEpoch}'; // 기본값 생성
|
||||
|
||||
final updateRequest = EquipmentUpdateRequestDto(
|
||||
companiesId: selectedCompanyId ?? 0,
|
||||
modelsId: _modelsId ?? 0,
|
||||
serialNumber: _serialNumber,
|
||||
companiesId: validCompanyId,
|
||||
modelsId: _modelsId,
|
||||
serialNumber: _serialNumber.trim(),
|
||||
barcode: null,
|
||||
purchasedAt: null,
|
||||
purchasePrice: purchasePrice?.toInt() ?? 0,
|
||||
warrantyNumber: '',
|
||||
warrantyStartedAt: DateTime.now(),
|
||||
warrantyEndedAt: DateTime.now().add(Duration(days: 365)),
|
||||
remark: remarkController.text.isNotEmpty ? remarkController.text : null,
|
||||
purchasedAt: purchaseDate,
|
||||
purchasePrice: purchasePrice?.toInt(),
|
||||
warrantyNumber: validWarrantyNumber,
|
||||
warrantyStartedAt: warrantyStartDate,
|
||||
warrantyEndedAt: warrantyEndDate,
|
||||
remark: remarkController.text.trim().isNotEmpty ? remarkController.text.trim() : null,
|
||||
);
|
||||
|
||||
// 디버그: 전송할 데이터 로깅
|
||||
DebugLogger.log('장비 업데이트 요청 데이터', tag: 'EQUIPMENT_UPDATE', data: {
|
||||
'equipmentId': actualEquipmentId,
|
||||
'companiesId': updateRequest.companiesId,
|
||||
'modelsId': updateRequest.modelsId,
|
||||
'serialNumber': updateRequest.serialNumber,
|
||||
'purchasedAt': updateRequest.purchasedAt?.toIso8601String(),
|
||||
'purchasePrice': updateRequest.purchasePrice,
|
||||
'warrantyNumber': updateRequest.warrantyNumber,
|
||||
'warrantyStartedAt': updateRequest.warrantyStartedAt?.toIso8601String(),
|
||||
'warrantyEndedAt': updateRequest.warrantyEndedAt?.toIso8601String(),
|
||||
'remark': updateRequest.remark,
|
||||
});
|
||||
|
||||
await _equipmentService.updateEquipment(actualEquipmentId!, updateRequest);
|
||||
|
||||
DebugLogger.log('장비 정보 업데이트 성공', tag: 'EQUIPMENT_IN');
|
||||
@@ -541,6 +626,7 @@ class EquipmentInFormController extends ChangeNotifier {
|
||||
@override
|
||||
void dispose() {
|
||||
remarkController.dispose();
|
||||
warrantyNumberController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ class EquipmentListController extends BaseListController<UnifiedEquipment> {
|
||||
|
||||
// 추가 상태 관리
|
||||
final Set<String> selectedEquipmentIds = {}; // 'id:status' 형식
|
||||
Map<String, dynamic>? cachedDropdownData; // 드롭다운 데이터 캐시
|
||||
|
||||
// 필터
|
||||
String? _statusFilter;
|
||||
@@ -191,6 +192,32 @@ class EquipmentListController extends BaseListController<UnifiedEquipment> {
|
||||
return groupedEquipments;
|
||||
}
|
||||
|
||||
/// 드롭다운 데이터를 미리 로드하는 메서드
|
||||
Future<void> preloadDropdownData() async {
|
||||
try {
|
||||
final result = await _lookupsService.getEquipmentFormDropdownData();
|
||||
result.fold(
|
||||
(failure) => throw failure,
|
||||
(data) => cachedDropdownData = data,
|
||||
);
|
||||
} catch (e) {
|
||||
print('Failed to preload dropdown data: $e');
|
||||
// 캐시 실패해도 계속 진행
|
||||
}
|
||||
}
|
||||
|
||||
/// 장비 상세 데이터 로드
|
||||
Future<EquipmentDto?> loadEquipmentDetail(int equipmentId) async {
|
||||
try {
|
||||
// getEquipmentDetail 메서드 사용 (getEquipmentById는 존재하지 않음)
|
||||
final equipment = await _equipmentService.getEquipmentDetail(equipmentId);
|
||||
return equipment;
|
||||
} catch (e) {
|
||||
print('Failed to load equipment detail: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 필터 설정
|
||||
void setFilters({
|
||||
String? status,
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/screens/common/templates/form_layout_template.dart';
|
||||
import 'package:superport/utils/currency_formatter.dart';
|
||||
import 'package:superport/core/widgets/category_cascade_form_field.dart';
|
||||
import 'controllers/equipment_in_form_controller.dart';
|
||||
import 'widgets/equipment_vendor_model_selector.dart';
|
||||
import 'package:superport/utils/formatters/number_formatter.dart';
|
||||
@@ -11,8 +10,9 @@ import 'package:superport/utils/formatters/number_formatter.dart';
|
||||
/// 새로운 Equipment 입고 폼 (Lookup API 기반)
|
||||
class EquipmentInFormScreen extends StatefulWidget {
|
||||
final int? equipmentInId;
|
||||
final Map<String, dynamic>? preloadedData; // 사전 로드된 데이터
|
||||
|
||||
const EquipmentInFormScreen({super.key, this.equipmentInId});
|
||||
const EquipmentInFormScreen({super.key, this.equipmentInId, this.preloadedData});
|
||||
|
||||
@override
|
||||
State<EquipmentInFormScreen> createState() => _EquipmentInFormScreenState();
|
||||
@@ -23,35 +23,49 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
|
||||
late TextEditingController _serialNumberController;
|
||||
late TextEditingController _initialStockController;
|
||||
late TextEditingController _purchasePriceController;
|
||||
Future<void>? _initFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = EquipmentInFormController(equipmentInId: widget.equipmentInId);
|
||||
|
||||
// preloadedData가 있으면 전달, 없으면 일반 초기화
|
||||
if (widget.preloadedData != null) {
|
||||
_controller = EquipmentInFormController.withPreloadedData(
|
||||
preloadedData: widget.preloadedData!,
|
||||
);
|
||||
_initFuture = Future.value(); // 데이터가 이미 있으므로 즉시 완료
|
||||
} else {
|
||||
_controller = EquipmentInFormController(equipmentInId: widget.equipmentInId);
|
||||
// 수정 모드일 때 데이터 로드를 Future로 처리
|
||||
if (_controller.isEditMode) {
|
||||
_initFuture = _initializeEditMode();
|
||||
} else {
|
||||
_initFuture = Future.value(); // 신규 모드는 즉시 완료
|
||||
}
|
||||
}
|
||||
|
||||
_controller.addListener(_onControllerUpdated);
|
||||
|
||||
// TextEditingController 초기화
|
||||
_serialNumberController = TextEditingController(text: _controller.serialNumber);
|
||||
_serialNumberController = TextEditingController(text: _controller.serialNumber);
|
||||
_initialStockController = TextEditingController(text: _controller.initialStock.toString());
|
||||
_purchasePriceController = TextEditingController(
|
||||
text: _controller.purchasePrice != null
|
||||
? CurrencyFormatter.formatKRW(_controller.purchasePrice)
|
||||
: ''
|
||||
);
|
||||
|
||||
// 수정 모드일 때 데이터 로드
|
||||
if (_controller.isEditMode) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await _controller.initializeForEdit();
|
||||
// 데이터 로드 후 컨트롤러 업데이트
|
||||
_serialNumberController.text = _controller.serialNumber;
|
||||
_serialNumberController.text = _controller.serialNumber;
|
||||
_purchasePriceController.text = _controller.purchasePrice != null
|
||||
? CurrencyFormatter.formatKRW(_controller.purchasePrice)
|
||||
: '';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initializeEditMode() async {
|
||||
await _controller.initializeForEdit();
|
||||
// 데이터 로드 후 컨트롤러 업데이트
|
||||
setState(() {
|
||||
_serialNumberController.text = _controller.serialNumber;
|
||||
_purchasePriceController.text = _controller.purchasePrice != null
|
||||
? CurrencyFormatter.formatKRW(_controller.purchasePrice)
|
||||
: '';
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -112,32 +126,54 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
|
||||
// 간소화된 디버깅
|
||||
print('🎯 [UI] canSave: ${_controller.canSave} | 장비번호: "${_controller.serialNumber}" | 제조사: "${_controller.manufacturer}"');
|
||||
|
||||
return FormLayoutTemplate(
|
||||
title: _controller.isEditMode ? '장비 수정' : '장비 입고',
|
||||
onSave: _controller.canSave && !_controller.isSaving ? _onSave : null,
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
isLoading: _controller.isSaving,
|
||||
child: _controller.isLoading
|
||||
? const Center(child: ShadProgress())
|
||||
: Form(
|
||||
key: _controller.formKey,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildBasicFields(),
|
||||
const SizedBox(height: 24),
|
||||
_buildCategorySection(),
|
||||
const SizedBox(height: 24),
|
||||
_buildLocationSection(),
|
||||
const SizedBox(height: 24),
|
||||
_buildPurchaseSection(),
|
||||
const SizedBox(height: 24),
|
||||
_buildRemarkSection(),
|
||||
],
|
||||
),
|
||||
return FutureBuilder<void>(
|
||||
future: _initFuture,
|
||||
builder: (context, snapshot) {
|
||||
// 수정 모드에서 데이터 로딩 중일 때 로딩 화면 표시
|
||||
if (_controller.isEditMode && snapshot.connectionState != ConnectionState.done) {
|
||||
return FormLayoutTemplate(
|
||||
title: '장비 정보 로딩 중...',
|
||||
onSave: null,
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
isLoading: false,
|
||||
child: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ShadProgress(),
|
||||
SizedBox(height: 16),
|
||||
Text('장비 정보를 불러오는 중입니다...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 데이터 로드 완료 또는 신규 모드
|
||||
return FormLayoutTemplate(
|
||||
title: _controller.isEditMode ? '장비 수정' : '장비 입고',
|
||||
onSave: _controller.canSave && !_controller.isSaving ? _onSave : null,
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
isLoading: _controller.isSaving,
|
||||
child: Form(
|
||||
key: _controller.formKey,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 24),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildBasicFields(),
|
||||
const SizedBox(height: 24),
|
||||
_buildLocationSection(),
|
||||
const SizedBox(height: 24),
|
||||
_buildPurchaseSection(),
|
||||
const SizedBox(height: 24),
|
||||
_buildRemarkSection(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,36 +244,6 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCategorySection() {
|
||||
return ShadCard(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'장비 분류',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CategoryCascadeFormField(
|
||||
category1: _controller.category1.isEmpty ? null : _controller.category1,
|
||||
category2: _controller.category2.isEmpty ? null : _controller.category2,
|
||||
category3: _controller.category3.isEmpty ? null : _controller.category3,
|
||||
onChanged: (cat1, cat2, cat3) {
|
||||
_controller.category1 = cat1?.trim() ?? '';
|
||||
_controller.category2 = cat2?.trim() ?? '';
|
||||
_controller.category3 = cat3?.trim() ?? '';
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLocationSection() {
|
||||
return ShadCard(
|
||||
@@ -264,8 +270,13 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
|
||||
child: Text(entry.value),
|
||||
)
|
||||
).toList(),
|
||||
selectedOptionBuilder: (context, value) =>
|
||||
Text(_controller.companies[value] ?? '선택하세요'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
// companies가 비어있거나 해당 value가 없는 경우 처리
|
||||
if (_controller.companies.isEmpty) {
|
||||
return const Text('로딩중...');
|
||||
}
|
||||
return Text(_controller.companies[value] ?? '선택하세요');
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_controller.selectedCompanyId = value;
|
||||
@@ -285,8 +296,13 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
|
||||
child: Text(entry.value),
|
||||
)
|
||||
).toList(),
|
||||
selectedOptionBuilder: (context, value) =>
|
||||
Text(_controller.warehouses[value] ?? '선택하세요'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
// warehouses가 비어있거나 해당 value가 없는 경우 처리
|
||||
if (_controller.warehouses.isEmpty) {
|
||||
return const Text('로딩중...');
|
||||
}
|
||||
return Text(_controller.warehouses[value] ?? '선택하세요');
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_controller.selectedWarehouseId = value;
|
||||
|
||||
@@ -32,6 +32,7 @@ class _EquipmentListState extends State<EquipmentList> {
|
||||
String _appliedSearchKeyword = '';
|
||||
// 페이지 상태는 이제 Controller에서 관리
|
||||
final Set<int> _selectedItems = {};
|
||||
Map<String, dynamic>? _cachedDropdownData; // 드롭다운 데이터 캐시
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -39,6 +40,7 @@ class _EquipmentListState extends State<EquipmentList> {
|
||||
_controller = EquipmentListController();
|
||||
_controller.pageSize = 10; // 페이지 크기 설정
|
||||
_setInitialFilter();
|
||||
_preloadDropdownData(); // 드롭다운 데이터 미리 로드
|
||||
|
||||
// API 호출을 위해 Future로 변경
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@@ -46,6 +48,20 @@ class _EquipmentListState extends State<EquipmentList> {
|
||||
});
|
||||
}
|
||||
|
||||
// 드롭다운 데이터를 미리 로드하는 메서드
|
||||
Future<void> _preloadDropdownData() async {
|
||||
try {
|
||||
await _controller.preloadDropdownData();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_cachedDropdownData = _controller.cachedDropdownData;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print('Failed to preload dropdown data: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
@@ -343,6 +359,18 @@ class _EquipmentListState extends State<EquipmentList> {
|
||||
reasonController.dispose();
|
||||
}
|
||||
|
||||
/// 드롭다운 데이터 확인 및 로드
|
||||
Future<Map<String, dynamic>> _ensureDropdownData() async {
|
||||
// 캐시된 데이터가 있으면 반환
|
||||
if (_cachedDropdownData != null) {
|
||||
return _cachedDropdownData!;
|
||||
}
|
||||
|
||||
// 없으면 새로 로드
|
||||
await _preloadDropdownData();
|
||||
return _cachedDropdownData ?? {};
|
||||
}
|
||||
|
||||
/// 편집 핸들러
|
||||
void _handleEdit(UnifiedEquipment equipment) async {
|
||||
// 디버그: 실제 상태 값 확인
|
||||
@@ -350,18 +378,87 @@ class _EquipmentListState extends State<EquipmentList> {
|
||||
print('DEBUG: equipment.id = ${equipment.id}');
|
||||
print('DEBUG: equipment.equipment.id = ${equipment.equipment.id}');
|
||||
|
||||
// 모든 상태의 장비 수정 가능
|
||||
// equipment.equipment.id를 사용해야 실제 장비 ID임
|
||||
final result = await Navigator.pushNamed(
|
||||
context,
|
||||
Routes.equipmentInEdit,
|
||||
arguments: equipment.equipment.id ?? equipment.id, // 실제 장비 ID 전달
|
||||
// 로딩 다이얼로그 표시
|
||||
showShadDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => ShadDialog(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: const Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShadProgress(),
|
||||
SizedBox(height: 16),
|
||||
Text('장비 정보를 불러오는 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (result == true) {
|
||||
setState(() {
|
||||
_controller.loadData(isRefresh: true);
|
||||
_controller.goToPage(1);
|
||||
});
|
||||
|
||||
try {
|
||||
// 장비 상세 데이터와 드롭다운 데이터를 병렬로 로드
|
||||
final results = await Future.wait([
|
||||
_controller.loadEquipmentDetail(equipment.equipment.id!),
|
||||
_ensureDropdownData(),
|
||||
]);
|
||||
|
||||
final equipmentDetail = results[0];
|
||||
final dropdownData = results[1] as Map<String, dynamic>;
|
||||
|
||||
// 로딩 다이얼로그 닫기
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
if (equipmentDetail == null) {
|
||||
if (mounted) {
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: const Text('오류'),
|
||||
description: const Text('장비 정보를 불러올 수 없습니다.'),
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('확인'),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 모든 데이터를 arguments로 전달
|
||||
final result = await Navigator.pushNamed(
|
||||
context,
|
||||
Routes.equipmentInEdit,
|
||||
arguments: {
|
||||
'equipmentId': equipment.equipment.id,
|
||||
'equipment': equipmentDetail,
|
||||
'dropdownData': dropdownData,
|
||||
},
|
||||
);
|
||||
|
||||
if (result == true) {
|
||||
setState(() {
|
||||
_controller.loadData(isRefresh: true);
|
||||
_controller.goToPage(1);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 오류 발생 시 로딩 다이얼로그 닫기
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: Text('장비 정보를 불러올 수 없습니다: $e'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/data/models/model_dto.dart';
|
||||
import 'package:superport/data/models/vendor_dto.dart';
|
||||
import 'package:superport/screens/vendor/controllers/vendor_controller.dart';
|
||||
import 'package:superport/screens/model/controllers/model_controller.dart';
|
||||
import 'package:superport/injection_container.dart';
|
||||
@@ -178,7 +179,13 @@ class _EquipmentVendorModelSelectorState extends State<EquipmentVendorModelSelec
|
||||
);
|
||||
}).toList(),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
final vendor = vendors.firstWhere((v) => v.id == value);
|
||||
final vendor = vendors.firstWhere(
|
||||
(v) => v.id == value,
|
||||
orElse: () => VendorDto(
|
||||
id: value,
|
||||
name: '로딩중...',
|
||||
),
|
||||
);
|
||||
return Text(vendor.name);
|
||||
},
|
||||
onChanged: widget.isReadOnly ? null : _onVendorChanged,
|
||||
@@ -221,7 +228,14 @@ class _EquipmentVendorModelSelectorState extends State<EquipmentVendorModelSelec
|
||||
);
|
||||
}).toList(),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
final model = _filteredModels.firstWhere((m) => m.id == value);
|
||||
final model = _filteredModels.firstWhere(
|
||||
(m) => m.id == value,
|
||||
orElse: () => ModelDto(
|
||||
id: value,
|
||||
name: '로딩중...',
|
||||
vendorsId: 0,
|
||||
),
|
||||
);
|
||||
return Text(model.name);
|
||||
},
|
||||
onChanged: isEnabled ? _onModelChanged : null,
|
||||
|
||||
Reference in New Issue
Block a user