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