- 실시간 출석 현황을 학년별 섹션으로 묶어서 표시 (백엔드에 grade 필드 추가)
- 학생 계정 추가 폼에 학년 선택 드롭다운 추가
- 학생 계정 생성/삭제가 실제로는 존재하지 않는 엔드포인트를 호출하던
버그 수정 (/api/users/register-student, /api/users/delete/{id} →
/api/users/create, /api/users/delete)
- 학생 대시보드(개발자 모드) 카드 그리드가 넓은 화면에서 과도하게
커지던 레이아웃 버그 수정, 웹은 5열/폰은 2열로 반응형 처리
- 버전 1.2.0+6
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
512 lines
20 KiB
Dart
512 lines
20 KiB
Dart
// 🎓 학생 대시보드 (UI 전용). NFC 주머니 체크인 진입, 실시간 학교 상황 안내,
|
|
// 개발자 마스터 계정 전용 관리 메뉴(현황/DB제어/계정관리/삭제) 카드를 그린다.
|
|
// 계정 삭제 서버 통신은 lib/function/student_dashboard_controller.dart가 담당한다.
|
|
import 'package:flutter/material.dart';
|
|
import '../function/student_dashboard_controller.dart';
|
|
import 'nfc_poccket_checkin_screen.dart';
|
|
import 'login_screen.dart';
|
|
import 'teacher_attendance_page.dart';
|
|
import 'admin_dashboard.dart';
|
|
import 'student_management_screen.dart';
|
|
import 'nfc_tag_writer_screen.dart';
|
|
|
|
// -------------------------------------------------------------
|
|
// 2. 학생 대시보드 (StudentDashboard)
|
|
// -------------------------------------------------------------
|
|
|
|
class StudentDashboard extends StatefulWidget {
|
|
final String studentId;
|
|
final String studentName;
|
|
final bool isDeviceMatched; // 🆕 [변경] 기기 UUID가 매칭되었는지 확인하는 변수 추가
|
|
|
|
const StudentDashboard({
|
|
super.key,
|
|
required this.studentId,
|
|
required this.studentName,
|
|
required this.isDeviceMatched, // 🆕 [변경] 필수 매개변수로 등록
|
|
});
|
|
|
|
@override
|
|
State<StudentDashboard> createState() => _StudentDashboardState();
|
|
}
|
|
|
|
class _StudentDashboardState extends State<StudentDashboard> {
|
|
final StudentDashboardController _controller = StudentDashboardController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
// 1️⃣ NFC 태그 카드 → 실제 NFC 주머니 체크인 화면으로 이동
|
|
void _openPocketCheckIn(BuildContext context) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => NfcPocketCheckInScreen(
|
|
studentId: widget.studentId,
|
|
studentName: widget.studentName,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 2️⃣ [기존 동일] 마스터 계정 전용 회원 삭제 버튼 동작
|
|
Future<void> _deleteUser(String userId) async {
|
|
final (_, message) = await _controller.deleteUser(userId);
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(message)));
|
|
}
|
|
|
|
// 3️⃣ [기존 동일] 학번/교직원 번호를 입력받는 모던 팝업창(Dialog)
|
|
void _showDeleteUserDialog(BuildContext context) {
|
|
final TextEditingController idController = TextEditingController();
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24),
|
|
),
|
|
title: const Row(
|
|
children: [
|
|
Icon(Icons.warning_amber_rounded, color: Colors.redAccent),
|
|
SizedBox(width: 10),
|
|
Text(
|
|
'계정 강제 삭제',
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
|
),
|
|
],
|
|
),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'학생의 학번 또는 교사의 교직원 번호를 입력하세요.\nDB에서 해당 계정과 토큰이 즉시 삭제됩니다.',
|
|
style: TextStyle(
|
|
color: Colors.black54,
|
|
fontSize: 13,
|
|
height: 1.4,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: idController,
|
|
decoration: InputDecoration(
|
|
labelText: '학번 또는 교직원 번호',
|
|
hintText: '예: 201101 또는 T1001',
|
|
labelStyle: TextStyle(color: Colors.red[400]),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide(color: Colors.red[400]!, width: 2),
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
prefixIcon: const Icon(Icons.person_remove_alt_1_rounded),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text(
|
|
'취소',
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
final inputId = idController.text.trim();
|
|
if (inputId.isNotEmpty) {
|
|
Navigator.pop(context);
|
|
_deleteUser(inputId);
|
|
}
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.redAccent,
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
child: const Text(
|
|
'삭제 실행',
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
final bool isDeveloper = widget.studentId == "2061";
|
|
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey[100],
|
|
appBar: AppBar(
|
|
title: Text(
|
|
isDeveloper ? '👑 MASTER CONTROL' : '🎓 STUDENT PORTAL',
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
letterSpacing: 1.2,
|
|
),
|
|
),
|
|
centerTitle: true,
|
|
backgroundColor: isDeveloper
|
|
? Colors.deepPurple[700]
|
|
: Colors.indigo[700],
|
|
foregroundColor: Colors.white,
|
|
elevation: 0,
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.logout_rounded),
|
|
onPressed: () => Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => const LoginScreen()),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 24,
|
|
vertical: 28,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: isDeveloper
|
|
? Colors.deepPurple[700]
|
|
: Colors.indigo[700],
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(32),
|
|
bottomRight: Radius.circular(32),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(4),
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: CircleAvatar(
|
|
radius: 30,
|
|
backgroundColor: isDeveloper
|
|
? Colors.deepPurple[50]
|
|
: Colors.indigo[50],
|
|
child: Icon(
|
|
isDeveloper
|
|
? Icons.admin_panel_settings_rounded
|
|
: Icons.school_rounded,
|
|
size: 32,
|
|
color: isDeveloper
|
|
? Colors.deepPurple
|
|
: Colors.indigo,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 18),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'${widget.studentName} 님',
|
|
style: const TextStyle(
|
|
fontSize: 22,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
isDeveloper
|
|
? '최고 관리 권한 활성화됨'
|
|
: '학번: ${widget.studentId} | 인증 완료',
|
|
style: TextStyle(
|
|
color: Colors.white.withValues(alpha: 0.8),
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 32),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 4,
|
|
height: 18,
|
|
decoration: BoxDecoration(
|
|
color: isDeveloper
|
|
? Colors.deepPurple
|
|
: Colors.indigo,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
const Text(
|
|
'스마트 관리 시스템 메뉴',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
// 🖥️ 웹(넓은 화면)은 한 줄에 5개씩, 폰(좁은 화면)은 기존 2개 그대로.
|
|
final bool isWide = constraints.maxWidth >= 800;
|
|
return Center(
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxWidth: isWide ? 1300 : 700,
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
child: GridView.count(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
crossAxisCount: isWide ? 5 : 2,
|
|
crossAxisSpacing: 16,
|
|
mainAxisSpacing: 16,
|
|
childAspectRatio: 0.95,
|
|
children: [
|
|
// 🆕 [변경 지점] 기기가 일치하면 정상 활성화, 일치하지 않으면 자물쇠Lock 처리
|
|
if (isDeveloper || widget.studentId != "2061")
|
|
_buildModernCard(
|
|
icon: widget.isDeviceMatched
|
|
? Icons.contactless_rounded
|
|
: Icons.lock_rounded,
|
|
title: 'NFC 태그',
|
|
subtitle: widget.isDeviceMatched
|
|
? '출석 및 폰 수거 완료'
|
|
: '⚠️ 본인 인증 기기 전용',
|
|
color: widget.isDeviceMatched
|
|
? Colors.blue
|
|
: Colors.grey[400]!,
|
|
onTap: widget.isDeviceMatched
|
|
? () => _openPocketCheckIn(context)
|
|
: () {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(
|
|
const SnackBar(
|
|
content: Text(
|
|
'🚨 대리 출석 방지를 위해 등록된 본인 스마트폰에서만 출석 가능합니다.',
|
|
),
|
|
),
|
|
);
|
|
},
|
|
isActionButton: widget.isDeviceMatched,
|
|
isLoading: _controller.isLoading,
|
|
),
|
|
|
|
// 🆕 [추가 지점] 기기 일치 여부 상관없이 태블릿에서도 누구나 확인 가능한 학교 상황판 카드
|
|
_buildModernCard(
|
|
icon: Icons.fastfood_rounded,
|
|
title: '실시간 학교 상황',
|
|
subtitle: '급식실 줄 & 매점 재고 확인',
|
|
color: Colors.orange[700]!,
|
|
onTap: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('🍔 실시간 학교 상황 페이지로 이동합니다.'),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
|
|
if (isDeveloper)
|
|
_buildModernCard(
|
|
icon: Icons.monitor_heart_rounded,
|
|
title: '실시간 현황',
|
|
subtitle: '교사용 수거 모니터링',
|
|
color: Colors.teal,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const TeacherAttendancePage(),
|
|
),
|
|
),
|
|
),
|
|
if (isDeveloper)
|
|
_buildModernCard(
|
|
icon: Icons.terminal_rounded,
|
|
title: '서버 DB 제어',
|
|
subtitle: '시스템 원격 초기화',
|
|
color: Colors.amber[800]!,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const AdminDashboard(),
|
|
),
|
|
),
|
|
),
|
|
if (isDeveloper)
|
|
_buildModernCard(
|
|
icon: Icons.add_moderator_rounded,
|
|
title: '학생 계정 관리',
|
|
subtitle: 'UUID 리셋 및 승인',
|
|
color: Colors.purple,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const StudentManagementScreen(),
|
|
),
|
|
),
|
|
),
|
|
if (isDeveloper)
|
|
_buildModernCard(
|
|
icon: Icons.delete_sweep_rounded,
|
|
title: '계정 강제 삭제',
|
|
subtitle: '학생 및 교사 DB 삭제',
|
|
color: Colors.red[600]!,
|
|
onTap: () => _showDeleteUserDialog(context),
|
|
),
|
|
if (isDeveloper)
|
|
_buildModernCard(
|
|
icon: Icons.edit_note_rounded,
|
|
title: 'NFC 태그 쓰기',
|
|
subtitle: '주머니 스티커 초기 설정',
|
|
color: Colors.deepPurple,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const NfcTagWriterScreen(),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 32),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
// 5️⃣ [카드 디자인 위젯] - 기존 형태 완전 보존
|
|
Widget _buildModernCard({
|
|
required IconData icon,
|
|
required String title,
|
|
required String subtitle,
|
|
required Color color,
|
|
required VoidCallback onTap,
|
|
bool isActionButton = false,
|
|
bool isLoading = false,
|
|
}) {
|
|
return InkWell(
|
|
onTap: isLoading ? null : onTap,
|
|
borderRadius: BorderRadius.circular(24),
|
|
child: Ink(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(24),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.04),
|
|
blurRadius: 16,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Icon(icon, color: color, size: 28),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
if (isLoading)
|
|
const SizedBox(
|
|
width: 16,
|
|
height: 16,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
else if (isActionButton)
|
|
Icon(
|
|
Icons.touch_app_rounded,
|
|
size: 16,
|
|
color: color.withValues(alpha: 0.5),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
subtitle,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Colors.grey[500],
|
|
height: 1.2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|