프로젝트 최초 커밋
This commit is contained in:
146
lib/screens/user/controllers/user_form_controller.dart
Normal file
146
lib/screens/user/controllers/user_form_controller.dart
Normal file
@@ -0,0 +1,146 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/user_model.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
import 'package:superport/utils/constants.dart';
|
||||
import 'package:superport/models/user_phone_field.dart';
|
||||
|
||||
// 사용자 폼의 상태 및 비즈니스 로직을 담당하는 컨트롤러
|
||||
class UserFormController {
|
||||
final MockDataService dataService;
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
bool isEditMode = false;
|
||||
int? userId;
|
||||
String name = '';
|
||||
int? companyId;
|
||||
int? branchId;
|
||||
String role = UserRoles.member;
|
||||
String position = '';
|
||||
String email = '';
|
||||
|
||||
// 전화번호 관련 상태
|
||||
final List<UserPhoneField> phoneFields = [];
|
||||
final List<String> phoneTypes = ['휴대폰', '사무실', '팩스', '기타'];
|
||||
|
||||
List<Company> companies = [];
|
||||
List<Branch> branches = [];
|
||||
|
||||
UserFormController({required this.dataService, this.userId});
|
||||
|
||||
// 회사 목록 로드
|
||||
void loadCompanies() {
|
||||
companies = dataService.getAllCompanies();
|
||||
}
|
||||
|
||||
// 회사 ID에 따라 지점 목록 로드
|
||||
void loadBranches(int companyId) {
|
||||
final company = dataService.getCompanyById(companyId);
|
||||
branches = company?.branches ?? [];
|
||||
// 지점 변경 시 이전 선택 지점이 새 회사에 없으면 초기화
|
||||
if (branchId != null && !branches.any((b) => b.id == branchId)) {
|
||||
branchId = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 사용자 정보 로드 (수정 모드)
|
||||
void loadUser() {
|
||||
if (userId == null) return;
|
||||
final user = dataService.getUserById(userId!);
|
||||
if (user != null) {
|
||||
name = user.name;
|
||||
companyId = user.companyId;
|
||||
branchId = user.branchId;
|
||||
role = user.role;
|
||||
position = user.position ?? '';
|
||||
email = user.email ?? '';
|
||||
if (companyId != null) {
|
||||
loadBranches(companyId!);
|
||||
}
|
||||
phoneFields.clear();
|
||||
if (user.phoneNumbers.isNotEmpty) {
|
||||
for (var phone in user.phoneNumbers) {
|
||||
phoneFields.add(
|
||||
UserPhoneField(
|
||||
type: phone['type'] ?? '휴대폰',
|
||||
initialValue: phone['number'] ?? '',
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
addPhoneField();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 전화번호 필드 추가
|
||||
void addPhoneField() {
|
||||
phoneFields.add(UserPhoneField(type: '휴대폰'));
|
||||
}
|
||||
|
||||
// 전화번호 필드 삭제
|
||||
void removePhoneField(int index) {
|
||||
if (phoneFields.length > 1) {
|
||||
phoneFields[index].dispose();
|
||||
phoneFields.removeAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
// 사용자 저장 (UI에서 호출)
|
||||
void saveUser(Function(String? error) onResult) {
|
||||
if (formKey.currentState?.validate() != true) {
|
||||
onResult('폼 유효성 검사 실패');
|
||||
return;
|
||||
}
|
||||
formKey.currentState?.save();
|
||||
if (companyId == null) {
|
||||
onResult('소속 회사를 선택해주세요');
|
||||
return;
|
||||
}
|
||||
// 전화번호 목록 준비 (UserPhoneField 기반)
|
||||
List<Map<String, String>> phoneNumbersList = [];
|
||||
for (var phoneField in phoneFields) {
|
||||
if (phoneField.number.isNotEmpty) {
|
||||
phoneNumbersList.add({
|
||||
'type': phoneField.type,
|
||||
'number': phoneField.number,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (isEditMode && userId != null) {
|
||||
final user = dataService.getUserById(userId!);
|
||||
if (user != null) {
|
||||
final updatedUser = User(
|
||||
id: user.id,
|
||||
companyId: companyId!,
|
||||
branchId: branchId,
|
||||
name: name,
|
||||
role: role,
|
||||
position: position.isNotEmpty ? position : null,
|
||||
email: email.isNotEmpty ? email : null,
|
||||
phoneNumbers: phoneNumbersList,
|
||||
);
|
||||
dataService.updateUser(updatedUser);
|
||||
}
|
||||
} else {
|
||||
final newUser = User(
|
||||
companyId: companyId!,
|
||||
branchId: branchId,
|
||||
name: name,
|
||||
role: role,
|
||||
position: position.isNotEmpty ? position : null,
|
||||
email: email.isNotEmpty ? email : null,
|
||||
phoneNumbers: phoneNumbersList,
|
||||
);
|
||||
dataService.addUser(newUser);
|
||||
}
|
||||
onResult(null);
|
||||
}
|
||||
|
||||
// 컨트롤러 해제
|
||||
void dispose() {
|
||||
for (var phoneField in phoneFields) {
|
||||
phoneField.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
lib/screens/user/controllers/user_list_controller.dart
Normal file
42
lib/screens/user/controllers/user_list_controller.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/user_model.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
import 'package:superport/utils/constants.dart';
|
||||
import 'package:superport/utils/user_utils.dart';
|
||||
|
||||
/// 담당자 목록 화면의 상태 및 비즈니스 로직을 담당하는 컨트롤러
|
||||
class UserListController extends ChangeNotifier {
|
||||
final MockDataService dataService;
|
||||
List<User> users = [];
|
||||
|
||||
UserListController({required this.dataService});
|
||||
|
||||
/// 사용자 목록 데이터 로드
|
||||
void loadUsers() {
|
||||
users = dataService.getAllUsers();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 사용자 삭제
|
||||
void deleteUser(int id, VoidCallback onDeleted) {
|
||||
dataService.deleteUser(id);
|
||||
loadUsers();
|
||||
onDeleted();
|
||||
}
|
||||
|
||||
/// 권한명 반환 함수는 user_utils.dart의 getRoleName을 사용
|
||||
|
||||
/// 회사 ID와 지점 ID로 지점명 조회
|
||||
String getBranchName(int companyId, int? branchId) {
|
||||
final company = dataService.getCompanyById(companyId);
|
||||
if (company == null || company.branches == null || branchId == null) {
|
||||
return '-';
|
||||
}
|
||||
final branch = company.branches!.firstWhere(
|
||||
(b) => b.id == branchId,
|
||||
orElse: () => Branch(companyId: companyId, name: '-'),
|
||||
);
|
||||
return branch.name;
|
||||
}
|
||||
}
|
||||
293
lib/screens/user/user_form.dart
Normal file
293
lib/screens/user/user_form.dart
Normal file
@@ -0,0 +1,293 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/user_model.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/constants.dart';
|
||||
import 'package:superport/utils/validators.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:superport/screens/user/controllers/user_form_controller.dart';
|
||||
import 'package:superport/models/user_phone_field.dart';
|
||||
import 'package:superport/screens/common/widgets/company_branch_dropdown.dart';
|
||||
|
||||
// 사용자 등록/수정 화면 (UI만 담당, 상태/로직 분리)
|
||||
class UserFormScreen extends StatefulWidget {
|
||||
final int? userId;
|
||||
const UserFormScreen({super.key, this.userId});
|
||||
|
||||
@override
|
||||
State<UserFormScreen> createState() => _UserFormScreenState();
|
||||
}
|
||||
|
||||
class _UserFormScreenState extends State<UserFormScreen> {
|
||||
late final UserFormController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = UserFormController(
|
||||
dataService: MockDataService(),
|
||||
userId: widget.userId,
|
||||
);
|
||||
_controller.isEditMode = widget.userId != null;
|
||||
_controller.loadCompanies();
|
||||
if (_controller.isEditMode) {
|
||||
_controller.loadUser();
|
||||
} else if (_controller.phoneFields.isEmpty) {
|
||||
_controller.addPhoneField();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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: [
|
||||
// 이름
|
||||
_buildTextField(
|
||||
label: '이름',
|
||||
initialValue: _controller.name,
|
||||
hintText: '사용자 이름을 입력하세요',
|
||||
validator: (value) => validateRequired(value, '이름'),
|
||||
onSaved: (value) => _controller.name = value!,
|
||||
),
|
||||
// 직급
|
||||
_buildTextField(
|
||||
label: '직급',
|
||||
initialValue: _controller.position,
|
||||
hintText: '직급을 입력하세요',
|
||||
onSaved: (value) => _controller.position = value ?? '',
|
||||
),
|
||||
// 소속 회사/지점
|
||||
CompanyBranchDropdown(
|
||||
companies: _controller.companies,
|
||||
selectedCompanyId: _controller.companyId,
|
||||
selectedBranchId: _controller.branchId,
|
||||
branches: _controller.branches,
|
||||
onCompanyChanged: (value) {
|
||||
setState(() {
|
||||
_controller.companyId = value;
|
||||
_controller.branchId = null;
|
||||
if (value != null) {
|
||||
_controller.loadBranches(value);
|
||||
} else {
|
||||
_controller.branches = [];
|
||||
}
|
||||
});
|
||||
},
|
||||
onBranchChanged: (value) {
|
||||
setState(() {
|
||||
_controller.branchId = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
// 이메일
|
||||
_buildTextField(
|
||||
label: '이메일',
|
||||
initialValue: _controller.email,
|
||||
hintText: '이메일을 입력하세요',
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) return null;
|
||||
return validateEmail(value);
|
||||
},
|
||||
onSaved: (value) => _controller.email = value ?? '',
|
||||
),
|
||||
// 전화번호
|
||||
_buildPhoneFieldsSection(),
|
||||
// 권한
|
||||
_buildRoleRadio(),
|
||||
const SizedBox(height: 24),
|
||||
// 저장 버튼
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _onSaveUser,
|
||||
style: AppThemeTailwind.primaryButtonStyle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
_controller.isEditMode ? '수정하기' : '등록하기',
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 이름/직급/이메일 등 공통 텍스트 필드 위젯
|
||||
Widget _buildTextField({
|
||||
required String label,
|
||||
required String initialValue,
|
||||
required String hintText,
|
||||
TextInputType? keyboardType,
|
||||
List<TextInputFormatter>? inputFormatters,
|
||||
String? Function(String?)? validator,
|
||||
void Function(String?)? onSaved,
|
||||
}) {
|
||||
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),
|
||||
keyboardType: keyboardType,
|
||||
inputFormatters: inputFormatters,
|
||||
validator: validator,
|
||||
onSaved: onSaved,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 전화번호 입력 필드 섹션 위젯 (UserPhoneField 기반)
|
||||
Widget _buildPhoneFieldsSection() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('전화번호', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
..._controller.phoneFields.asMap().entries.map((entry) {
|
||||
final i = entry.key;
|
||||
final phoneField = entry.value;
|
||||
return Row(
|
||||
children: [
|
||||
// 종류 드롭다운
|
||||
DropdownButton<String>(
|
||||
value: phoneField.type,
|
||||
items:
|
||||
_controller.phoneTypes
|
||||
.map(
|
||||
(type) =>
|
||||
DropdownMenuItem(value: type, child: Text(type)),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
phoneField.type = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 번호 입력
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: phoneField.controller,
|
||||
keyboardType: TextInputType.phone,
|
||||
decoration: const InputDecoration(hintText: '전화번호'),
|
||||
onSaved: (value) {}, // 값은 controller에서 직접 추출
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove_circle, color: Colors.red),
|
||||
onPressed:
|
||||
_controller.phoneFields.length > 1
|
||||
? () {
|
||||
setState(() {
|
||||
_controller.removePhoneField(i);
|
||||
});
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
// 추가 버튼
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_controller.addPhoneField();
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('전화번호 추가'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 권한(관리등급) 라디오 위젯
|
||||
Widget _buildRoleRadio() {
|
||||
return 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: [
|
||||
Expanded(
|
||||
child: RadioListTile<String>(
|
||||
title: const Text('관리자'),
|
||||
value: UserRoles.admin,
|
||||
groupValue: _controller.role,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_controller.role = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RadioListTile<String>(
|
||||
title: const Text('일반 사용자'),
|
||||
value: UserRoles.member,
|
||||
groupValue: _controller.role,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_controller.role = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 저장 버튼 클릭 시 사용자 저장
|
||||
void _onSaveUser() {
|
||||
setState(() {
|
||||
_controller.saveUser((error) {
|
||||
if (error != null) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error)));
|
||||
} else {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
174
lib/screens/user/user_list.dart
Normal file
174
lib/screens/user/user_list.dart
Normal file
@@ -0,0 +1,174 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/user_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/user/controllers/user_list_controller.dart';
|
||||
import 'package:superport/screens/user/widgets/user_table.dart';
|
||||
import 'package:superport/utils/user_utils.dart';
|
||||
import 'package:superport/screens/common/widgets/pagination.dart';
|
||||
|
||||
// 담당자 목록 화면 (UI만 담당)
|
||||
class UserListScreen extends StatefulWidget {
|
||||
const UserListScreen({super.key});
|
||||
|
||||
@override
|
||||
State<UserListScreen> createState() => _UserListScreenState();
|
||||
}
|
||||
|
||||
class _UserListScreenState extends State<UserListScreen> {
|
||||
late final UserListController _controller;
|
||||
final MockDataService _dataService = MockDataService();
|
||||
// 페이지네이션 상태 추가
|
||||
int _currentPage = 1;
|
||||
final int _pageSize = 10;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = UserListController(dataService: _dataService);
|
||||
_controller.loadUsers();
|
||||
_controller.addListener(_refresh);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.removeListener(_refresh);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// 상태 갱신용 setState 래퍼
|
||||
void _refresh() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
// 사용자 추가 화면 이동
|
||||
void _navigateToAddScreen() async {
|
||||
final result = await Navigator.pushNamed(context, '/user/add');
|
||||
if (result == true) {
|
||||
_controller.loadUsers();
|
||||
}
|
||||
}
|
||||
|
||||
// 사용자 수정 화면 이동
|
||||
void _navigateToEditScreen(int id) async {
|
||||
final result = await Navigator.pushNamed(
|
||||
context,
|
||||
'/user/edit',
|
||||
arguments: id,
|
||||
);
|
||||
if (result == true) {
|
||||
_controller.loadUsers();
|
||||
}
|
||||
}
|
||||
|
||||
// 사용자 삭제 다이얼로그
|
||||
void _showDeleteDialog(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: () {
|
||||
_controller.deleteUser(id, () {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 회사명 반환 함수 (내부에서만 사용)
|
||||
String _getCompanyName(int companyId) {
|
||||
final company = _dataService.getCompanyById(companyId);
|
||||
return company?.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.users.length;
|
||||
final int startIndex = (_currentPage - 1) * _pageSize;
|
||||
final int endIndex =
|
||||
(startIndex + _pageSize) > totalCount
|
||||
? totalCount
|
||||
: (startIndex + _pageSize);
|
||||
final pagedUsers = _controller.users.sublist(startIndex, endIndex);
|
||||
|
||||
return MainLayout(
|
||||
title: '담당자 관리',
|
||||
currentRoute: Routes.user,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: _controller.loadUsers,
|
||||
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: UserTable(
|
||||
users: pagedUsers,
|
||||
width: maxContentWidth - 32,
|
||||
getRoleName: getRoleName,
|
||||
getBranchName: _controller.getBranchName,
|
||||
getCompanyName: _getCompanyName,
|
||||
onEdit: _navigateToEditScreen,
|
||||
onDelete: _showDeleteDialog,
|
||||
),
|
||||
),
|
||||
),
|
||||
// 페이지네이션 위젯 추가
|
||||
if (totalCount > _pageSize)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Pagination(
|
||||
totalCount: totalCount,
|
||||
currentPage: _currentPage,
|
||||
pageSize: _pageSize,
|
||||
onPageChanged: (page) {
|
||||
setState(() {
|
||||
_currentPage = page;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
98
lib/screens/user/widgets/user_table.dart
Normal file
98
lib/screens/user/widgets/user_table.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/user_model.dart';
|
||||
|
||||
/// 사용자 목록 테이블 위젯 (SRP, 재사용성 중심)
|
||||
class UserTable extends StatelessWidget {
|
||||
final List<User> users;
|
||||
final double width;
|
||||
final String Function(String role) getRoleName;
|
||||
final String Function(int companyId, int? branchId) getBranchName;
|
||||
final String Function(int companyId) getCompanyName;
|
||||
final void Function(int userId) onEdit;
|
||||
final void Function(int userId) onDelete;
|
||||
|
||||
const UserTable({
|
||||
super.key,
|
||||
required this.users,
|
||||
required this.width,
|
||||
required this.getRoleName,
|
||||
required this.getBranchName,
|
||||
required this.getCompanyName,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return users.isEmpty
|
||||
? const Center(child: Text('등록된 사용자 정보가 없습니다.'))
|
||||
: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Container(
|
||||
constraints: BoxConstraints(minWidth: width - 32),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: DataTable(
|
||||
columns: const [
|
||||
DataColumn(label: Text('번호')),
|
||||
DataColumn(label: Text('이름')),
|
||||
DataColumn(label: Text('직급')),
|
||||
DataColumn(label: Text('소속 회사')),
|
||||
DataColumn(label: Text('소속 지점')),
|
||||
DataColumn(label: Text('이메일')),
|
||||
DataColumn(label: Text('전화번호')),
|
||||
DataColumn(label: Text('권한')),
|
||||
DataColumn(label: Text('관리')),
|
||||
],
|
||||
rows:
|
||||
users.map((user) {
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text('${user.id}')),
|
||||
DataCell(Text(user.name)),
|
||||
DataCell(Text(user.position ?? '-')),
|
||||
DataCell(Text(getCompanyName(user.companyId))),
|
||||
DataCell(
|
||||
Text(
|
||||
user.branchId != null
|
||||
? getBranchName(user.companyId, user.branchId)
|
||||
: '-',
|
||||
),
|
||||
),
|
||||
DataCell(Text(user.email ?? '-')),
|
||||
DataCell(
|
||||
user.phoneNumbers.isNotEmpty
|
||||
? Text(user.phoneNumbers.first['number'] ?? '-')
|
||||
: const Text('-'),
|
||||
),
|
||||
DataCell(Text(getRoleName(user.role))),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.edit,
|
||||
color: Colors.blue,
|
||||
),
|
||||
onPressed: () => onEdit(user.id!),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.red,
|
||||
),
|
||||
onPressed: () => onDelete(user.id!),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user