157 lines
5.5 KiB
Dart
157 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:shadcn_ui/shadcn_ui.dart';
|
|
import 'package:superport/screens/common/widgets/remark_input.dart';
|
|
import 'package:superport/screens/common/templates/form_layout_template.dart';
|
|
import 'controllers/warehouse_location_form_controller.dart';
|
|
import 'package:superport/utils/formatters/korean_phone_formatter.dart';
|
|
|
|
/// 입고지 추가/수정 폼 화면 (SRP 적용, 상태/로직 분리)
|
|
class WarehouseLocationFormScreen extends StatefulWidget {
|
|
final int? id; // 수정 모드 지원을 위한 id 파라미터
|
|
const WarehouseLocationFormScreen({super.key, this.id});
|
|
|
|
@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) {
|
|
ShadToaster.of(context).show(
|
|
ShadToast(
|
|
title: const Text('성공'),
|
|
description: Text(_controller.isEditMode ? '입고지가 수정되었습니다' : '입고지가 추가되었습니다'),
|
|
),
|
|
);
|
|
// 리스트 화면으로 돌아가기
|
|
Navigator.of(context).pop(true);
|
|
}
|
|
} else {
|
|
// 실패 메시지 표시
|
|
if (mounted) {
|
|
ShadToaster.of(context).show(
|
|
ShadToast.destructive(
|
|
title: const Text('오류'),
|
|
description: Text(_controller.error ?? '저장에 실패했습니다'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
@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: ShadInputFormField(
|
|
controller: _controller.nameController,
|
|
placeholder: const Text('창고명을 입력하세요'),
|
|
validator: (value) {
|
|
if (value.trim().isEmpty) {
|
|
return '창고명을 입력하세요';
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
),
|
|
// 주소 입력 (단일 필드)
|
|
FormFieldWrapper(
|
|
label: '주소',
|
|
child: ShadInputFormField(
|
|
controller: _controller.addressController,
|
|
placeholder: const Text('주소를 입력하세요 (예: 경기도 용인시 기흥구 동백로 123)'),
|
|
maxLines: 3,
|
|
),
|
|
),
|
|
// 담당자명 입력
|
|
FormFieldWrapper(
|
|
label: '담당자명',
|
|
child: ShadInputFormField(
|
|
controller: _controller.managerNameController,
|
|
placeholder: const Text('담당자명을 입력하세요'),
|
|
),
|
|
),
|
|
// 담당자 연락처 입력
|
|
FormFieldWrapper(
|
|
label: '담당자 연락처',
|
|
child: ShadInputFormField(
|
|
controller: _controller.managerPhoneController,
|
|
placeholder: const Text('010-1234-5678'),
|
|
keyboardType: TextInputType.phone,
|
|
inputFormatters: [
|
|
KoreanPhoneFormatter(), // 한국식 전화번호 자동 포맷팅
|
|
],
|
|
validator: (value) => PhoneValidator.validate(value),
|
|
),
|
|
),
|
|
// 수용량 입력
|
|
FormFieldWrapper(
|
|
label: '수용량',
|
|
child: ShadInputFormField(
|
|
controller: _controller.capacityController,
|
|
placeholder: const Text('수용량을 입력하세요 (개)'),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
],
|
|
validator: _controller.validateCapacity,
|
|
),
|
|
),
|
|
// 비고 입력
|
|
FormFieldWrapper(
|
|
label: '비고',
|
|
child: RemarkInput(controller: _controller.remarkController),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|