import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:service_api/service_api.dart'; import 'package:url_launcher/url_launcher.dart'; class SettingsScreen extends StatelessWidget { const SettingsScreen({super.key}); Future _launchHomepage() async { final Uri url = Uri.parse('https://lunaticbum.kr'); if (!await launchUrl(url, mode: LaunchMode.externalApplication)) { debugPrint('Could not launch $url'); } } // ๐Ÿ”ฝ [์‹ ๊ทœ] ๊ธฐ๋ก ์‚ญ์ œ ํ™•์ธ ๋‹ค์ด์–ผ๋กœ๊ทธ Future _confirmClearHistory(BuildContext context) async { final bool? confirmed = await showDialog( context: context, builder: (ctx) => AlertDialog( title: const Text('์ง„๋‹จ ๊ธฐ๋ก ์‚ญ์ œ'), content: const Text('์ €์žฅ๋œ ๋ชจ๋“  ๋‘๋‡Œ ์ง„๋‹จ ๊ธฐ๋ก์„ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n์‚ญ์ œ๋œ ๋ฐ์ดํ„ฐ๋Š” ๋ณต๊ตฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.'), actions: [ TextButton( onPressed: () => Navigator.pop(ctx, false), child: const Text('์ทจ์†Œ'), ), TextButton( onPressed: () => Navigator.pop(ctx, true), style: TextButton.styleFrom(foregroundColor: Colors.red), child: const Text('์‚ญ์ œ'), ), ], ), ); if (confirmed == true && context.mounted) { final identityService = context.read(); await identityService.clearAssessmentHistory(); if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('์ง„๋‹จ ๊ธฐ๋ก์ด ์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.')), ); } } } @override Widget build(BuildContext context) { final themeNotifier = context.watch(); final sessionNotifier = context.watch(); return Scaffold( appBar: AppBar(title: const Text('์„ค์ •')), body: ListView( children: [ ListTile( leading: Icon( sessionNotifier.isGuest ? Icons.person_outline : Icons.person_rounded ), title: Text( sessionNotifier.isLoading ? '๊ณ„์ • ์ •๋ณด ๋กœ๋”ฉ ์ค‘...' : (sessionNotifier.isGuest ? '๊ฒŒ์ŠคํŠธ ๊ณ„์ •' : sessionNotifier.session?.userName ?? '๋กœ๊ทธ์ธ๋จ') ), subtitle: Text( sessionNotifier.isLoading ? '' : (sessionNotifier.isGuest ? '์ง„ํ–‰ ์ƒํ™ฉ์„ ์ €์žฅํ•˜๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์„ธ์š”.' : (sessionNotifier.session?.email ?? '์†Œ์…œ ๊ณ„์ •')) ), ), if (!sessionNotifier.isLoading) if (sessionNotifier.isGuest) Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: Row( children: [ Expanded( child: OutlinedButton.icon( icon: const Icon(Icons.g_mobiledata), label: const Text('Google ๋กœ๊ทธ์ธ'), onPressed: () { sessionNotifier.login('google'); }, ), ), const SizedBox(width: 10), Expanded( child: OutlinedButton.icon( icon: const Icon(Icons.apple), label: const Text('Apple ๋กœ๊ทธ์ธ'), onPressed: () { sessionNotifier.login('apple'); }, ), ), ], ), ) else ListTile( title: const Text('๋กœ๊ทธ์•„์›ƒ', style: TextStyle(color: Colors.red)), leading: const Icon(Icons.logout, color: Colors.red), onTap: () { sessionNotifier.logout(); }, ), const Divider(), SwitchListTile( title: const Text('๋‹คํฌ ๋ชจ๋“œ'), secondary: const Icon(Icons.dark_mode_outlined), value: themeNotifier.isDarkMode, onChanged: (newValue) { themeNotifier.toggleTheme(newValue); }, ), // ๐Ÿ”ฝ [์‹ ๊ทœ] ๊ธ€์ž ํฌ๊ธฐ ์กฐ์ ˆ ์„น์…˜ ListTile( title: const Text('๊ธ€์ž ํฌ๊ธฐ'), subtitle: Text(_getScaleLabel(themeNotifier.textScaleFactor)), leading: const Icon(Icons.format_size), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 24.0), child: Column( children: [ Slider( value: themeNotifier.textScaleFactor, min: 0.85, max: 1.5, divisions: 4, label: _getScaleLabel(themeNotifier.textScaleFactor), onChanged: (value) { themeNotifier.setTextScale(value); }, ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: const [ Text("์ž‘๊ฒŒ", style: TextStyle(fontSize: 12)), Text("ํ‘œ์ค€", style: TextStyle(fontSize: 12)), Text("ํฌ๊ฒŒ", style: TextStyle(fontSize: 12)), Text("๋” ํฌ๊ฒŒ", style: TextStyle(fontSize: 12)), Text("์™„์ „ ํฌ๊ฒŒ", style: TextStyle(fontSize: 12)), ], ), const SizedBox(height: 16), ], ), ), const Divider(), // ๐Ÿ”ฝ [์‹ ๊ทœ] ๋ฐ์ดํ„ฐ ๊ด€๋ฆฌ ์„น์…˜ const Padding( padding: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0), child: Text( '๋ฐ์ดํ„ฐ ๊ด€๋ฆฌ', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), ), ListTile( leading: const Icon(Icons.delete_outline, color: Colors.red), title: const Text('์ง„๋‹จ ๊ธฐ๋ก ์‚ญ์ œ', style: TextStyle(color: Colors.red)), subtitle: const Text('์ €์žฅ๋œ ๋‘๋‡Œ ๊ฑด๊ฐ• ์ง„๋‹จ ๊ธฐ๋ก์„ ๋ชจ๋‘ ์ง€์›๋‹ˆ๋‹ค.'), onTap: () => _confirmClearHistory(context), ), const Divider(), const Padding( padding: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0), child: Text( '์•ฑ ํ…Œ๋งˆ ์ƒ‰์ƒ', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), ), ...appColors.entries.map((entry) { final String colorName = entry.key; final MaterialColor color = entry.value; return ListTile( leading: CircleAvatar( backgroundColor: color, ), title: Text(colorName), trailing: (themeNotifier.currentColor == color) ? Icon(Icons.check, color: Theme.of(context).colorScheme.secondary) : null, onTap: () { themeNotifier.setTheme(colorName); }, ); }), const Divider(), ListTile( leading: const Icon(Icons.description_outlined), title: const Text('์˜คํ”ˆ์†Œ์Šค ๋ผ์ด์„ ์Šค'), onTap: () { showLicensePage( context: context, applicationName: '์Šค๋„์ฟ  ๊ฒŒ์ž„', applicationVersion: '1.0.0', applicationIcon: const Icon(Icons.apps_rounded, size: 64), ); }, ), ListTile( leading: const Icon(Icons.info_outline), title: const Text('์•ฑ ์ •๋ณด'), onTap: () { showAboutDialog( context: context, applicationName: '์Šค๋„์ฟ  ๊ฒŒ์ž„', applicationVersion: '1.0.0', applicationIcon: const Icon(Icons.apps_rounded, size: 48), children: [ const SizedBox(height: 16), InkWell( onTap: _launchHomepage, child: Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: Text( 'ยฉ 2025 lunaticbum', textAlign: TextAlign.center, style: TextStyle( color: Theme.of(context).colorScheme.primary, decoration: TextDecoration.underline, ), ), ), ), ], ); }, ), ], ), ); } String _getScaleLabel(double scale) { if (scale <= 0.9) return "์ž‘๊ฒŒ"; if (scale <= 1.05) return "ํ‘œ์ค€"; if (scale <= 1.2) return "ํฌ๊ฒŒ"; if (scale <= 1.3) return "๋” ํฌ๊ฒŒ"; return "์™„์ „ ํฌ๊ฒŒ"; } }