학교 전용 공부 타이머(열품타) + 학년별 랭킹 기능 추가

학생 참여 유도를 위해 공부 시작/종료 타이머와 학년별(오늘/이번주/전체)
랭킹 화면을 대시보드에 추가. 로그인 응답에 학년 정보를 포함시켜
세션 저장/복원 전체 경로에 전달되도록 함.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-14 14:58:55 +09:00
co-authored by Claude Sonnet 5
parent 26e54a1798
commit a59a3054fb
9 changed files with 662 additions and 2 deletions
+7
View File
@@ -78,6 +78,7 @@ class _LoginScreenState extends State<LoginScreen> {
result.name!,
result.role!,
result.isDeviceMatched,
result.grade,
);
break;
case LoginOutcome.success:
@@ -87,6 +88,7 @@ class _LoginScreenState extends State<LoginScreen> {
result.studentId!,
result.name!,
result.isDeviceMatched,
result.grade,
);
break;
}
@@ -98,6 +100,7 @@ class _LoginScreenState extends State<LoginScreen> {
String name,
String role,
bool isDeviceMatched,
int? grade,
) {
final TextEditingController newPwController = TextEditingController();
@@ -168,6 +171,7 @@ class _LoginScreenState extends State<LoginScreen> {
studentId,
name,
isDeviceMatched,
grade,
);
} else {
AppNotice.show(context, message);
@@ -189,6 +193,7 @@ class _LoginScreenState extends State<LoginScreen> {
String studentId,
String name,
bool isDeviceMatched,
int? grade,
) async {
if (_keepLoggedIn) {
await SessionStore.save(
@@ -197,6 +202,7 @@ class _LoginScreenState extends State<LoginScreen> {
userName: name,
role: role,
isDeviceMatched: isDeviceMatched,
grade: grade,
),
);
} else {
@@ -211,6 +217,7 @@ class _LoginScreenState extends State<LoginScreen> {
userName: name,
role: role,
isDeviceMatched: isDeviceMatched,
grade: grade,
),
),
);
+20
View File
@@ -19,6 +19,7 @@ import 'launchpad_transition.dart';
import 'login_screen.dart';
import 'nfc_poccket_checkin_screen.dart';
import 'nfc_tag_writer_screen.dart';
import 'study_timer_screen.dart';
import 'teacher_attendance_page.dart';
import 'teacher_student_management_page.dart';
@@ -27,6 +28,7 @@ class MainDashboard extends StatefulWidget {
final String? userName;
final String role; // 'student' | 'teacher' | 'admin'
final bool isDeviceMatched;
final int? grade; // 🎓 공부 타이머 학년별 랭킹에서 본인 학년을 기본값으로 쓰기 위함.
const MainDashboard({
super.key,
@@ -34,6 +36,7 @@ class MainDashboard extends StatefulWidget {
this.userName,
required this.role,
this.isDeviceMatched = true,
this.grade,
});
@override
@@ -312,6 +315,23 @@ class _MainDashboardState extends State<MainDashboard> {
),
),
));
tiles.add((
id: 'study_timer',
child: _buildModernCard(
icon: Icons.timer_rounded,
title: '공부 타이머',
subtitle: '열품타 | 학년별 공부 랭킹',
color: AppPalette.ink,
onTap: () => pushLaunchpad(
context,
(context) => StudyTimerScreen(
studentId: _displayId,
studentName: _displayName,
grade: widget.grade,
),
),
),
));
}
if (_isTeacherOrAbove) {
+193
View File
@@ -0,0 +1,193 @@
// 🏆 학년별 공부시간 랭킹 화면 (UI 전용).
// 서버 통신/상태는 lib/function/study_ranking_controller.dart가 담당한다.
import 'package:flutter/material.dart';
import '../function/study_ranking_controller.dart';
import '../theme/app_palette.dart';
import 'title_pill.dart';
class StudyRankingScreen extends StatefulWidget {
final int grade;
final String myStudentId;
const StudyRankingScreen({
super.key,
required this.grade,
required this.myStudentId,
});
@override
State<StudyRankingScreen> createState() => _StudyRankingScreenState();
}
class _StudyRankingScreenState extends State<StudyRankingScreen> {
late final StudyRankingController _controller;
@override
void initState() {
super.initState();
_controller = StudyRankingController(grade: widget.grade);
_controller.init();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
String _formatHM(int totalSeconds) {
final h = totalSeconds ~/ 3600;
final m = (totalSeconds % 3600) ~/ 60;
if (h > 0) return '$h시간 $m분';
return '$m분';
}
Color? _rankColor(int rank) {
switch (rank) {
case 1:
return const Color(0xFFC9A227); // 금
case 2:
return const Color(0xFF9AA0A6); // 은
case 3:
return const Color(0xFFB07A4B); // 동
default:
return null;
}
}
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: _controller,
builder: (context, _) {
final ranking = _controller.ranking;
return Scaffold(
backgroundColor: AppPalette.mist,
appBar: AppBar(
backgroundColor: Colors.transparent,
foregroundColor: AppPalette.ink,
elevation: 0,
centerTitle: true,
title: TitlePill('${widget.grade}학년 공부 랭킹'),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
child: Row(
children: [
_periodChip('today', '오늘'),
const SizedBox(width: 8),
_periodChip('week', '이번주'),
const SizedBox(width: 8),
_periodChip('total', '전체'),
],
),
),
Expanded(
child: _controller.isLoading
? const Center(child: CircularProgressIndicator())
: ranking.isEmpty
? const Center(
child: Text(
'아직 기록이 없어요.\n공부 타이머를 눌러 1등에 도전해보세요.',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey),
),
)
: ListView.builder(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
itemCount: ranking.length,
itemBuilder: (context, index) {
final r = ranking[index];
final bool isMe =
r['studentId'] == widget.myStudentId;
final int rank = (r['rank'] as num).toInt();
final medalColor = _rankColor(rank);
return Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration(
color: isMe ? AppPalette.ink : AppPalette.paper,
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: isMe ? AppPalette.ink : AppPalette.sage,
),
),
child: Row(
children: [
SizedBox(
width: 32,
child: medalColor != null
? Icon(
Icons.emoji_events_rounded,
color: medalColor,
size: 22,
)
: Text(
'$rank',
style: TextStyle(
fontWeight: FontWeight.bold,
color: isMe
? Colors.white
: AppPalette.ink,
),
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
r['name'] ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
color: isMe
? Colors.white
: AppPalette.ink,
),
),
),
Text(
_formatHM((r['totalSeconds'] as num).toInt()),
style: TextStyle(
fontWeight: FontWeight.bold,
color: isMe ? Colors.white : AppPalette.ink,
),
),
],
),
);
},
),
),
],
),
);
},
);
}
Widget _periodChip(String value, String label) {
final bool selected = _controller.period == value;
return Expanded(
child: ChoiceChip(
label: Center(child: Text(label)),
selected: selected,
onSelected: (_) => _controller.setPeriod(value),
selectedColor: AppPalette.ink,
labelStyle: TextStyle(
color: selected ? Colors.white : AppPalette.ink,
fontWeight: FontWeight.bold,
),
),
);
}
}
+233
View File
@@ -0,0 +1,233 @@
// ⏱️ 우리 학교 전용 "열품타" 공부 타이머 화면 (UI 전용).
// 서버 통신/상태는 lib/function/study_timer_controller.dart가 담당한다.
import 'package:flutter/material.dart';
import '../function/study_timer_controller.dart';
import '../theme/app_palette.dart';
import 'app_notice.dart';
import 'launchpad_transition.dart';
import 'study_ranking_screen.dart';
import 'title_pill.dart';
class StudyTimerScreen extends StatefulWidget {
final String studentId;
final String studentName;
final int? grade;
const StudyTimerScreen({
super.key,
required this.studentId,
required this.studentName,
this.grade,
});
@override
State<StudyTimerScreen> createState() => _StudyTimerScreenState();
}
class _StudyTimerScreenState extends State<StudyTimerScreen> {
late final StudyTimerController _controller;
@override
void initState() {
super.initState();
_controller = StudyTimerController(
studentId: widget.studentId,
studentName: widget.studentName,
);
_controller.init();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
String _formatHMS(int totalSeconds) {
final h = totalSeconds ~/ 3600;
final m = (totalSeconds % 3600) ~/ 60;
final s = totalSeconds % 60;
final hh = h.toString().padLeft(2, '0');
final mm = m.toString().padLeft(2, '0');
final ss = s.toString().padLeft(2, '0');
return '$hh:$mm:$ss';
}
String _formatHM(int totalSeconds) {
final h = totalSeconds ~/ 3600;
final m = (totalSeconds % 3600) ~/ 60;
if (h > 0) return '$h시간 $m분';
return '$m분';
}
Future<void> _toggle() async {
final (success, message) = _controller.isRunning
? await _controller.stop()
: await _controller.start();
if (!mounted) return;
AppNotice.show(
context,
message,
icon: success ? Icons.check_circle_rounded : Icons.error_outline_rounded,
);
}
void _openRanking() {
if (widget.grade == null) {
AppNotice.show(context, '학년 정보가 없어 랭킹을 볼 수 없어요.');
return;
}
pushLaunchpad(
context,
(context) => StudyRankingScreen(
grade: widget.grade!,
myStudentId: widget.studentId,
),
);
}
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: _controller,
builder: (context, _) {
final bool isRunning = _controller.isRunning;
return Scaffold(
backgroundColor: AppPalette.mist,
appBar: AppBar(
backgroundColor: Colors.transparent,
foregroundColor: AppPalette.ink,
elevation: 0,
centerTitle: true,
title: const TitlePill('공부 타이머'),
actions: [
IconButton(
icon: const Icon(Icons.leaderboard_rounded),
tooltip: '학년 랭킹',
onPressed: _openRanking,
),
],
),
body: _controller.isLoading
? const Center(child: CircularProgressIndicator())
: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
isRunning ? '지금 공부 중이에요' : '공부를 시작해볼까요?',
style: const TextStyle(
fontSize: 15,
color: Colors.grey,
),
),
const SizedBox(height: 12),
Text(
_formatHMS(_controller.liveElapsedSeconds),
style: const TextStyle(
fontSize: 52,
fontWeight: FontWeight.bold,
color: AppPalette.ink,
),
),
const SizedBox(height: 36),
GestureDetector(
onTap: _controller.isBusy ? null : _toggle,
child: Container(
width: 140,
height: 140,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isRunning
? Colors.red[400]
: AppPalette.ink,
boxShadow: [
BoxShadow(
color:
(isRunning ? Colors.red : AppPalette.ink)
.withValues(alpha: 0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Center(
child: _controller.isBusy
? const CircularProgressIndicator(
color: Colors.white,
)
: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
isRunning
? Icons.stop_rounded
: Icons.play_arrow_rounded,
color: Colors.white,
size: 36,
),
Text(
isRunning ? '공부 종료' : '공부 시작',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
),
const SizedBox(height: 40),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_statBox(
'오늘',
_formatHM(_controller.todaySecondsLive),
),
const SizedBox(width: 12),
_statBox(
'이번주',
_formatHM(_controller.weekSecondsLive),
),
const SizedBox(width: 12),
_statBox(
'전체',
_formatHM(_controller.totalSecondsLive),
),
],
),
],
),
),
),
);
},
);
}
Widget _statBox(String label, String value) {
return Container(
width: 100,
padding: const EdgeInsets.symmetric(vertical: 14),
decoration: BoxDecoration(
color: AppPalette.paper,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppPalette.sage),
),
child: Column(
children: [
Text(label, style: TextStyle(color: Colors.grey[600], fontSize: 12)),
const SizedBox(height: 4),
Text(
value,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
],
),
);
}
}