feat: 장비 관리 기능 강화 및 이력 추적 개선

- EquipmentHistoryDto 모델 확장 (상세 정보 추가)
- 장비 이력 화면 UI/UX 개선
- 장비 입고 폼 검증 로직 강화
- 테스트 이력 화면 추가
- API 응답 처리 개선

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
JiWoong Sul
2025-08-09 02:17:16 +09:00
parent f8e8a95391
commit cddde57450
9 changed files with 738 additions and 258 deletions

View File

@@ -2,15 +2,16 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
// import 'package:superport/models/equipment_unified_model.dart';
import 'package:superport/screens/common/custom_widgets.dart';
// import 'package:superport/screens/common/custom_widgets.dart' hide FormFieldWrapper;
import 'package:superport/screens/common/theme_tailwind.dart';
import 'package:superport/screens/common/templates/form_layout_template.dart';
import 'package:superport/services/mock_data_service.dart';
import 'package:superport/utils/constants.dart';
// import 'package:flutter_localizations/flutter_localizations.dart';
// import 'package:superport/screens/equipment/widgets/autocomplete_text_field.dart';
import 'controllers/equipment_in_form_controller.dart';
// import 'package:superport/screens/common/widgets/category_autocomplete_field.dart';
import 'package:superport/screens/common/widgets/autocomplete_dropdown_field.dart';
// import 'package:superport/screens/common/widgets/autocomplete_dropdown_field.dart';
import 'package:superport/screens/common/widgets/remark_input.dart';
class EquipmentInFormScreen extends StatefulWidget {
@@ -66,6 +67,13 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
OverlayEntry? _subSubCategoryOverlayEntry;
final FocusNode _subSubCategoryFocusNode = FocusNode();
late TextEditingController _subSubCategoryController;
// 추가 필드 컨트롤러들
late TextEditingController _nameController;
late TextEditingController _serialNumberController;
late TextEditingController _barcodeController;
late TextEditingController _quantityController;
late TextEditingController _warrantyCodeController;
// 프로그램적 입력란 변경 여부 플래그
bool _isProgrammaticPartnerChange = false;
@@ -176,6 +184,16 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
dataService: MockDataService(),
equipmentInId: widget.equipmentInId,
);
// 수정 모드일 때 데이터 로드
if (_controller.isEditMode) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await _controller.initializeForEdit();
// 데이터 로드 후 텍스트 컨트롤러 업데이트
_updateTextControllers();
});
}
_manufacturerFocusNode = FocusNode();
_nameFieldFocusNode = FocusNode();
_partnerController = TextEditingController(
@@ -202,6 +220,13 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
_subSubCategoryController = TextEditingController(
text: _controller.subSubCategory,
);
// 추가 필드 컨트롤러 초기화
_nameController = TextEditingController(text: _controller.name);
_serialNumberController = TextEditingController(text: _controller.serialNumber);
_barcodeController = TextEditingController(text: _controller.barcode);
_quantityController = TextEditingController(text: _controller.quantity.toString());
_warrantyCodeController = TextEditingController(text: _controller.warrantyCode ?? '');
// 포커스 변경 리스너 추가
_partnerFocusNode.addListener(_onPartnerFocusChange);
@@ -213,6 +238,24 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
_subSubCategoryFocusNode.addListener(_onSubSubCategoryFocusChange);
}
// 텍스트 컨트롤러 업데이트 메서드
void _updateTextControllers() {
setState(() {
_manufacturerController.text = _controller.manufacturer;
_nameController.text = _controller.name;
_categoryController.text = _controller.category;
_subCategoryController.text = _controller.subCategory;
_subSubCategoryController.text = _controller.subSubCategory;
_serialNumberController.text = _controller.serialNumber;
_barcodeController.text = _controller.barcode;
_quantityController.text = _controller.quantity.toString();
_warehouseController.text = _controller.warehouseLocation ?? '';
_partnerController.text = _controller.partnerCompany ?? '';
_warrantyCodeController.text = _controller.warrantyCode ?? '';
_controller.remarkController.text = _controller.remarkController.text;
});
}
@override
void dispose() {
_manufacturerFocusNode.dispose();
@@ -243,7 +286,15 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
_subSubCategoryOverlayEntry?.remove();
_subSubCategoryFocusNode.dispose();
_subSubCategoryController.dispose();
// 추가 컨트롤러 정리
_nameController.dispose();
_serialNumberController.dispose();
_barcodeController.dispose();
_quantityController.dispose();
_warrantyCodeController.dispose();
_controller.dispose();
super.dispose();
}
@@ -365,19 +416,23 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
final success = await _controller.save();
// 로딩 다이얼로그 닫기
if (!mounted) return;
Navigator.pop(context);
if (success) {
// 성공 메시지 표시
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_controller.isEditMode ? '장비 입고가 수정되었습니다.' : '장비 입고가 등록되었습니다.'),
content: Text(_controller.isEditMode ? '장비 정보가 수정되었습니다.' : '장비 입고가 등록되었습니다.'),
backgroundColor: Colors.green,
),
);
if (!mounted) return;
Navigator.pop(context, true);
} else {
// 에러 메시지 표시
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_controller.error ?? '저장 중 오류가 발생했습니다.'),
@@ -387,9 +442,11 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
}
} catch (e) {
// 로딩 다이얼로그 닫기
if (!mounted) return;
Navigator.pop(context);
// 예외 처리
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('오류: $e'),
@@ -429,7 +486,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -481,7 +538,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -533,7 +590,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -585,7 +642,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -637,7 +694,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -689,7 +746,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -741,7 +798,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -793,7 +850,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -845,7 +902,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -897,7 +954,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -949,7 +1006,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -1001,7 +1058,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -1053,7 +1110,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
borderRadius: BorderRadius.circular(4),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
color: Colors.grey.withValues(alpha: 0.3),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(0, 1),
@@ -1105,7 +1162,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
child: Text(item),
),
);
}).toList(),
}),
],
),
),
@@ -1141,9 +1198,27 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
return ChangeNotifierProvider<EquipmentInFormController>.value(
value: _controller,
child: Consumer<EquipmentInFormController>(
builder: (context, controller, child) => GestureDetector(
// 화면의 다른 곳을 탭하면 모든 드롭다운 닫기
onTap: () {
builder: (context, controller, child) {
// 수정 모드에서 로딩 중일 때 로딩 인디케이터 표시
if (controller.isEditMode && controller.isLoading) {
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('장비 정보를 불러오는 중...'),
],
),
),
);
}
return GestureDetector(
// 화면의 다른 곳을 탭하면 모든 드롭다운 닫기
onTap: () {
// 현재 포커스된 위젯 포커스 해제
FocusScope.of(context).unfocus();
// 모든 드롭다운 닫기
@@ -1155,24 +1230,28 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
_removeSubCategoryDropdown();
_removeSubSubCategoryDropdown();
},
child: Scaffold(
appBar: AppBar(
title: Text(_controller.isEditMode ? '장비 입고 수정' : '장비 입고 등록'),
),
body: Form(
child: FormLayoutTemplate(
title: _controller.isEditMode ? '장비 입고 수정' : '장비 입고 등록',
onSave: _controller.isLoading ? null : _saveEquipmentIn,
onCancel: () => Navigator.of(context).pop(),
saveButtonText: _controller.isEditMode ? '수정 완료' : '입고 등록',
isLoading: _controller.isSaving,
child: Form(
key: _controller.formKey,
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(UIConstants.formPadding),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 기본 정보 섹션
Text('기본 정보', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 12),
FormSection(
title: '기본 정보',
subtitle: '입고할 장비의 기본 정보를 입력하세요',
children: [
// 장비 유형 선택 (라디오 버튼)
FormFieldWrapper(
label: '장비 유형',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1244,7 +1323,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '구매처',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1288,7 +1367,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
'[구매처:onFieldSubmitted] 자동완성 적용: "$suggestion"',
);
_isProgrammaticPartnerChange = true;
_partnerController.text = suggestion!;
_partnerController.text = suggestion;
_controller.partnerCompany = suggestion;
// 커서를 맨 뒤로 이동
_partnerController
@@ -1315,7 +1394,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
top: 2,
),
child: Text(
suggestion!,
suggestion,
style: const TextStyle(
color: Color(0xFF1976D2),
fontWeight: FontWeight.bold,
@@ -1331,7 +1410,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '입고지',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1383,7 +1462,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
);
_isProgrammaticWarehouseChange = true;
_warehouseController.text =
warehouseSuggestion!;
warehouseSuggestion;
_controller.warehouseLocation =
warehouseSuggestion;
// 커서를 맨 뒤로 이동
@@ -1441,7 +1520,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '제조사',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1494,7 +1573,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
);
_isProgrammaticManufacturerChange = true;
_manufacturerController.text =
manufacturerSuggestion!;
manufacturerSuggestion;
_controller.manufacturer =
manufacturerSuggestion;
// 커서를 맨 뒤로 이동
@@ -1548,7 +1627,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '장비명',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1601,7 +1680,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
);
_isProgrammaticEquipmentNameChange = true;
_equipmentNameController.text =
equipmentNameSuggestion!;
equipmentNameSuggestion;
_controller.name =
equipmentNameSuggestion;
// 커서를 맨 뒤로 이동
@@ -1659,7 +1738,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '대분류',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1709,7 +1788,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
);
_isProgrammaticCategoryChange = true;
_categoryController.text =
categorySuggestion!;
categorySuggestion;
_controller.category = categorySuggestion;
// 커서를 맨 뒤로 이동
_categoryController
@@ -1761,7 +1840,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '중분류',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1814,7 +1893,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
);
_isProgrammaticSubCategoryChange = true;
_subCategoryController.text =
subCategorySuggestion!;
subCategorySuggestion;
_controller.subCategory =
subCategorySuggestion;
// 커서를 맨 뒤로 이동
@@ -1868,7 +1947,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
Expanded(
child: FormFieldWrapper(
label: '소분류',
isRequired: true,
required: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1922,7 +2001,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
_isProgrammaticSubSubCategoryChange =
true;
_subSubCategoryController.text =
subSubCategorySuggestion!;
subSubCategorySuggestion;
_controller.subSubCategory =
subSubCategorySuggestion;
// 커서를 맨 뒤로 이동
@@ -1977,7 +2056,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
// 시리얼 번호 유무 토글
FormFieldWrapper(
label: '시리얼 번호',
isRequired: false,
required: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -2017,7 +2096,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
// 바코드 필드
FormFieldWrapper(
label: '바코드',
isRequired: false,
required: false,
child: TextFormField(
initialValue: _controller.barcode,
decoration: const InputDecoration(
@@ -2031,7 +2110,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
// 수량 필드
FormFieldWrapper(
label: '수량',
isRequired: true,
required: true,
child: TextFormField(
initialValue: _controller.quantity.toString(),
decoration: const InputDecoration(hintText: '수량을 입력하세요'),
@@ -2055,7 +2134,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
// 입고일 필드
FormFieldWrapper(
label: '입고일',
isRequired: true,
required: true,
child: InkWell(
onTap: () async {
final DateTime? picked = await showDatePicker(
@@ -2111,7 +2190,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
flex: 2,
child: FormFieldWrapper(
label: '워런티 라이센스',
isRequired: false,
required: false,
child: TextFormField(
initialValue: _controller.warrantyLicense ?? '',
decoration: const InputDecoration(
@@ -2130,7 +2209,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
flex: 2,
child: FormFieldWrapper(
label: '워런티 코드',
isRequired: false,
required: false,
child: TextFormField(
initialValue: _controller.warrantyCode ?? '',
decoration: const InputDecoration(
@@ -2149,7 +2228,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
flex: 1,
child: FormFieldWrapper(
label: '시작일',
isRequired: false,
required: false,
child: InkWell(
onTap: () async {
final DateTime? picked = await showDatePicker(
@@ -2199,7 +2278,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
flex: 1,
child: FormFieldWrapper(
label: '종료일',
isRequired: false,
required: false,
child: InkWell(
onTap: () async {
final DateTime? picked = await showDatePicker(
@@ -2249,7 +2328,7 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
flex: 1,
child: FormFieldWrapper(
label: '워런티 기간',
isRequired: false,
required: false,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
@@ -2281,35 +2360,23 @@ class _EquipmentInFormScreenState extends State<EquipmentInFormScreen> {
const SizedBox(height: 16),
FormFieldWrapper(
label: '비고',
isRequired: false,
required: false,
child: RemarkInput(
controller: _controller.remarkController,
hint: '비고를 입력하세요',
minLines: 4,
),
),
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _saveEquipmentIn,
style: AppThemeTailwind.primaryButtonStyle,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
_controller.isEditMode ? '수정하기' : '등록하기',
style: const TextStyle(fontSize: 16),
),
),
),
),
],
),
),
),
),
),
),
);
], // FormSection children 끝
), // FormSection 끝
], // Column children 끝
), // SingleChildScrollView child 끝
), // Form child 끝
), // FormLayoutTemplate child 끝
), // GestureDetector 끝
);
}, // Consumer builder 끝
), // Consumer 끝
); // ChangeNotifierProvider.value 끝
}
}