프로젝트 최초 커밋

This commit is contained in:
JiWoong Sul
2025-07-02 17:45:44 +09:00
commit e346f83c97
235 changed files with 23139 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:superport/models/license_model.dart';
import 'package:superport/services/mock_data_service.dart';
// 라이센스 폼의 상태 및 비즈니스 로직을 담당하는 컨트롤러
class LicenseFormController {
final MockDataService dataService;
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
bool isEditMode = false;
int? licenseId;
String name = '';
int durationMonths = 12; // 기본값: 12개월
String visitCycle = '미방문'; // 기본값: 미방문
LicenseFormController({required this.dataService, this.licenseId});
// 라이센스 정보 로드 (수정 모드)
void loadLicense() {
if (licenseId == null) return;
final license = dataService.getLicenseById(licenseId!);
if (license != null) {
name = license.name;
durationMonths = license.durationMonths;
visitCycle = license.visitCycle;
}
}
// 라이센스 저장 (UI에서 호출)
void saveLicense(Function() onSuccess) {
if (formKey.currentState?.validate() != true) return;
formKey.currentState?.save();
if (isEditMode && licenseId != null) {
final license = dataService.getLicenseById(licenseId!);
if (license != null) {
final updatedLicense = License(
id: license.id,
companyId: license.companyId,
name: name,
durationMonths: durationMonths,
visitCycle: visitCycle,
);
dataService.updateLicense(updatedLicense);
}
} else {
// 라이센스 추가 시 임시 회사 ID 사용 또는 나중에 설정하도록 변경
final newLicense = License(
companyId: 1, // 기본값 또는 필요에 따라 수정
name: name,
durationMonths: durationMonths,
visitCycle: visitCycle,
);
dataService.addLicense(newLicense);
}
onSuccess();
}
}

View File

@@ -0,0 +1,21 @@
import 'package:superport/models/license_model.dart';
import 'package:superport/services/mock_data_service.dart';
// 라이센스 목록 화면의 상태 및 비즈니스 로직을 담당하는 컨트롤러
class LicenseListController {
final MockDataService dataService;
List<License> licenses = [];
LicenseListController({required this.dataService});
// 데이터 로드
void loadData() {
licenses = dataService.getAllLicenses();
}
// 라이센스 삭제
void deleteLicense(int id) {
dataService.deleteLicense(id);
loadData();
}
}

View File

@@ -0,0 +1,262 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:superport/models/license_model.dart';
import 'package:superport/screens/license/controllers/license_form_controller.dart';
import 'package:superport/screens/common/theme_tailwind.dart';
import 'package:superport/screens/common/custom_widgets.dart';
import 'package:superport/services/mock_data_service.dart';
import 'package:superport/utils/validators.dart';
// 유지보수 등록/수정 화면 (UI만 담당, 상태/로직 분리)
class MaintenanceFormScreen extends StatefulWidget {
final int? maintenanceId;
const MaintenanceFormScreen({Key? key, this.maintenanceId}) : super(key: key);
@override
_MaintenanceFormScreenState createState() => _MaintenanceFormScreenState();
}
class _MaintenanceFormScreenState extends State<MaintenanceFormScreen> {
late final LicenseFormController _controller;
// 방문주기 드롭다운 옵션
final List<String> _visitCycleOptions = [
'미방문',
'장애시 지원',
'',
'격월',
'분기',
'반기',
'',
];
// 점검형태 라디오 옵션
final List<String> _inspectionTypeOptions = ['방문', '원격'];
String _selectedVisitCycle = '미방문';
String _selectedInspectionType = '방문';
int _durationMonths = 12;
@override
void initState() {
super.initState();
_controller = LicenseFormController(
dataService: MockDataService(),
licenseId: widget.maintenanceId,
);
_controller.isEditMode = widget.maintenanceId != null;
if (_controller.isEditMode) {
_controller.loadLicense();
// TODO: 기존 데이터 로딩 시 _selectedVisitCycle, _selectedInspectionType, _durationMonths 값 세팅 필요
}
}
@override
Widget build(BuildContext context) {
// 유지보수 명은 유지보수기간, 방문주기, 점검형태를 결합해서 표기
final String maintenanceName =
'${_durationMonths}개월,${_selectedVisitCycle},${_selectedInspectionType}';
return Scaffold(
appBar: AppBar(
title: Text(_controller.isEditMode ? '유지보수 수정' : '유지보수 등록'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _controller.formKey,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 유지보수 명 표기 (입력 불가, 자동 생성)
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'유지보수 명',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 8,
),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade400),
borderRadius: BorderRadius.circular(4),
color: Colors.grey.shade100,
),
child: Text(
maintenanceName,
style: const TextStyle(fontSize: 16),
),
),
],
),
),
// 유지보수 기간 (개월)
_buildTextField(
label: '유지보수 기간 (개월)',
initialValue: _durationMonths.toString(),
hintText: '유지보수 기간을 입력하세요',
suffixText: '개월',
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
validator: (value) => validateNumber(value, '유지보수 기간'),
onChanged: (value) {
setState(() {
_durationMonths = int.tryParse(value ?? '') ?? 0;
});
},
),
// 방문 주기 (드롭다운)
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'방문 주기',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
DropdownButtonFormField<String>(
value: _selectedVisitCycle,
items:
_visitCycleOptions
.map(
(option) => DropdownMenuItem(
value: option,
child: Text(option),
),
)
.toList(),
onChanged: (value) {
setState(() {
_selectedVisitCycle = value!;
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(
horizontal: 8,
vertical: 0,
),
),
validator:
(value) =>
value == null || value.isEmpty
? '방문 주기를 선택하세요'
: null,
),
],
),
),
// 점검 형태 (라디오버튼)
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'점검 형태',
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Row(
children:
_inspectionTypeOptions.map((type) {
return Row(
children: [
Radio<String>(
value: type,
groupValue: _selectedInspectionType,
onChanged: (value) {
setState(() {
_selectedInspectionType = value!;
});
},
),
Text(type),
],
);
}).toList(),
),
],
),
),
const SizedBox(height: 24),
// 저장 버튼
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
if (_controller.formKey.currentState!.validate()) {
_controller.formKey.currentState!.save();
// 유지보수 명 결합하여 저장
final String saveName =
'${_durationMonths}개월,${_selectedVisitCycle},${_selectedInspectionType}';
_controller.name = saveName;
_controller.durationMonths = _durationMonths;
_controller.visitCycle = _selectedVisitCycle;
// 점검형태 저장 로직 필요 시 추가
setState(() {
_controller.saveLicense(() {
Navigator.pop(context, true);
});
});
}
},
style: AppThemeTailwind.primaryButtonStyle,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
_controller.isEditMode ? '수정하기' : '등록하기',
style: const TextStyle(fontSize: 16),
),
),
),
),
],
),
),
),
),
);
}
// 공통 텍스트 필드 위젯 (onSaved → onChanged로 변경)
Widget _buildTextField({
required String label,
required String initialValue,
required String hintText,
String? suffixText,
TextInputType? keyboardType,
List<TextInputFormatter>? inputFormatters,
required String? Function(String?) validator,
required void Function(String?) onChanged,
}) {
return Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
const SizedBox(height: 4),
TextFormField(
initialValue: initialValue,
decoration: InputDecoration(
hintText: hintText,
suffixText: suffixText,
),
keyboardType: keyboardType,
inputFormatters: inputFormatters,
validator: validator,
onChanged: onChanged,
),
],
),
);
}
}

View File

@@ -0,0 +1,174 @@
import 'package:flutter/material.dart';
import 'package:superport/models/license_model.dart';
import 'package:superport/screens/common/theme_tailwind.dart';
import 'package:superport/screens/common/main_layout.dart';
import 'package:superport/screens/common/custom_widgets.dart';
import 'package:superport/services/mock_data_service.dart';
import 'package:superport/utils/constants.dart';
import 'package:superport/screens/license/controllers/license_list_controller.dart';
import 'package:superport/screens/license/widgets/license_table.dart';
import 'package:superport/screens/common/widgets/pagination.dart';
// 유지보수 목록 화면 (UI만 담당, 상태/로직/테이블 분리)
class MaintenanceListScreen extends StatefulWidget {
const MaintenanceListScreen({super.key});
@override
State<MaintenanceListScreen> createState() => _MaintenanceListScreenState();
}
// 유지보수 목록 화면의 상태 클래스
class _MaintenanceListScreenState extends State<MaintenanceListScreen> {
late final LicenseListController _controller;
// 페이지네이션 상태 추가
int _currentPage = 1;
final int _pageSize = 10;
@override
void initState() {
super.initState();
_controller = LicenseListController(dataService: MockDataService());
_controller.loadData();
}
void _reload() {
setState(() {
_controller.loadData();
});
}
void _navigateToAddScreen() async {
final result = await Navigator.pushNamed(context, '/license/add');
if (result == true) {
_reload();
}
}
void _navigateToEditScreen(int id) async {
final result = await Navigator.pushNamed(
context,
'/license/edit',
arguments: id,
);
if (result == true) {
_reload();
}
}
void _deleteLicense(int id) {
showDialog(
context: context,
builder:
(context) => AlertDialog(
title: const Text('삭제 확인'),
content: const Text('이 라이센스 정보를 삭제하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('취소'),
),
TextButton(
onPressed: () {
setState(() {
_controller.deleteLicense(id);
});
Navigator.pop(context);
},
child: const Text('삭제'),
),
],
),
);
}
// 회사명 반환 함수 (재사용성 위해 분리)
String _getCompanyName(int companyId) {
return MockDataService().getCompanyById(companyId)?.name ?? '-';
}
@override
Widget build(BuildContext context) {
// 대시보드 폭에 맞게 조정
final screenWidth = MediaQuery.of(context).size.width;
final maxContentWidth = screenWidth > 1200 ? 1200.0 : screenWidth - 32;
// 페이지네이션 데이터 슬라이싱
final int totalCount = _controller.licenses.length;
final int startIndex = (_currentPage - 1) * _pageSize;
final int endIndex =
(startIndex + _pageSize) > totalCount
? totalCount
: (startIndex + _pageSize);
final pagedLicenses = _controller.licenses.sublist(startIndex, endIndex);
return MainLayout(
title: '유지보수 관리',
currentRoute: Routes.license,
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: _navigateToAddScreen,
icon: const Icon(Icons.add),
label: const Text('추가'),
style: AppThemeTailwind.primaryButtonStyle,
),
),
Expanded(
child: DataTableCard(
width: maxContentWidth - 32,
child:
pagedLicenses.isEmpty
? const Center(child: Text('등록된 라이센스 정보가 없습니다.'))
: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
constraints: BoxConstraints(
minWidth: maxContentWidth - 64,
),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: LicenseTable(
licenses: pagedLicenses,
getCompanyName: _getCompanyName,
onEdit: _navigateToEditScreen,
onDelete: _deleteLicense,
),
),
),
),
),
),
// 페이지네이션 위젯 추가
if (totalCount > _pageSize)
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Pagination(
totalCount: totalCount,
currentPage: _currentPage,
pageSize: _pageSize,
onPageChanged: (page) {
setState(() {
_currentPage = page;
});
},
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:superport/models/license_model.dart';
import 'package:superport/screens/common/theme_tailwind.dart';
// 라이센스 목록 테이블 위젯 (SRP, 재사용성)
class LicenseTable extends StatelessWidget {
final List<License> licenses;
final String Function(int companyId) getCompanyName;
final void Function(int id) onEdit;
final void Function(int id) onDelete;
const LicenseTable({
super.key,
required this.licenses,
required this.getCompanyName,
required this.onEdit,
required this.onDelete,
});
@override
Widget build(BuildContext context) {
return DataTable(
columns: const [
DataColumn(label: Text('번호')),
DataColumn(label: Text('유지보수명')),
DataColumn(label: Text('기간')),
DataColumn(label: Text('방문주기')),
DataColumn(label: Text('점검형태')),
DataColumn(label: Text('관리')),
],
rows:
licenses.map((license) {
// name에서 기간, 방문주기, 점검형태 파싱 (예: '12개월,격월,방문')
final parts = license.name.split(',');
final period = parts.isNotEmpty ? parts[0] : '-';
final visit = parts.length > 1 ? parts[1] : '-';
final inspection = parts.length > 2 ? parts[2] : '-';
return DataRow(
cells: [
DataCell(Text('${license.id}')),
DataCell(Text(license.name)),
DataCell(Text(period)),
DataCell(Text(visit)),
DataCell(Text(inspection)),
DataCell(
Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(
Icons.edit,
color: AppThemeTailwind.primary,
),
onPressed: () => onEdit(license.id!),
),
IconButton(
icon: const Icon(
Icons.delete,
color: AppThemeTailwind.danger,
),
onPressed: () => onDelete(license.id!),
),
],
),
),
],
);
}).toList(),
);
}
}