프로젝트 최초 커밋
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/warehouse_location_model.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
|
||||
/// 입고지 폼 상태 및 저장/수정 로직을 담당하는 컨트롤러
|
||||
class WarehouseLocationFormController {
|
||||
/// 폼 키
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
/// 입고지명 입력 컨트롤러
|
||||
final TextEditingController nameController = TextEditingController();
|
||||
|
||||
/// 비고 입력 컨트롤러
|
||||
final TextEditingController remarkController = TextEditingController();
|
||||
|
||||
/// 주소 정보
|
||||
Address address = const Address();
|
||||
|
||||
/// 저장 중 여부
|
||||
bool isSaving = false;
|
||||
|
||||
/// 수정 모드 여부
|
||||
bool isEditMode = false;
|
||||
|
||||
/// 입고지 id (수정 모드)
|
||||
int? id;
|
||||
|
||||
/// 기존 데이터 세팅 (수정 모드)
|
||||
void initialize(int? locationId) {
|
||||
id = locationId;
|
||||
if (id != null) {
|
||||
final location = MockDataService().getWarehouseLocationById(id!);
|
||||
if (location != null) {
|
||||
isEditMode = true;
|
||||
nameController.text = location.name;
|
||||
address = location.address;
|
||||
remarkController.text = location.remark ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 주소 변경 처리
|
||||
void updateAddress(Address newAddress) {
|
||||
address = newAddress;
|
||||
}
|
||||
|
||||
/// 저장 처리 (추가/수정)
|
||||
Future<bool> save(BuildContext context) async {
|
||||
if (!formKey.currentState!.validate()) return false;
|
||||
isSaving = true;
|
||||
if (isEditMode) {
|
||||
// 수정
|
||||
MockDataService().updateWarehouseLocation(
|
||||
WarehouseLocation(
|
||||
id: id!,
|
||||
name: nameController.text.trim(),
|
||||
address: address,
|
||||
remark: remarkController.text.trim(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// 추가
|
||||
MockDataService().addWarehouseLocation(
|
||||
WarehouseLocation(
|
||||
id: 0,
|
||||
name: nameController.text.trim(),
|
||||
address: address,
|
||||
remark: remarkController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
isSaving = false;
|
||||
Navigator.pop(context, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// 취소 처리
|
||||
void cancel(BuildContext context) {
|
||||
Navigator.pop(context, false);
|
||||
}
|
||||
|
||||
/// 컨트롤러 해제
|
||||
void dispose() {
|
||||
nameController.dispose();
|
||||
remarkController.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:superport/models/warehouse_location_model.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
|
||||
/// 입고지 리스트 상태 및 CRUD만 담당하는 컨트롤러 클래스 (SRP 적용)
|
||||
/// UI, 네비게이션, 다이얼로그 등은 포함하지 않음
|
||||
/// 향후 서비스/리포지토리 DI 구조로 확장 가능
|
||||
class WarehouseLocationListController {
|
||||
/// 입고지 데이터 서비스 (mock)
|
||||
final MockDataService _dataService = MockDataService();
|
||||
|
||||
/// 전체 입고지 목록
|
||||
List<WarehouseLocation> warehouseLocations = [];
|
||||
|
||||
/// 데이터 로드
|
||||
void loadWarehouseLocations() {
|
||||
warehouseLocations = _dataService.getAllWarehouseLocations();
|
||||
}
|
||||
|
||||
/// 입고지 추가
|
||||
void addWarehouseLocation(WarehouseLocation location) {
|
||||
_dataService.addWarehouseLocation(location);
|
||||
loadWarehouseLocations();
|
||||
}
|
||||
|
||||
/// 입고지 수정
|
||||
void updateWarehouseLocation(WarehouseLocation location) {
|
||||
_dataService.updateWarehouseLocation(location);
|
||||
loadWarehouseLocations();
|
||||
}
|
||||
|
||||
/// 입고지 삭제
|
||||
void deleteWarehouseLocation(int id) {
|
||||
_dataService.deleteWarehouseLocation(id);
|
||||
loadWarehouseLocations();
|
||||
}
|
||||
}
|
||||
139
lib/screens/warehouse_location/warehouse_location_form.dart
Normal file
139
lib/screens/warehouse_location/warehouse_location_form.dart
Normal file
@@ -0,0 +1,139 @@
|
||||
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/utils/constants.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();
|
||||
_controller.initialize(widget.id);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 컨트롤러 해제
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_controller.isEditMode ? '입고지 수정' : '입고지 추가'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.of(context).maybePop(),
|
||||
),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Form(
|
||||
key: _controller.formKey,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 입고지명 입력
|
||||
TextFormField(
|
||||
controller: _controller.nameController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '입고지명',
|
||||
hintText: '입고지명을 입력하세요',
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return '입고지명을 입력하세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// 주소 입력 (공통 위젯)
|
||||
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,
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// 비고 입력
|
||||
RemarkInput(controller: _controller.remarkController),
|
||||
const SizedBox(height: 80), // 하단 버튼 여백 확보
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed:
|
||||
_controller.isSaving
|
||||
? null
|
||||
: () async {
|
||||
setState(() {}); // 저장 중 상태 갱신
|
||||
await _controller.save(context);
|
||||
setState(() {}); // 저장 완료 후 상태 갱신
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppThemeTailwind.primary,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child:
|
||||
_controller.isSaving
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text(
|
||||
'저장',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/warehouse_location_model.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
|
||||
/// 입고지 폼 상태 및 저장/수정 로직을 담당하는 컨트롤러
|
||||
class WarehouseLocationFormController {
|
||||
/// 폼 키
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
/// 입고지명 입력 컨트롤러
|
||||
final TextEditingController nameController = TextEditingController();
|
||||
|
||||
/// 비고 입력 컨트롤러
|
||||
final TextEditingController remarkController = TextEditingController();
|
||||
|
||||
/// 주소 정보
|
||||
Address address = const Address();
|
||||
|
||||
/// 저장 중 여부
|
||||
bool isSaving = false;
|
||||
|
||||
/// 수정 모드 여부
|
||||
bool isEditMode = false;
|
||||
|
||||
/// 입고지 id (수정 모드)
|
||||
int? id;
|
||||
|
||||
/// 기존 데이터 세팅 (수정 모드)
|
||||
void initialize(int? locationId) {
|
||||
id = locationId;
|
||||
if (id != null) {
|
||||
final location = MockDataService().getWarehouseLocationById(id!);
|
||||
if (location != null) {
|
||||
isEditMode = true;
|
||||
nameController.text = location.name;
|
||||
address = location.address;
|
||||
remarkController.text = location.remark ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 주소 변경 처리
|
||||
void updateAddress(Address newAddress) {
|
||||
address = newAddress;
|
||||
}
|
||||
|
||||
/// 저장 처리 (추가/수정)
|
||||
Future<bool> save(BuildContext context) async {
|
||||
if (!formKey.currentState!.validate()) return false;
|
||||
isSaving = true;
|
||||
if (isEditMode) {
|
||||
// 수정
|
||||
MockDataService().updateWarehouseLocation(
|
||||
WarehouseLocation(
|
||||
id: id!,
|
||||
name: nameController.text.trim(),
|
||||
address: address,
|
||||
remark: remarkController.text.trim(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// 추가
|
||||
MockDataService().addWarehouseLocation(
|
||||
WarehouseLocation(
|
||||
id: 0,
|
||||
name: nameController.text.trim(),
|
||||
address: address,
|
||||
remark: remarkController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
isSaving = false;
|
||||
Navigator.pop(context, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// 취소 처리
|
||||
void cancel(BuildContext context) {
|
||||
Navigator.pop(context, false);
|
||||
}
|
||||
|
||||
/// 컨트롤러 해제
|
||||
void dispose() {
|
||||
nameController.dispose();
|
||||
remarkController.dispose();
|
||||
}
|
||||
}
|
||||
218
lib/screens/warehouse_location/warehouse_location_list.dart
Normal file
218
lib/screens/warehouse_location/warehouse_location_list.dart
Normal file
@@ -0,0 +1,218 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/warehouse_location_model.dart';
|
||||
import 'controllers/warehouse_location_list_controller.dart';
|
||||
import 'package:superport/screens/common/widgets/address_input.dart';
|
||||
import 'package:superport/utils/constants.dart';
|
||||
import 'package:superport/screens/common/main_layout.dart';
|
||||
import 'package:superport/screens/common/widgets/pagination.dart';
|
||||
import 'package:superport/screens/common/custom_widgets.dart';
|
||||
import 'package:superport/screens/common/theme_tailwind.dart';
|
||||
|
||||
/// 입고지 관리 리스트 화면 (SRP 적용, UI만 담당)
|
||||
class WarehouseLocationListScreen extends StatefulWidget {
|
||||
const WarehouseLocationListScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<WarehouseLocationListScreen> createState() =>
|
||||
_WarehouseLocationListScreenState();
|
||||
}
|
||||
|
||||
class _WarehouseLocationListScreenState
|
||||
extends State<WarehouseLocationListScreen> {
|
||||
/// 리스트 컨트롤러 (상태 및 CRUD 위임)
|
||||
final WarehouseLocationListController _controller =
|
||||
WarehouseLocationListController();
|
||||
int _currentPage = 1;
|
||||
final int _pageSize = 10;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.loadWarehouseLocations();
|
||||
}
|
||||
|
||||
/// 리스트 새로고침
|
||||
void _reload() {
|
||||
setState(() {
|
||||
_controller.loadWarehouseLocations();
|
||||
});
|
||||
}
|
||||
|
||||
/// 입고지 추가 폼으로 이동
|
||||
void _navigateToAdd() async {
|
||||
final result = await Navigator.pushNamed(
|
||||
context,
|
||||
Routes.warehouseLocationAdd,
|
||||
);
|
||||
if (result == true) {
|
||||
_reload();
|
||||
}
|
||||
}
|
||||
|
||||
/// 입고지 수정 폼으로 이동
|
||||
void _navigateToEdit(WarehouseLocation location) async {
|
||||
final result = await Navigator.pushNamed(
|
||||
context,
|
||||
Routes.warehouseLocationEdit,
|
||||
arguments: location.id,
|
||||
);
|
||||
if (result == true) {
|
||||
_reload();
|
||||
}
|
||||
}
|
||||
|
||||
/// 삭제 다이얼로그 (별도 위젯으로 분리 가능)
|
||||
void _showDeleteDialog(int id) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => AlertDialog(
|
||||
title: const Text('입고지 삭제'),
|
||||
content: const Text('정말로 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_controller.deleteWarehouseLocation(id);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 대시보드 폭에 맞게 조정
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final maxContentWidth = screenWidth > 1200 ? 1200.0 : screenWidth - 32;
|
||||
|
||||
final int totalCount = _controller.warehouseLocations.length;
|
||||
final int startIndex = (_currentPage - 1) * _pageSize;
|
||||
final int endIndex =
|
||||
(startIndex + _pageSize) > totalCount
|
||||
? totalCount
|
||||
: (startIndex + _pageSize);
|
||||
final List<WarehouseLocation> pagedLocations = _controller
|
||||
.warehouseLocations
|
||||
.sublist(startIndex, endIndex);
|
||||
|
||||
return MainLayout(
|
||||
title: '입고지 관리',
|
||||
currentRoute: Routes.warehouseLocation,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: _reload,
|
||||
color: Colors.grey,
|
||||
),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PageTitle(
|
||||
title: '입고지 목록',
|
||||
width: maxContentWidth - 32,
|
||||
rightWidget: ElevatedButton.icon(
|
||||
onPressed: _navigateToAdd,
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('입고지 추가'),
|
||||
style: AppThemeTailwind.primaryButtonStyle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: DataTableCard(
|
||||
width: maxContentWidth - 32,
|
||||
child:
|
||||
pagedLocations.isEmpty
|
||||
? const Center(child: Text('등록된 입고지가 없습니다.'))
|
||||
: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Container(
|
||||
width: maxContentWidth - 32,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: maxContentWidth - 64,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: DataTable(
|
||||
columns: const [
|
||||
DataColumn(label: Text('번호')),
|
||||
DataColumn(label: Text('입고지명')),
|
||||
DataColumn(label: Text('주소')),
|
||||
DataColumn(label: Text('관리')),
|
||||
],
|
||||
rows: List.generate(pagedLocations.length, (i) {
|
||||
final location = pagedLocations[i];
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text('${startIndex + i + 1}')),
|
||||
DataCell(Text(location.name)),
|
||||
DataCell(
|
||||
AddressInput.readonly(
|
||||
address: location.address,
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.edit,
|
||||
color: AppThemeTailwind.primary,
|
||||
),
|
||||
tooltip: '수정',
|
||||
onPressed:
|
||||
() =>
|
||||
_navigateToEdit(location),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.delete,
|
||||
color: AppThemeTailwind.danger,
|
||||
),
|
||||
tooltip: '삭제',
|
||||
onPressed:
|
||||
() => _showDeleteDialog(
|
||||
location.id,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Pagination(
|
||||
currentPage: _currentPage,
|
||||
totalCount: totalCount,
|
||||
pageSize: _pageSize,
|
||||
onPageChanged: (page) {
|
||||
setState(() {
|
||||
_currentPage = page;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user