프로젝트 최초 커밋
This commit is contained in:
174
lib/screens/license/license_list.dart
Normal file
174
lib/screens/license/license_list.dart
Normal 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;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user