사용하지 않는 파일 정리 전 백업 (Phase 10 완료 후 상태)
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
import 'package:superport/screens/common/templates/form_layout_template.dart';
|
||||
import 'package:superport/screens/company/controllers/company_form_controller.dart';
|
||||
import 'package:superport/utils/validators.dart';
|
||||
import 'package:superport/utils/phone_utils.dart';
|
||||
import 'package:superport/utils/formatters/korean_phone_formatter.dart';
|
||||
|
||||
/// 회사 등록/수정 화면
|
||||
/// User/Warehouse Location 화면과 동일한 FormFieldWrapper 패턴 사용
|
||||
class CompanyFormScreen extends StatefulWidget {
|
||||
final Map? args;
|
||||
const CompanyFormScreen({Key? key, this.args}) : super(key: key);
|
||||
const CompanyFormScreen({super.key, this.args});
|
||||
|
||||
@override
|
||||
State<CompanyFormScreen> createState() => _CompanyFormScreenState();
|
||||
@@ -25,10 +23,6 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
final TextEditingController _phoneNumberController = TextEditingController();
|
||||
int? companyId;
|
||||
bool isBranch = false;
|
||||
|
||||
// 전화번호 관련 변수
|
||||
String _selectedPhonePrefix = '010';
|
||||
List<String> _phonePrefixes = PhoneUtils.getCommonPhonePrefixes();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -57,8 +51,7 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 전화번호 분리 초기화
|
||||
final fullPhone = _controller.contactPhoneController.text;
|
||||
if (fullPhone.isNotEmpty) {
|
||||
_selectedPhonePrefix = PhoneUtils.extractPhonePrefix(fullPhone, _phonePrefixes);
|
||||
_phoneNumberController.text = PhoneUtils.extractPhoneNumberWithoutPrefix(fullPhone, _phonePrefixes);
|
||||
_phoneNumberController.text = fullPhone; // 통합 필드로 그대로 사용
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
@@ -87,15 +80,26 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
Address.fromFullAddress(_addressController.text)
|
||||
);
|
||||
|
||||
// 전화번호 합치기
|
||||
final fullPhoneNumber = PhoneUtils.getFullPhoneNumber(_selectedPhonePrefix, _phoneNumberController.text);
|
||||
_controller.contactPhoneController.text = fullPhoneNumber;
|
||||
// 전화번호는 이미 포맷팅되어 있으므로 그대로 사용
|
||||
_controller.contactPhoneController.text = _phoneNumberController.text;
|
||||
|
||||
// 로딩 표시
|
||||
showDialog(
|
||||
showShadDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(child: CircularProgressIndicator()),
|
||||
builder: (context) => ShadDialog(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 20),
|
||||
Text('저장 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -105,18 +109,18 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
Navigator.pop(context); // 로딩 다이얼로그 닫기
|
||||
|
||||
if (success) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(companyId != null ? '회사 정보가 수정되었습니다.' : '회사가 등록되었습니다.'),
|
||||
backgroundColor: Colors.green,
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast(
|
||||
title: const Text('성공'),
|
||||
description: Text(companyId != null ? '회사 정보가 수정되었습니다.' : '회사가 등록되었습니다.'),
|
||||
),
|
||||
);
|
||||
Navigator.pop(context, true);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('회사 저장에 실패했습니다.'),
|
||||
backgroundColor: Colors.red,
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: const Text('회사 저장에 실패했습니다.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -124,10 +128,10 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Navigator.pop(context); // 로딩 다이얼로그 닫기
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('오류가 발생했습니다: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: Text('오류가 발생했습니다: $e'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -156,43 +160,86 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CheckboxListTile(
|
||||
title: const Text('고객사'),
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.customer),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.customer, checked ?? false);
|
||||
});
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.customer),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.customer, checked);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('고객사'),
|
||||
],
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('파트너사'),
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.partner),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.partner, checked ?? false);
|
||||
});
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.partner),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.partner, checked);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('파트너사'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 부모 회사 선택 (선택사항)
|
||||
FormFieldWrapper(
|
||||
label: "부모 회사",
|
||||
child: ShadSelect<int?>(
|
||||
placeholder: const Text('부모 회사를 선택하세요 (선택사항)'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('없음 (본사)');
|
||||
}
|
||||
final company = _controller.availableParentCompanies.firstWhere(
|
||||
(c) => c.id == value,
|
||||
orElse: () => Company(id: 0, name: '알 수 없음'),
|
||||
);
|
||||
return Text(company.name);
|
||||
},
|
||||
options: [
|
||||
const ShadOption(
|
||||
value: null,
|
||||
child: Text('없음 (본사)'),
|
||||
),
|
||||
..._controller.availableParentCompanies.map((company) {
|
||||
return ShadOption(
|
||||
value: company.id,
|
||||
child: Text(company.name),
|
||||
);
|
||||
}),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_controller.selectedParentCompanyId = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 회사명 (필수)
|
||||
FormFieldWrapper(
|
||||
label: "회사명 *",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.nameController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '회사명을 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('회사명을 입력하세요'),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
if (value.trim().isEmpty) {
|
||||
return '회사명을 입력하세요';
|
||||
}
|
||||
if (value.trim().length < 2) {
|
||||
@@ -200,7 +247,6 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -209,14 +255,10 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 주소 (선택)
|
||||
FormFieldWrapper(
|
||||
label: "주소",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _addressController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '회사 주소를 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('회사 주소를 입력하세요'),
|
||||
maxLines: 2,
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -225,19 +267,15 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자명 (필수)
|
||||
FormFieldWrapper(
|
||||
label: "담당자명 *",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.contactNameController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '담당자명을 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('담당자명을 입력하세요'),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
if (value.trim().isEmpty) {
|
||||
return '담당자명을 입력하세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -246,13 +284,9 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자 직급 (선택)
|
||||
FormFieldWrapper(
|
||||
label: "담당자 직급",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.contactPositionController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '담당자 직급을 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
textInputAction: TextInputAction.next,
|
||||
placeholder: const Text('담당자 직급을 입력하세요'),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -261,72 +295,14 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자 연락처 (필수) - 사용자 폼과 동일한 패턴
|
||||
FormFieldWrapper(
|
||||
label: "담당자 연락처 *",
|
||||
child: Row(
|
||||
children: [
|
||||
// 접두사 드롭다운 (010, 02, 031 등)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: DropdownButton<String>(
|
||||
value: _selectedPhonePrefix,
|
||||
items: _phonePrefixes.map((prefix) {
|
||||
return DropdownMenuItem(
|
||||
value: prefix,
|
||||
child: Text(prefix),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_selectedPhonePrefix = value;
|
||||
});
|
||||
}
|
||||
},
|
||||
underline: Container(), // 밑줄 제거
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('-', style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(width: 8),
|
||||
// 전화번호 입력 (7-8자리)
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _phoneNumberController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '1234-5678',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
TextInputFormatter.withFunction((oldValue, newValue) {
|
||||
final formatted = PhoneUtils.formatPhoneNumberByPrefix(
|
||||
_selectedPhonePrefix,
|
||||
newValue.text,
|
||||
);
|
||||
return TextEditingValue(
|
||||
text: formatted,
|
||||
selection: TextSelection.collapsed(offset: formatted.length),
|
||||
);
|
||||
}),
|
||||
],
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return '전화번호를 입력하세요';
|
||||
}
|
||||
final digitsOnly = value.replaceAll(RegExp(r'[^\d]'), '');
|
||||
if (digitsOnly.length < 7) {
|
||||
return '전화번호는 7-8자리 숫자를 입력해주세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
child: ShadInputFormField(
|
||||
controller: _phoneNumberController,
|
||||
placeholder: const Text('010-1234-5678'),
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
KoreanPhoneFormatter(), // 한국식 전화번호 자동 포맷팅
|
||||
],
|
||||
validator: PhoneValidator.validate, // 전화번호 유효성 검증
|
||||
),
|
||||
),
|
||||
|
||||
@@ -335,20 +311,16 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자 이메일 (필수)
|
||||
FormFieldWrapper(
|
||||
label: "담당자 이메일 *",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.contactEmailController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'example@company.com',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('example@company.com'),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
if (value.trim().isEmpty) {
|
||||
return '담당자 이메일을 입력하세요';
|
||||
}
|
||||
return validateEmail(value);
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -357,30 +329,20 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 비고 (선택)
|
||||
FormFieldWrapper(
|
||||
label: "비고",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.remarkController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '추가 정보나 메모를 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('추가 정보나 메모를 입력하세요'),
|
||||
maxLines: 3,
|
||||
textInputAction: TextInputAction.done,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 저장 버튼
|
||||
ElevatedButton(
|
||||
ShadButton(
|
||||
onPressed: _saveCompany,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ShadcnTheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
size: ShadButtonSize.lg,
|
||||
width: double.infinity,
|
||||
child: Text(
|
||||
isEditMode ? '수정 완료' : '등록 완료',
|
||||
style: const TextStyle(
|
||||
|
||||
Reference in New Issue
Block a user