From 80667d20f124d3a09e920b89ceaaff33f9c75c45 Mon Sep 17 00:00:00 2001 From: sihoo Date: Tue, 22 Sep 2026 07:19:05 +0000 Subject: [PATCH] =?UTF-8?q?=EB=B0=B1=ED=92=88=ED=83=80=20=EB=9E=AD?= =?UTF-8?q?=ED=82=B9=EC=97=90=20=EC=A0=84=EC=B2=B4=EB=9E=AD=ED=82=B9/?= =?UTF-8?q?=ED=95=99=EB=85=84=EB=9E=AD=ED=82=B9=20=ED=95=84=ED=84=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit grade 쿼리파라미터를 생략하면 전체 학년 통합 랭킹을 주도록 백엔드를 바꾸고, 랭킹 화면에 "N학년"/"전체랭킹" 필 필터를 추가해 시간대 필터(오늘/이번주/전체)와 별도로 고를 수 있게 했다. Co-Authored-By: Claude Sonnet 5 --- lib/function/study_ranking_controller.dart | 11 +++++++- lib/ui/study_ranking_screen.dart | 33 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/function/study_ranking_controller.dart b/lib/function/study_ranking_controller.dart index 13c5f25..4fa7794 100644 --- a/lib/function/study_ranking_controller.dart +++ b/lib/function/study_ranking_controller.dart @@ -11,10 +11,12 @@ class StudyRankingController extends ChangeNotifier { bool _isLoading = true; String _period = 'today'; // today / week / total + String _scope = 'grade'; // grade / all List _ranking = []; bool get isLoading => _isLoading; String get period => _period; + String get scope => _scope; List get ranking => _ranking; Future init() => fetchRanking(); @@ -25,12 +27,19 @@ class StudyRankingController extends ChangeNotifier { await fetchRanking(); } + Future setScope(String scope) async { + if (_scope == scope) return; + _scope = scope; + await fetchRanking(); + } + Future fetchRanking() async { _isLoading = true; notifyListeners(); try { + final gradeParam = _scope == 'grade' ? '&grade=$grade' : ''; final response = await http.get( - Uri.parse('$baseUrl/api/study/ranking?grade=$grade&period=$_period'), + Uri.parse('$baseUrl/api/study/ranking?period=$_period$gradeParam'), ); if (response.statusCode == 200) { final data = jsonDecode(utf8.decode(response.bodyBytes)); diff --git a/lib/ui/study_ranking_screen.dart b/lib/ui/study_ranking_screen.dart index c8bc434..592f48e 100644 --- a/lib/ui/study_ranking_screen.dart +++ b/lib/ui/study_ranking_screen.dart @@ -68,10 +68,24 @@ class _StudyRankingScreenState extends State { foregroundColor: AppPalette.ink, elevation: 0, centerTitle: true, - title: TitlePill('${widget.grade}학년 공부 랭킹'), + title: TitlePill( + _controller.scope == 'grade' + ? '${widget.grade}학년 공부 랭킹' + : '전체 공부 랭킹', + ), ), body: Column( children: [ + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), + child: Row( + children: [ + _scopeChip('grade', '${widget.grade}학년'), + const SizedBox(width: 8), + _scopeChip('all', '전체랭킹'), + ], + ), + ), Padding( padding: const EdgeInsets.fromLTRB(16, 8, 16, 8), child: Row( @@ -190,4 +204,21 @@ class _StudyRankingScreenState extends State { ), ); } + + Widget _scopeChip(String value, String label) { + final bool selected = _controller.scope == value; + return Expanded( + child: ChoiceChip( + label: Center(child: Text(label, style: const TextStyle(fontSize: 13))), + selected: selected, + onSelected: (_) => _controller.setScope(value), + selectedColor: AppPalette.ink, + backgroundColor: AppPalette.mist, + labelStyle: TextStyle( + color: selected ? Colors.white : Colors.grey[600], + fontWeight: FontWeight.bold, + ), + ), + ); + } }