Files
superport/lib/screens/warehouse_location/warehouse_location_form.dart
JiWoong Sul a220449671
Some checks failed
Flutter Test & Quality Check / Test on macos-latest (push) Has been cancelled
Flutter Test & Quality Check / Test on ubuntu-latest (push) Has been cancelled
Flutter Test & Quality Check / Build APK (push) Has been cancelled
chore: 프로젝트 정리 및 문서 업데이트
- 창고 위치 폼 UI 개선
- 테스트 리포트 업데이트
- API 이슈 문서 추가
- 폼 레이아웃 템플릿 추가
- main.dart 정리
- 상수 업데이트

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-09 02:17:47 +09:00

139 lines
4.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:superport/models/address_model.dart';
import 'package:superport/screens/common/widgets/address_input.dart';
import 'package:superport/screens/common/widgets/remark_input.dart';
import 'package:superport/screens/common/theme_tailwind.dart';
import 'package:superport/screens/common/templates/form_layout_template.dart';
import 'controllers/warehouse_location_form_controller.dart';
/// 입고지 추가/수정 폼 화면 (SRP 적용, 상태/로직 분리)
class WarehouseLocationFormScreen extends StatefulWidget {
final int? id; // 수정 모드 지원을 위한 id 파라미터
const WarehouseLocationFormScreen({Key? key, this.id}) : super(key: key);
@override
State<WarehouseLocationFormScreen> createState() =>
_WarehouseLocationFormScreenState();
}
class _WarehouseLocationFormScreenState
extends State<WarehouseLocationFormScreen> {
/// 폼 컨트롤러 (상태 및 저장/수정 로직 위임)
late final WarehouseLocationFormController _controller;
@override
void initState() {
super.initState();
// 컨트롤러 생성 및 초기화
_controller = WarehouseLocationFormController();
if (widget.id != null) {
_controller.initialize(widget.id!);
}
}
@override
void dispose() {
// 컨트롤러 해제
_controller.dispose();
super.dispose();
}
// 저장 메소드
Future<void> _onSave() async {
setState(() {}); // 저장 중 상태 갱신
final success = await _controller.save();
setState(() {}); // 저장 완료 후 상태 갱신
if (success) {
// 성공 메시지 표시
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_controller.isEditMode ? '입고지가 수정되었습니다' : '입고지가 추가되었습니다'),
backgroundColor: AppThemeTailwind.success,
),
);
// 리스트 화면으로 돌아가기
Navigator.of(context).pop(true);
}
} else {
// 실패 메시지 표시
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_controller.error ?? '저장에 실패했습니다'),
backgroundColor: AppThemeTailwind.danger,
),
);
}
}
}
@override
Widget build(BuildContext context) {
return FormLayoutTemplate(
title: _controller.isEditMode ? '입고지 수정' : '입고지 추가',
onSave: _controller.isSaving ? null : _onSave,
saveButtonText: '저장',
isLoading: _controller.isSaving,
child: Form(
key: _controller.formKey,
child: SingleChildScrollView(
padding: const EdgeInsets.all(UIConstants.formPadding),
child: FormSection(
title: '입고지 정보',
subtitle: '입고지의 기본 정보를 입력하세요',
children: [
// 입고지명 입력
FormFieldWrapper(
label: '입고지명',
required: true,
child: TextFormField(
controller: _controller.nameController,
decoration: const InputDecoration(
hintText: '입고지명을 입력하세요',
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return '입고지명을 입력하세요';
}
return null;
},
),
),
// 주소 입력 (공통 위젯)
FormFieldWrapper(
label: '주소',
required: true,
child: AddressInput(
initialZipCode: _controller.address.zipCode,
initialRegion: _controller.address.region,
initialDetailAddress: _controller.address.detailAddress,
isRequired: true,
onAddressChanged: (zip, region, detail) {
setState(() {
_controller.updateAddress(
Address(
zipCode: zip,
region: region,
detailAddress: detail,
),
);
});
},
),
),
// 비고 입력
FormFieldWrapper(
label: '비고',
child: RemarkInput(controller: _controller.remarkController),
),
],
),
),
),
);
}
}