선생님/마스터 계정의 학생 계정 관리 화면을 하나로 통합

- 두 화면이 서로 다른 기능만 갖고 있던 문제 해결: 선생님 화면(엑셀 일괄등록,
  학년 지정, 커스텀 초기비번)에 마스터 화면에만 있던 실시간 학생 목록 조회 +
  기기 리셋(학생이 폰 바꿨을 때 재등록용) 기능을 합침
- 학번을 직접 타이핑하던 블라인드 학년변경/삭제 다이얼로그를 목록의
  행별 액션(학년 칩, 기기 리셋 버튼, 삭제 버튼)으로 교체
- 계정 생성/삭제/학년변경 성공 시 목록 자동 새로고침
- 마스터(2061) 계정의 "학생 계정 관리" 카드도 이 통합 화면으로 연결하고,
  중복되던 student_management_screen.dart / student_management_controller.dart 삭제

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-30 01:23:46 +09:00
co-authored by Claude Sonnet 5
parent a622249008
commit 94ba3efff7
5 changed files with 288 additions and 699 deletions
+228 -287
View File
@@ -27,6 +27,12 @@ class _TeacherStudentManagementPageState
int? _selectedGrade;
bool _isDragging = false;
@override
void initState() {
super.initState();
_controller.init();
}
@override
void dispose() {
_controller.dispose();
@@ -244,185 +250,125 @@ class _TeacherStudentManagementPageState
);
}
// 🏫 [기존 학생 학년 지정/변경 다이얼로그]
void _showUpdateGradeDialog() {
final TextEditingController idController = TextEditingController();
int? grade;
// 🏫 [목록 행의 "학년" 칩] 눌러서 바로 학년 변경 (미배정/1/2/3학년 중 선택).
Future<void> _showGradeMenu(
BuildContext tileContext,
String studentId,
String studentName,
int? currentGrade,
) async {
final RenderBox box = tileContext.findRenderObject() as RenderBox;
final Offset position = box.localToGlobal(Offset.zero);
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setDialogState) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
title: const Text(
'🏫 학년 지정/변경',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'이미 만들어진 학생 계정의 학년을 지정하거나 바꿉니다.',
style: TextStyle(color: Colors.black54, fontSize: 13),
),
const SizedBox(height: 16),
TextField(
controller: idController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: '학번',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.badge),
),
),
const SizedBox(height: 12),
DropdownButtonFormField<int?>(
initialValue: grade,
decoration: const InputDecoration(
labelText: '학년',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.class_),
),
items: const [
DropdownMenuItem(value: null, child: Text('미배정')),
DropdownMenuItem(value: 1, child: Text('1학년')),
DropdownMenuItem(value: 2, child: Text('2학년')),
DropdownMenuItem(value: 3, child: Text('3학년')),
],
onChanged: (value) => setDialogState(() => grade = value),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('취소', style: TextStyle(color: Colors.grey)),
),
ElevatedButton(
onPressed: () async {
final inputId = idController.text.trim();
if (inputId.isEmpty) return;
Navigator.pop(context);
final (_, message) = await _controller.updateStudentGrade(
studentId: inputId,
grade: grade,
);
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message)));
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'적용',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
],
);
},
);
},
final selected = await showMenu<int?>(
context: tileContext,
position: RelativeRect.fromLTRB(
position.dx,
position.dy + box.size.height,
position.dx,
0,
),
items: const [
PopupMenuItem(value: null, child: Text('미배정')),
PopupMenuItem(value: 1, child: Text('1학년')),
PopupMenuItem(value: 2, child: Text('2학년')),
PopupMenuItem(value: 3, child: Text('3학년')),
],
);
}
if (selected == currentGrade) return; // 취소했거나 같은 값 선택
if (!mounted) return;
// ❌ [학생 삭제 버튼 동작]
Future<void> _deleteStudentAccount(String studentId) async {
final (_, message) = await _controller.deleteStudentAccount(studentId);
final (_, message) = await _controller.updateStudentGrade(
studentId: studentId,
grade: selected,
);
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message)));
}
// 🚨 계정 삭제 확인 팝업창 모달
void _showDeleteDialog() {
final TextEditingController deleteIdController = TextEditingController();
// 🔓 [목록 행의 "기기 리셋" 버튼] 학생이 폰을 바꿨을 때 등록 초기화.
void _confirmResetDevice(String studentId, String studentName) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
builder: (ctx) => AlertDialog(
title: const Text(
'⚠️ 기기 등록 초기화',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.purple),
),
content: Text('$studentName 학생의 스마트폰 기기 등록과 비밀번호(1234)를 초기화하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('취소', style: TextStyle(color: Colors.grey)),
),
title: Row(
children: [
Icon(Icons.warning_amber_rounded, color: Colors.orange[700]),
const SizedBox(width: 10),
const Text(
'학생 계정 강제 삭제',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'영구 삭제할 학생의 학번을 정확하게 입력하세요.',
style: TextStyle(color: Colors.black54, fontSize: 13),
),
const SizedBox(height: 16),
TextField(
controller: deleteIdController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: '학번 입력',
labelStyle: TextStyle(color: Colors.orange[700]),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide(
color: Colors.orange[700]!,
width: 2,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
),
prefixIcon: const Icon(Icons.no_accounts_rounded),
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('취소', style: TextStyle(color: Colors.grey)),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.purple,
foregroundColor: Colors.white,
),
ElevatedButton(
onPressed: () {
final inputId = deleteIdController.text.trim();
if (inputId.isNotEmpty) {
Navigator.pop(context);
_deleteStudentAccount(inputId);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange[700],
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'삭제 확정',
style: TextStyle(fontWeight: FontWeight.bold),
),
onPressed: () async {
Navigator.pop(ctx);
final (_, message) = await _controller.resetDevice(
studentId,
studentName,
);
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message)));
},
child: const Text('초기화 승인'),
),
],
),
);
}
// 🚨 [목록 행의 삭제 버튼] 계정 완전 삭제 확인 팝업.
void _confirmDeleteStudent(String studentId, String studentName) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
title: Row(
children: [
Icon(Icons.warning_amber_rounded, color: Colors.red[700]),
const SizedBox(width: 10),
const Text(
'계정 완전 삭제',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
],
);
},
),
content: Text(
'정말로 $studentName ($studentId) 학생의 계정을 영구 삭제하시겠습니까?\n이 작업은 되돌릴 수 없습니다.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('취소', style: TextStyle(color: Colors.grey)),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red[600],
foregroundColor: Colors.white,
),
onPressed: () async {
Navigator.pop(ctx);
final (_, message) = await _controller.deleteStudentAccount(
studentId,
);
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message)));
},
child: const Text('영구 삭제'),
),
],
),
);
}
@@ -642,7 +588,7 @@ class _TeacherStudentManagementPageState
),
const SizedBox(height: 36),
// 🏷️ 인디케이터 바 (기존 학생 학년 지정/변경)
// 🏷️ 인디케이터 바 (전체 학생 목록)
Row(
children: [
Container(
@@ -655,139 +601,134 @@ class _TeacherStudentManagementPageState
),
const SizedBox(width: 8),
const Text(
'기존 학생 학년 지정/변경',
'전체 학생 목록',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 16),
InkWell(
onTap: _showUpdateGradeDialog,
borderRadius: BorderRadius.circular(24),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(24),
border: Border.all(color: Colors.blue.shade200),
),
child: const Row(
children: [
Icon(Icons.class_rounded, color: Colors.blue, size: 32),
SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'학번으로 학년 지정',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.blue,
),
),
SizedBox(height: 2),
Text(
'이미 만든 계정의 학년을 나중에 지정하거나 바꿀 때 사용',
style: TextStyle(
fontSize: 12,
color: Colors.blueAccent,
),
),
],
),
),
Icon(
Icons.arrow_forward_ios_rounded,
color: Colors.blue,
size: 16,
),
],
),
),
),
const SizedBox(height: 36),
// 🏷️ 인디케이터 바 2 (삭제 권한 제어메뉴)
Row(
children: [
Container(
width: 4,
height: 16,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
const Text(
'위험 구역 (Account Reset)',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.redAccent,
),
const Spacer(),
IconButton(
icon: const Icon(Icons.refresh_rounded),
onPressed: _controller.isLoadingStudents
? null
: _controller.fetchStudents,
tooltip: '새로고침',
),
],
),
const SizedBox(height: 16),
const SizedBox(height: 8),
const Text(
'학년 칩을 눌러 학년을 바꾸고, 기기 리셋은 학생이 폰을 바꿨을 때 사용하세요.',
style: TextStyle(color: Colors.black54, fontSize: 12),
),
const SizedBox(height: 12),
// 🚨 학생 삭제 트리거 카드
InkWell(
onTap: _showDeleteDialog,
borderRadius: BorderRadius.circular(24),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.red[50],
borderRadius: BorderRadius.circular(24),
border: Border.all(color: Colors.red.shade200),
),
child: const Row(
children: [
Icon(
Icons.delete_sweep_rounded,
color: Colors.red,
size: 32,
),
SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'학생 계정 강제 원격 삭제',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.red,
),
),
SizedBox(height: 2),
Text(
'인증 초기화 및 DB 제거용',
style: TextStyle(
fontSize: 12,
color: Colors.redAccent,
),
),
],
_controller.isLoadingStudents
? const Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Center(child: CircularProgressIndicator()),
)
: _controller.students.isEmpty
? const Padding(
padding: EdgeInsets.symmetric(vertical: 24),
child: Center(
child: Text(
'가입된 학생 계정이 없습니다.',
style: TextStyle(color: Colors.grey),
),
),
Icon(
Icons.arrow_forward_ios_rounded,
color: Colors.red,
size: 16,
),
],
),
),
),
)
: ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _controller.students.length,
itemBuilder: (context, index) {
final student = _controller.students[index];
final String studentId = student['id'].toString();
final String studentName = student['name'].toString();
final int? grade = student['grade'] as int?;
final bool needsReset = student['device'] == '초기화 필요';
return Card(
elevation: 1,
margin: const EdgeInsets.only(bottom: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
leading: CircleAvatar(
backgroundColor: needsReset
? Colors.red[50]
: Colors.blue[50],
child: Icon(
needsReset ? Icons.lock_reset : Icons.person,
color: needsReset ? Colors.red : Colors.blue,
),
),
title: Text(
'$studentName ($studentId)',
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
needsReset ? '기기 초기화 승인 대기중' : '정상 등록 상태',
style: TextStyle(
color: needsReset ? Colors.red : Colors.grey,
fontWeight: needsReset
? FontWeight.bold
: FontWeight.normal,
),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Builder(
builder: (chipContext) => ActionChip(
label: Text(
grade != null ? '$grade학년' : '미배정',
),
onPressed: () => _showGradeMenu(
chipContext,
studentId,
studentName,
grade,
),
),
),
IconButton(
icon: const Icon(
Icons.lock_reset,
color: Colors.purple,
),
tooltip: '기기 리셋',
onPressed: () => _confirmResetDevice(
studentId,
studentName,
),
),
IconButton(
icon: const Icon(
Icons.delete_forever_rounded,
color: Colors.redAccent,
),
tooltip: '계정 영구 삭제',
onPressed: () => _confirmDeleteStudent(
studentId,
studentName,
),
),
],
),
),
);
},
),
],
),
),