Files
superport/lib/screens/user/widgets/user_table.dart
2025-07-02 17:45:44 +09:00

99 lines
3.8 KiB
Dart

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(),
),
),
),
);
}
}