settings_screen.dart 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. import 'package:flutter/material.dart';
  2. import 'package:url_launcher/url_launcher.dart';
  3. import '../l10n/app_localizations.dart';
  4. import '../utils/colors.dart';
  5. import '../utils/haptic_utils.dart';
  6. import '../utils/settings_manager.dart';
  7. import '../utils/locale_manager.dart';
  8. import '../utils/theme_manager.dart';
  9. import '../utils/theme_notifier.dart';
  10. import 'components/animated_background.dart';
  11. import 'google_play_games_widget.dart';
  12. class SettingsScreen extends StatefulWidget {
  13. const SettingsScreen({super.key});
  14. @override
  15. State<SettingsScreen> createState() => _SettingsScreenState();
  16. }
  17. class _SettingsScreenState extends State<SettingsScreen> {
  18. bool _musicEnabled = true;
  19. bool _hapticsEnabled = true;
  20. double _bgmVolume = 0.4;
  21. double _sfxVolume = 0.6;
  22. @override
  23. void initState() {
  24. super.initState();
  25. _loadSettings();
  26. }
  27. Future<void> _loadSettings() async {
  28. setState(() {
  29. _musicEnabled = SettingsManager.isMusicEnabled;
  30. _hapticsEnabled = SettingsManager.isHapticsEnabled;
  31. _bgmVolume = SettingsManager.bgmVolume;
  32. _sfxVolume = SettingsManager.sfxVolume;
  33. });
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return ThemeAwareBuilder(
  38. builder: (context, theme) {
  39. return Scaffold(
  40. backgroundColor: ZenColors.currentAppBackground,
  41. body: AnimatedBackground(
  42. child: SafeArea(
  43. child: Column(
  44. children: [
  45. // Header
  46. Padding(
  47. padding: const EdgeInsets.all(16.0),
  48. child: Row(
  49. children: [
  50. IconButton(
  51. onPressed: () => Navigator.of(context).pop(),
  52. icon: Icon(
  53. Icons.arrow_back,
  54. color: ZenColors.currentPrimaryText,
  55. size: 28,
  56. ),
  57. style: IconButton.styleFrom(
  58. backgroundColor: ZenColors.black.withValues(alpha: 0.3),
  59. shape: const CircleBorder(),
  60. ),
  61. ),
  62. const SizedBox(width: 16),
  63. Text(
  64. AppLocalizations.of(context)!.settings,
  65. style: TextStyle(
  66. color: ZenColors.currentPrimaryText,
  67. fontSize: 28,
  68. fontWeight: FontWeight.bold,
  69. letterSpacing: 1.0,
  70. ),
  71. ),
  72. ],
  73. ),
  74. ),
  75. // Settings List
  76. Expanded(
  77. child: SingleChildScrollView(
  78. padding: const EdgeInsets.symmetric(horizontal: 20.0),
  79. child: Column(
  80. children: [
  81. const SizedBox(height: 20),
  82. // Audio Section
  83. _buildSectionHeader(AppLocalizations.of(context)!.audio),
  84. _buildSettingTile(
  85. icon: Icons.music_note,
  86. title: AppLocalizations.of(context)!.backgroundMusic,
  87. subtitle: AppLocalizations.of(context)!.backgroundMusicDesc,
  88. value: _musicEnabled,
  89. onChanged: _toggleMusic,
  90. ),
  91. _buildVolumeSlider(
  92. icon: Icons.volume_up,
  93. title: AppLocalizations.of(context)!.musicVolume,
  94. value: _bgmVolume,
  95. onChanged: _setBgmVolume,
  96. ),
  97. const SizedBox(height: 10),
  98. _buildVolumeSlider(
  99. icon: Icons.volume_up,
  100. title: AppLocalizations.of(context)!.soundEffectsVolume,
  101. value: _sfxVolume,
  102. onChanged: _setSfxVolume,
  103. ),
  104. const SizedBox(height: 30),
  105. // Feedback Section
  106. _buildSectionHeader(AppLocalizations.of(context)!.feedback),
  107. _buildSettingTile(
  108. icon: Icons.vibration,
  109. title: AppLocalizations.of(context)!.hapticFeedback,
  110. subtitle: AppLocalizations.of(context)!.hapticFeedbackDesc,
  111. value: _hapticsEnabled,
  112. onChanged: _toggleHaptics,
  113. ),
  114. const SizedBox(height: 30),
  115. // Appearance Section
  116. _buildSectionHeader(AppLocalizations.of(context)!.appearance),
  117. _buildThemeTile(),
  118. const SizedBox(height: 30),
  119. // Language Section
  120. _buildSectionHeader(AppLocalizations.of(context)!.language),
  121. _buildLanguageTile(),
  122. const SizedBox(height: 30),
  123. // Tutorial Section
  124. _buildSectionHeader(AppLocalizations.of(context)!.help),
  125. _buildActionTile(
  126. icon: Icons.help_outline,
  127. title: AppLocalizations.of(context)!.showTutorial,
  128. subtitle: AppLocalizations.of(context)!.showTutorialDesc,
  129. onTap: _showTutorial,
  130. ),
  131. const SizedBox(height: 30),
  132. // Google Play Games Section
  133. _buildSectionHeader(AppLocalizations.of(context)!.googlePlayGames),
  134. const GooglePlayGamesWidget(),
  135. const SizedBox(height: 30),
  136. // Support Section
  137. _buildSectionHeader(AppLocalizations.of(context)!.supportZenTap),
  138. _buildDonationTile(),
  139. const SizedBox(height: 30),
  140. // About Section
  141. Padding(
  142. padding: const EdgeInsets.only(bottom: 20),
  143. child: Column(
  144. children: [
  145. Text(
  146. 'ZenTap v1.0.4',
  147. style: TextStyle(
  148. color: ZenColors.currentMutedText,
  149. fontSize: 14,
  150. ),
  151. ),
  152. const SizedBox(height: 8),
  153. Text(
  154. AppLocalizations.of(context)!.stressReliefGame,
  155. style: TextStyle(
  156. color: ZenColors.currentMutedText,
  157. fontSize: 12,
  158. fontStyle: FontStyle.italic,
  159. ),
  160. ),
  161. ],
  162. ),
  163. ),
  164. ],
  165. ),
  166. ),
  167. ),
  168. ],
  169. ),
  170. ),
  171. ),
  172. );
  173. },
  174. );
  175. }
  176. Widget _buildSectionHeader(String title) {
  177. return Align(
  178. alignment: Alignment.centerLeft,
  179. child: Text(
  180. title,
  181. style: TextStyle(
  182. color: ZenColors.currentSecondaryText,
  183. fontSize: 16,
  184. fontWeight: FontWeight.w600,
  185. letterSpacing: 0.5,
  186. ),
  187. ),
  188. );
  189. }
  190. Widget _buildSettingTile({
  191. required IconData icon,
  192. required String title,
  193. required String subtitle,
  194. required bool value,
  195. required ValueChanged<bool> onChanged,
  196. }) {
  197. return Container(
  198. margin: const EdgeInsets.only(top: 12),
  199. padding: const EdgeInsets.all(16),
  200. decoration: BoxDecoration(
  201. color: ZenColors.currentUiElements.withValues(alpha: 0.3),
  202. borderRadius: BorderRadius.circular(12),
  203. border: Border.all(
  204. color: ZenColors.currentUiElements.withValues(alpha: 0.2),
  205. width: 1,
  206. ),
  207. ),
  208. child: Row(
  209. children: [
  210. Icon(
  211. icon,
  212. color: ZenColors.currentPrimaryText,
  213. size: 24,
  214. ),
  215. const SizedBox(width: 16),
  216. Expanded(
  217. child: Column(
  218. crossAxisAlignment: CrossAxisAlignment.start,
  219. children: [
  220. Text(
  221. title,
  222. style: TextStyle(
  223. color: ZenColors.currentPrimaryText,
  224. fontSize: 16,
  225. fontWeight: FontWeight.w500,
  226. ),
  227. ),
  228. const SizedBox(height: 2),
  229. Text(
  230. subtitle,
  231. style: TextStyle(
  232. color: ZenColors.currentSecondaryText,
  233. fontSize: 13,
  234. ),
  235. ),
  236. ],
  237. ),
  238. ),
  239. Switch(
  240. value: value,
  241. onChanged: onChanged,
  242. activeColor: ZenColors.currentButtonBackground,
  243. activeTrackColor: ZenColors.currentButtonBackground.withValues(alpha: 0.3),
  244. inactiveThumbColor: ZenColors.currentMutedText,
  245. inactiveTrackColor: ZenColors.currentMutedText.withValues(alpha: 0.2),
  246. ),
  247. ],
  248. ),
  249. );
  250. }
  251. Widget _buildActionTile({
  252. required IconData icon,
  253. required String title,
  254. required String subtitle,
  255. required VoidCallback onTap,
  256. }) {
  257. return Container(
  258. margin: const EdgeInsets.only(top: 12),
  259. child: Material(
  260. color: ZenColors.currentUiElements.withValues(alpha: 0.3),
  261. borderRadius: BorderRadius.circular(12),
  262. child: InkWell(
  263. onTap: onTap,
  264. borderRadius: BorderRadius.circular(12),
  265. child: Container(
  266. padding: const EdgeInsets.all(16),
  267. decoration: BoxDecoration(
  268. borderRadius: BorderRadius.circular(12),
  269. border: Border.all(
  270. color: ZenColors.currentUiElements.withValues(alpha: 0.2),
  271. width: 1,
  272. ),
  273. ),
  274. child: Row(
  275. children: [
  276. Icon(
  277. icon,
  278. color: ZenColors.currentPrimaryText,
  279. size: 24,
  280. ),
  281. const SizedBox(width: 16),
  282. Expanded(
  283. child: Column(
  284. crossAxisAlignment: CrossAxisAlignment.start,
  285. children: [
  286. Text(
  287. title,
  288. style: TextStyle(
  289. color: ZenColors.currentPrimaryText,
  290. fontSize: 16,
  291. fontWeight: FontWeight.w500,
  292. ),
  293. ),
  294. const SizedBox(height: 2),
  295. Text(
  296. subtitle,
  297. style: TextStyle(
  298. color: ZenColors.currentSecondaryText,
  299. fontSize: 13,
  300. ),
  301. ),
  302. ],
  303. ),
  304. ),
  305. Icon(
  306. Icons.arrow_forward_ios,
  307. color: ZenColors.currentMutedText,
  308. size: 16,
  309. ),
  310. ],
  311. ),
  312. ),
  313. ),
  314. ),
  315. );
  316. }
  317. Widget _buildVolumeSlider({
  318. required IconData icon,
  319. required String title,
  320. required double value,
  321. required ValueChanged<double> onChanged,
  322. }) {
  323. return Container(
  324. margin: const EdgeInsets.only(top: 8),
  325. padding: const EdgeInsets.all(16),
  326. decoration: BoxDecoration(
  327. color: ZenColors.currentUiElements.withValues(alpha: 0.3),
  328. borderRadius: BorderRadius.circular(12),
  329. border: Border.all(
  330. color: ZenColors.currentUiElements.withValues(alpha: 0.2),
  331. width: 1,
  332. ),
  333. ),
  334. child: Row(
  335. children: [
  336. Icon(
  337. icon,
  338. color: ZenColors.currentPrimaryText,
  339. size: 24,
  340. ),
  341. const SizedBox(width: 16),
  342. Expanded(
  343. child: Column(
  344. crossAxisAlignment: CrossAxisAlignment.start,
  345. children: [
  346. Text(
  347. title,
  348. style: TextStyle(
  349. color: ZenColors.currentPrimaryText,
  350. fontSize: 16,
  351. fontWeight: FontWeight.w500,
  352. ),
  353. ),
  354. const SizedBox(height: 8),
  355. Slider(
  356. value: value,
  357. onChanged: onChanged,
  358. min: 0.0,
  359. max: 1.0,
  360. divisions: 10,
  361. label: '${(value * 100).round()}%',
  362. activeColor: ZenColors.currentButtonBackground,
  363. inactiveColor: ZenColors.currentMutedText.withValues(alpha: 0.2),
  364. ),
  365. ],
  366. ),
  367. ),
  368. ],
  369. ),
  370. );
  371. }
  372. Widget _buildThemeTile() {
  373. final currentTheme = ThemeManager.currentTheme;
  374. final currentThemeName = _getLocalizedThemeName(currentTheme);
  375. return Container(
  376. margin: const EdgeInsets.only(top: 12),
  377. child: Material(
  378. color: ZenColors.currentUiElements.withValues(alpha: 0.3),
  379. borderRadius: BorderRadius.circular(12),
  380. child: InkWell(
  381. onTap: _showThemeDialog,
  382. borderRadius: BorderRadius.circular(12),
  383. child: Container(
  384. padding: const EdgeInsets.all(16),
  385. decoration: BoxDecoration(
  386. borderRadius: BorderRadius.circular(12),
  387. border: Border.all(
  388. color: ZenColors.currentUiElements.withValues(alpha: 0.2),
  389. width: 1,
  390. ),
  391. ),
  392. child: Row(
  393. children: [
  394. Icon(
  395. ThemeManager.getThemeIcon(currentTheme),
  396. color: ZenColors.currentPrimaryText,
  397. size: 24,
  398. ),
  399. const SizedBox(width: 16),
  400. Expanded(
  401. child: Column(
  402. crossAxisAlignment: CrossAxisAlignment.start,
  403. children: [
  404. Text(
  405. AppLocalizations.of(context)!.colorTheme,
  406. style: TextStyle(
  407. color: ZenColors.currentPrimaryText,
  408. fontSize: 16,
  409. fontWeight: FontWeight.w500,
  410. ),
  411. ),
  412. const SizedBox(height: 2),
  413. Text(
  414. currentThemeName,
  415. style: TextStyle(
  416. color: ZenColors.currentSecondaryText,
  417. fontSize: 13,
  418. ),
  419. ),
  420. ],
  421. ),
  422. ),
  423. Icon(
  424. Icons.arrow_forward_ios,
  425. color: ZenColors.currentMutedText,
  426. size: 16,
  427. ),
  428. ],
  429. ),
  430. ),
  431. ),
  432. ),
  433. );
  434. }
  435. Widget _buildLanguageTile() {
  436. final currentLocale = LocaleManager.currentLocale;
  437. final currentLanguageName = LocaleManager.getLocaleDisplayName(currentLocale);
  438. return Container(
  439. margin: const EdgeInsets.only(top: 12),
  440. child: Material(
  441. color: ZenColors.currentUiElements.withValues(alpha: 0.3),
  442. borderRadius: BorderRadius.circular(12),
  443. child: InkWell(
  444. onTap: _showLanguageDialog,
  445. borderRadius: BorderRadius.circular(12),
  446. child: Container(
  447. padding: const EdgeInsets.all(16),
  448. decoration: BoxDecoration(
  449. borderRadius: BorderRadius.circular(12),
  450. border: Border.all(
  451. color: ZenColors.currentUiElements.withValues(alpha: 0.2),
  452. width: 1,
  453. ),
  454. ),
  455. child: Row(
  456. children: [
  457. Icon(
  458. Icons.language,
  459. color: ZenColors.currentPrimaryText,
  460. size: 24,
  461. ),
  462. const SizedBox(width: 16),
  463. Expanded(
  464. child: Column(
  465. crossAxisAlignment: CrossAxisAlignment.start,
  466. children: [
  467. Text(
  468. AppLocalizations.of(context)!.language,
  469. style: TextStyle(
  470. color: ZenColors.currentPrimaryText,
  471. fontSize: 16,
  472. fontWeight: FontWeight.w500,
  473. ),
  474. ),
  475. const SizedBox(height: 2),
  476. Text(
  477. currentLanguageName,
  478. style: TextStyle(
  479. color: ZenColors.currentSecondaryText,
  480. fontSize: 13,
  481. ),
  482. ),
  483. ],
  484. ),
  485. ),
  486. Icon(
  487. Icons.arrow_forward_ios,
  488. color: ZenColors.currentMutedText,
  489. size: 16,
  490. ),
  491. ],
  492. ),
  493. ),
  494. ),
  495. ),
  496. );
  497. }
  498. Widget _buildDonationTile() {
  499. return _buildActionTile(
  500. icon: Icons.favorite,
  501. title: AppLocalizations.of(context)!.supportDevelopment,
  502. subtitle: AppLocalizations.of(context)!.supportDevelopmentDesc,
  503. onTap: _showDonationDialog,
  504. );
  505. }
  506. // Event Handlers
  507. Future<void> _toggleMusic(bool value) async {
  508. setState(() {
  509. _musicEnabled = value;
  510. });
  511. await SettingsManager.setMusicEnabled(value);
  512. if (_hapticsEnabled) {
  513. await HapticUtils.vibrate(duration: 50);
  514. }
  515. }
  516. Future<void> _setBgmVolume(double value) async {
  517. setState(() {
  518. _bgmVolume = value;
  519. });
  520. await SettingsManager.setBgmVolume(value);
  521. SettingsManager.applyBgmVolume();
  522. }
  523. Future<void> _setSfxVolume(double value) async {
  524. setState(() {
  525. _sfxVolume = value;
  526. });
  527. await SettingsManager.setSfxVolume(value);
  528. SettingsManager.applySfxVolume();
  529. }
  530. Future<void> _toggleHaptics(bool value) async {
  531. setState(() {
  532. _hapticsEnabled = value;
  533. });
  534. await SettingsManager.setHapticsEnabled(value);
  535. // Give immediate feedback if enabling haptics
  536. if (value) {
  537. await HapticUtils.vibrate(duration: 100);
  538. }
  539. }
  540. void _showTutorial() {
  541. if (_hapticsEnabled) {
  542. HapticUtils.vibrate(duration: 50);
  543. }
  544. showDialog(
  545. context: context,
  546. builder: (context) => _buildTutorialDialog(),
  547. );
  548. }
  549. void _showDonationDialog() {
  550. if (_hapticsEnabled) {
  551. HapticUtils.vibrate(duration: 50);
  552. }
  553. showDialog(
  554. context: context,
  555. builder: (context) => _buildDonationDialog(),
  556. );
  557. }
  558. void _showLanguageDialog() {
  559. if (_hapticsEnabled) {
  560. HapticUtils.vibrate(duration: 50);
  561. }
  562. showDialog(
  563. context: context,
  564. builder: (context) => _buildLanguageDialog(),
  565. );
  566. }
  567. void _showThemeDialog() {
  568. if (_hapticsEnabled) {
  569. HapticUtils.vibrate(duration: 50);
  570. }
  571. showDialog(
  572. context: context,
  573. builder: (context) => _buildThemeDialog(),
  574. );
  575. }
  576. // Dialog Builders
  577. Widget _buildTutorialDialog() {
  578. return AlertDialog(
  579. backgroundColor: ZenColors.currentUiElements,
  580. shape: RoundedRectangleBorder(
  581. borderRadius: BorderRadius.circular(20),
  582. ),
  583. title: Text(
  584. AppLocalizations.of(context)!.howToUseZenTap,
  585. style: TextStyle(
  586. color: ZenColors.currentPrimaryText,
  587. fontSize: 22,
  588. fontWeight: FontWeight.bold,
  589. ),
  590. ),
  591. content: Column(
  592. mainAxisSize: MainAxisSize.min,
  593. crossAxisAlignment: CrossAxisAlignment.start,
  594. children: [
  595. _buildTutorialStep(
  596. icon: Icons.touch_app,
  597. text: AppLocalizations.of(context)!.tapToPopBubbles,
  598. ),
  599. const SizedBox(height: 16),
  600. _buildTutorialStep(
  601. icon: Icons.stars,
  602. text: AppLocalizations.of(context)!.earnRelaxationPoints,
  603. ),
  604. const SizedBox(height: 16),
  605. _buildTutorialStep(
  606. icon: Icons.self_improvement,
  607. text: AppLocalizations.of(context)!.chooseZenMode,
  608. ),
  609. const SizedBox(height: 16),
  610. _buildTutorialStep(
  611. icon: Icons.pause,
  612. text: AppLocalizations.of(context)!.tapPauseAnytime,
  613. ),
  614. ],
  615. ),
  616. actions: [
  617. ElevatedButton(
  618. onPressed: () => Navigator.of(context).pop(),
  619. style: ElevatedButton.styleFrom(
  620. backgroundColor: ZenColors.currentButtonBackground,
  621. foregroundColor: ZenColors.currentButtonText,
  622. shape: RoundedRectangleBorder(
  623. borderRadius: BorderRadius.circular(12),
  624. ),
  625. ),
  626. child: Text(AppLocalizations.of(context)!.gotIt),
  627. ),
  628. ],
  629. );
  630. }
  631. Widget _buildTutorialStep({
  632. required IconData icon,
  633. required String text,
  634. }) {
  635. return Row(
  636. children: [
  637. Icon(
  638. icon,
  639. color: ZenColors.currentButtonBackground,
  640. size: 20,
  641. ),
  642. const SizedBox(width: 12),
  643. Expanded(
  644. child: Text(
  645. text,
  646. style: TextStyle(
  647. color: ZenColors.currentSecondaryText,
  648. fontSize: 14,
  649. ),
  650. ),
  651. ),
  652. ],
  653. );
  654. }
  655. Widget _buildLanguageDialog() {
  656. final currentLocale = LocaleManager.currentLocale;
  657. return AlertDialog(
  658. backgroundColor: ZenColors.currentUiElements,
  659. shape: RoundedRectangleBorder(
  660. borderRadius: BorderRadius.circular(20),
  661. ),
  662. title: Text(
  663. AppLocalizations.of(context)!.selectLanguage,
  664. style: TextStyle(
  665. color: ZenColors.currentPrimaryText,
  666. fontSize: 22,
  667. fontWeight: FontWeight.bold,
  668. ),
  669. ),
  670. content: Column(
  671. mainAxisSize: MainAxisSize.min,
  672. children: LocaleManager.supportedLocales.map((locale) {
  673. final isSelected = locale.languageCode == currentLocale.languageCode;
  674. final languageName = LocaleManager.getLocaleDisplayName(locale);
  675. return Container(
  676. margin: const EdgeInsets.only(bottom: 8),
  677. child: Material(
  678. color: isSelected
  679. ? ZenColors.currentButtonBackground.withValues(alpha: 0.1)
  680. : Colors.transparent,
  681. borderRadius: BorderRadius.circular(12),
  682. child: InkWell(
  683. onTap: () => _selectLanguage(locale),
  684. borderRadius: BorderRadius.circular(12),
  685. child: Container(
  686. padding: const EdgeInsets.all(12),
  687. decoration: BoxDecoration(
  688. borderRadius: BorderRadius.circular(12),
  689. border: Border.all(
  690. color: isSelected
  691. ? ZenColors.currentButtonBackground.withValues(alpha: 0.3)
  692. : ZenColors.currentUiElements.withValues(alpha: 0.2),
  693. width: 1,
  694. ),
  695. ),
  696. child: Row(
  697. children: [
  698. Expanded(
  699. child: Text(
  700. languageName,
  701. style: TextStyle(
  702. color: isSelected ? ZenColors.currentButtonBackground : ZenColors.currentPrimaryText,
  703. fontSize: 16,
  704. fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
  705. ),
  706. ),
  707. ),
  708. if (isSelected)
  709. Icon(
  710. Icons.check,
  711. color: ZenColors.currentButtonBackground,
  712. size: 20,
  713. ),
  714. ],
  715. ),
  716. ),
  717. ),
  718. ),
  719. );
  720. }).toList(),
  721. ),
  722. actions: [
  723. TextButton(
  724. onPressed: () => Navigator.of(context).pop(),
  725. child: Text(
  726. AppLocalizations.of(context)!.cancel,
  727. style: TextStyle(
  728. color: ZenColors.currentMutedText,
  729. ),
  730. ),
  731. ),
  732. ],
  733. );
  734. }
  735. Widget _buildThemeDialog() {
  736. final currentTheme = ThemeManager.currentTheme;
  737. return AlertDialog(
  738. backgroundColor: ZenColors.currentUiElements,
  739. shape: RoundedRectangleBorder(
  740. borderRadius: BorderRadius.circular(20),
  741. ),
  742. title: Text(
  743. AppLocalizations.of(context)!.selectTheme,
  744. style: TextStyle(
  745. color: ZenColors.currentPrimaryText,
  746. fontSize: 22,
  747. fontWeight: FontWeight.bold,
  748. ),
  749. ),
  750. content: Column(
  751. mainAxisSize: MainAxisSize.min,
  752. children: SeasonalTheme.values.map((theme) {
  753. final isSelected = theme == currentTheme;
  754. final themeName = _getLocalizedThemeName(theme);
  755. final themeIcon = ThemeManager.getThemeIcon(theme);
  756. return Container(
  757. margin: const EdgeInsets.only(bottom: 8),
  758. child: Material(
  759. color: isSelected
  760. ? ZenColors.currentButtonBackground.withValues(alpha: 0.1)
  761. : Colors.transparent,
  762. borderRadius: BorderRadius.circular(12),
  763. child: InkWell(
  764. onTap: () => _selectTheme(theme),
  765. borderRadius: BorderRadius.circular(12),
  766. child: Container(
  767. padding: const EdgeInsets.all(12),
  768. decoration: BoxDecoration(
  769. borderRadius: BorderRadius.circular(12),
  770. border: Border.all(
  771. color: isSelected
  772. ? ZenColors.currentButtonBackground.withValues(alpha: 0.3)
  773. : ZenColors.currentUiElements.withValues(alpha: 0.2),
  774. width: 1,
  775. ),
  776. ),
  777. child: Row(
  778. children: [
  779. Icon(
  780. themeIcon,
  781. color: isSelected ? ZenColors.currentButtonBackground : ZenColors.currentPrimaryText,
  782. size: 20,
  783. ),
  784. const SizedBox(width: 12),
  785. Expanded(
  786. child: Text(
  787. themeName,
  788. style: TextStyle(
  789. color: isSelected ? ZenColors.currentButtonBackground : ZenColors.currentPrimaryText,
  790. fontSize: 16,
  791. fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
  792. ),
  793. ),
  794. ),
  795. if (isSelected)
  796. Icon(
  797. Icons.check,
  798. color: ZenColors.currentButtonBackground,
  799. size: 20,
  800. ),
  801. ],
  802. ),
  803. ),
  804. ),
  805. ),
  806. );
  807. }).toList(),
  808. ),
  809. actions: [
  810. TextButton(
  811. onPressed: () => Navigator.of(context).pop(),
  812. child: Text(
  813. AppLocalizations.of(context)!.cancel,
  814. style: TextStyle(
  815. color: ZenColors.currentMutedText,
  816. ),
  817. ),
  818. ),
  819. ],
  820. );
  821. }
  822. Widget _buildDonationDialog() {
  823. return AlertDialog(
  824. backgroundColor: ZenColors.currentUiElements,
  825. shape: RoundedRectangleBorder(
  826. borderRadius: BorderRadius.circular(20),
  827. ),
  828. title: Row(
  829. children: [
  830. Icon(
  831. Icons.favorite,
  832. color: ZenColors.red,
  833. size: 24,
  834. ),
  835. const SizedBox(width: 12),
  836. Text(
  837. AppLocalizations.of(context)!.supportZenTapTitle,
  838. style: TextStyle(
  839. color: ZenColors.currentPrimaryText,
  840. fontSize: 22,
  841. fontWeight: FontWeight.bold,
  842. ),
  843. ),
  844. ],
  845. ),
  846. content: Column(
  847. mainAxisSize: MainAxisSize.min,
  848. crossAxisAlignment: CrossAxisAlignment.start,
  849. children: [
  850. Text(
  851. AppLocalizations.of(context)!.supportMessage,
  852. style: TextStyle(
  853. color: ZenColors.currentSecondaryText,
  854. fontSize: 14,
  855. height: 1.4,
  856. ),
  857. ),
  858. const SizedBox(height: 20),
  859. // Ko-fi Button
  860. _buildDonationButton(
  861. icon: Icons.coffee,
  862. title: AppLocalizations.of(context)!.buyMeACoffee,
  863. subtitle: AppLocalizations.of(context)!.kofiOneTime,
  864. color: const Color(0xFF13C3FF),
  865. onTap: () => _openDonationLink('https://ko-fi.com/fsociety_hu'),
  866. ),
  867. const SizedBox(height: 12),
  868. // PayPal Button
  869. _buildDonationButton(
  870. icon: Icons.payment,
  871. title: AppLocalizations.of(context)!.paypalDonation,
  872. subtitle: AppLocalizations.of(context)!.directDonation,
  873. color: const Color(0xFF0070BA),
  874. onTap: () => _openDonationLink('https://paypal.me/fsocietyhu'),
  875. ),
  876. const SizedBox(height: 12),
  877. // GitHub Sponsors Button
  878. _buildDonationButton(
  879. icon: Icons.code,
  880. title: AppLocalizations.of(context)!.githubSponsors,
  881. subtitle: AppLocalizations.of(context)!.monthlySupport,
  882. color: const Color(0xFFEA4AAA),
  883. onTap: () => _openDonationLink('https://github.com/sponsors/fszontagh'),
  884. ),
  885. const SizedBox(height: 16),
  886. Text(
  887. AppLocalizations.of(context)!.thankYouMessage,
  888. style: TextStyle(
  889. color: ZenColors.currentSecondaryText,
  890. fontSize: 12,
  891. fontStyle: FontStyle.italic,
  892. ),
  893. textAlign: TextAlign.center,
  894. ),
  895. ],
  896. ),
  897. actions: [
  898. TextButton(
  899. onPressed: () => Navigator.of(context).pop(),
  900. child: Text(
  901. AppLocalizations.of(context)!.maybeLater,
  902. style: TextStyle(
  903. color: ZenColors.currentMutedText,
  904. ),
  905. ),
  906. ),
  907. ],
  908. );
  909. }
  910. Widget _buildDonationButton({
  911. required IconData icon,
  912. required String title,
  913. required String subtitle,
  914. required Color color,
  915. required VoidCallback onTap,
  916. }) {
  917. return Material(
  918. color: color.withValues(alpha: 0.1),
  919. borderRadius: BorderRadius.circular(12),
  920. child: InkWell(
  921. onTap: onTap,
  922. borderRadius: BorderRadius.circular(12),
  923. child: Container(
  924. padding: const EdgeInsets.all(12),
  925. decoration: BoxDecoration(
  926. borderRadius: BorderRadius.circular(12),
  927. border: Border.all(
  928. color: color.withValues(alpha: 0.3),
  929. width: 1,
  930. ),
  931. ),
  932. child: Row(
  933. children: [
  934. Icon(
  935. icon,
  936. color: color,
  937. size: 20,
  938. ),
  939. const SizedBox(width: 12),
  940. Expanded(
  941. child: Column(
  942. crossAxisAlignment: CrossAxisAlignment.start,
  943. children: [
  944. Text(
  945. title,
  946. style: TextStyle(
  947. color: ZenColors.currentPrimaryText,
  948. fontSize: 14,
  949. fontWeight: FontWeight.w500,
  950. ),
  951. ),
  952. Text(
  953. subtitle,
  954. style: TextStyle(
  955. color: ZenColors.currentSecondaryText,
  956. fontSize: 12,
  957. ),
  958. ),
  959. ],
  960. ),
  961. ),
  962. Icon(
  963. Icons.open_in_new,
  964. color: color,
  965. size: 16,
  966. ),
  967. ],
  968. ),
  969. ),
  970. ),
  971. );
  972. }
  973. // Helper Methods
  974. String _getLocalizedThemeName(SeasonalTheme theme) {
  975. final localizations = AppLocalizations.of(context)!;
  976. switch (theme) {
  977. case SeasonalTheme.default_:
  978. return localizations.defaultTheme;
  979. case SeasonalTheme.spring:
  980. return localizations.springTheme;
  981. case SeasonalTheme.summer:
  982. return localizations.summerTheme;
  983. case SeasonalTheme.autumn:
  984. return localizations.autumnTheme;
  985. case SeasonalTheme.winter:
  986. return localizations.winterTheme;
  987. }
  988. }
  989. Future<void> _selectLanguage(Locale locale) async {
  990. if (_hapticsEnabled) {
  991. HapticUtils.vibrate(duration: 30);
  992. }
  993. await LocaleManager.setLocale(locale);
  994. if (mounted) {
  995. Navigator.of(context).pop(); // Close language dialog
  996. setState(() {}); // Refresh the settings screen to show new language
  997. }
  998. }
  999. Future<void> _selectTheme(SeasonalTheme theme) async {
  1000. if (_hapticsEnabled) {
  1001. HapticUtils.vibrate(duration: 30);
  1002. }
  1003. await SettingsManager.setSelectedTheme(theme);
  1004. if (mounted) {
  1005. Navigator.of(context).pop(); // Close theme dialog
  1006. setState(() {}); // Refresh the settings screen to show new theme
  1007. }
  1008. }
  1009. Future<void> _openDonationLink(String url) async {
  1010. if (_hapticsEnabled) {
  1011. HapticUtils.vibrate(duration: 30);
  1012. }
  1013. try {
  1014. final Uri uri = Uri.parse(url);
  1015. if (await canLaunchUrl(uri)) {
  1016. await launchUrl(uri, mode: LaunchMode.externalApplication);
  1017. Navigator.of(context).pop(); // Close dialog after opening link
  1018. } else {
  1019. // Show error if URL can't be launched
  1020. if (mounted) {
  1021. ScaffoldMessenger.of(context).showSnackBar(
  1022. SnackBar(
  1023. content: Text(AppLocalizations.of(context)!.couldNotOpenDonationLink),
  1024. backgroundColor: ZenColors.currentMutedText,
  1025. behavior: SnackBarBehavior.floating,
  1026. ),
  1027. );
  1028. }
  1029. }
  1030. } catch (e) {
  1031. // Show error on exception
  1032. if (mounted) {
  1033. ScaffoldMessenger.of(context).showSnackBar(
  1034. SnackBar(
  1035. content: Text(AppLocalizations.of(context)!.errorOpeningDonationLink),
  1036. backgroundColor: ZenColors.currentMutedText,
  1037. behavior: SnackBarBehavior.floating,
  1038. ),
  1039. );
  1040. }
  1041. }
  1042. }
  1043. }