| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189 |
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:url_launcher/url_launcher.dart';
- import '../l10n/app_localizations.dart';
- import '../utils/colors.dart';
- import '../utils/haptic_utils.dart';
- import '../utils/settings_manager.dart';
- import '../utils/locale_manager.dart';
- import '../utils/theme_manager.dart';
- import '../utils/theme_notifier.dart';
- import 'components/animated_background.dart';
- import 'google_play_games_widget.dart';
- import '../game/audio/audio_manager.dart';
- class SettingsScreen extends StatefulWidget {
- const SettingsScreen({super.key});
- @override
- State<SettingsScreen> createState() => _SettingsScreenState();
- }
- class _SettingsScreenState extends State<SettingsScreen> {
- bool _musicEnabled = true;
- bool _hapticsEnabled = true;
- double _bgmVolume = 0.4;
- double _sfxVolume = 0.6;
- @override
- void initState() {
- super.initState();
- _loadSettings();
- }
- Future<void> _loadSettings() async {
- setState(() {
- _musicEnabled = SettingsManager.isMusicEnabled;
- _hapticsEnabled = SettingsManager.isHapticsEnabled;
- _bgmVolume = SettingsManager.bgmVolume;
- _sfxVolume = SettingsManager.sfxVolume;
- });
- }
- @override
- Widget build(BuildContext context) {
- return ThemeAwareBuilder(
- builder: (context, theme) {
- return Scaffold(
- backgroundColor: ZenColors.currentAppBackground,
- body: AnimatedBackground(
- child: SafeArea(
- child: Column(
- children: [
- // Header
- Padding(
- padding: const EdgeInsets.all(16.0),
- child: Row(
- children: [
- IconButton(
- onPressed: () => Navigator.of(context).pop(),
- icon: Icon(
- Icons.arrow_back,
- color: ZenColors.currentPrimaryText,
- size: 28,
- ),
- style: IconButton.styleFrom(
- backgroundColor: ZenColors.black.withValues(
- alpha: 0.3,
- ),
- shape: const CircleBorder(),
- ),
- ),
- const SizedBox(width: 16),
- Text(
- AppLocalizations.of(context)!.settings,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 28,
- fontWeight: FontWeight.bold,
- letterSpacing: 1.0,
- ),
- ),
- ],
- ),
- ),
- // Settings List
- Expanded(
- child: SingleChildScrollView(
- padding: const EdgeInsets.symmetric(horizontal: 20.0),
- child: Column(
- children: [
- const SizedBox(height: 20),
- // Audio Section
- _buildSectionHeader(
- AppLocalizations.of(context)!.audio,
- ),
- _buildSettingTile(
- icon: Icons.music_note,
- title:
- AppLocalizations.of(context)!.backgroundMusic,
- subtitle:
- AppLocalizations.of(
- context,
- )!.backgroundMusicDesc,
- value: _musicEnabled,
- onChanged: _toggleMusic,
- ),
- _buildVolumeSlider(
- icon: Icons.volume_up,
- title: AppLocalizations.of(context)!.musicVolume,
- value: _bgmVolume,
- onChanged: _setBgmVolume,
- ),
- const SizedBox(height: 10),
- _buildVolumeSlider(
- icon: Icons.volume_up,
- title:
- AppLocalizations.of(
- context,
- )!.soundEffectsVolume,
- value: _sfxVolume,
- onChanged: _setSfxVolume,
- ),
- const SizedBox(height: 30),
- // Feedback Section
- _buildSectionHeader(
- AppLocalizations.of(context)!.feedback,
- ),
- _buildSettingTile(
- icon: Icons.vibration,
- title: AppLocalizations.of(context)!.hapticFeedback,
- subtitle:
- AppLocalizations.of(
- context,
- )!.hapticFeedbackDesc,
- value: _hapticsEnabled,
- onChanged: _toggleHaptics,
- ),
- const SizedBox(height: 30),
- // Appearance Section
- _buildSectionHeader(
- AppLocalizations.of(context)!.appearance,
- ),
- _buildThemeTile(),
- const SizedBox(height: 30),
- // Language Section
- _buildSectionHeader(
- AppLocalizations.of(context)!.language,
- ),
- _buildLanguageTile(),
- const SizedBox(height: 30),
- // Tutorial Section
- _buildSectionHeader(
- AppLocalizations.of(context)!.help,
- ),
- _buildActionTile(
- icon: Icons.help_outline,
- title: AppLocalizations.of(context)!.showTutorial,
- subtitle:
- AppLocalizations.of(context)!.showTutorialDesc,
- onTap: _showTutorial,
- ),
- const SizedBox(height: 30),
- // Google Play Games Section
- _buildSectionHeader(
- AppLocalizations.of(context)!.googlePlayGames,
- ),
- const GooglePlayGamesWidget(),
- const SizedBox(height: 30),
- // Support Section - Hidden as requested
- // _buildSectionHeader(
- // AppLocalizations.of(context)!.supportZenTap,
- // ),
- // _buildDonationTile(),
- // const SizedBox(height: 30),
- // About Section
- Padding(
- padding: const EdgeInsets.only(bottom: 20),
- child: Column(
- children: [
- Text(
- 'ZenTap v1.0.5',
- style: TextStyle(
- color: ZenColors.currentMutedText,
- fontSize: 14,
- ),
- ),
- const SizedBox(height: 8),
- Text(
- AppLocalizations.of(
- context,
- )!.stressReliefGame,
- style: TextStyle(
- color: ZenColors.currentMutedText,
- fontSize: 12,
- fontStyle: FontStyle.italic,
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- );
- },
- );
- }
- Widget _buildSectionHeader(String title) {
- return Align(
- alignment: Alignment.centerLeft,
- child: Text(
- title,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 16,
- fontWeight: FontWeight.w600,
- letterSpacing: 0.5,
- ),
- ),
- );
- }
- Widget _buildSettingTile({
- required IconData icon,
- required String title,
- required String subtitle,
- required bool value,
- required ValueChanged<bool> onChanged,
- }) {
- return Container(
- margin: const EdgeInsets.only(top: 12),
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- color: ZenColors.currentUiElements.withValues(alpha: 0.3),
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color: ZenColors.currentUiElements.withValues(alpha: 0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Icon(icon, color: ZenColors.currentPrimaryText, size: 24),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 16,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(height: 2),
- Text(
- subtitle,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 13,
- ),
- ),
- ],
- ),
- ),
- Switch(
- value: value,
- onChanged: onChanged,
- activeColor: ZenColors.currentButtonBackground,
- activeTrackColor: ZenColors.currentButtonBackground.withValues(
- alpha: 0.3,
- ),
- inactiveThumbColor: ZenColors.currentMutedText,
- inactiveTrackColor: ZenColors.currentMutedText.withValues(
- alpha: 0.2,
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildActionTile({
- required IconData icon,
- required String title,
- required String subtitle,
- required VoidCallback onTap,
- }) {
- return Container(
- margin: const EdgeInsets.only(top: 12),
- child: Material(
- color: ZenColors.currentUiElements.withValues(alpha: 0.3),
- borderRadius: BorderRadius.circular(12),
- child: InkWell(
- onTap: onTap,
- borderRadius: BorderRadius.circular(12),
- child: Container(
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color: ZenColors.currentUiElements.withValues(alpha: 0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Icon(icon, color: ZenColors.currentPrimaryText, size: 24),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 16,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(height: 2),
- Text(
- subtitle,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 13,
- ),
- ),
- ],
- ),
- ),
- Icon(
- Icons.arrow_forward_ios,
- color: ZenColors.currentMutedText,
- size: 16,
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }
- Widget _buildVolumeSlider({
- required IconData icon,
- required String title,
- required double value,
- required ValueChanged<double> onChanged,
- }) {
- return Container(
- margin: const EdgeInsets.only(top: 8),
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- color: ZenColors.currentUiElements.withValues(alpha: 0.3),
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color: ZenColors.currentUiElements.withValues(alpha: 0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Icon(icon, color: ZenColors.currentPrimaryText, size: 24),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 16,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(height: 8),
- Slider(
- value: value,
- onChanged: onChanged,
- min: 0.0,
- max: 1.0,
- divisions: 10,
- label: '${(value * 100).round()}%',
- activeColor: ZenColors.currentButtonBackground,
- inactiveColor: ZenColors.currentMutedText.withValues(
- alpha: 0.2,
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildThemeTile() {
- var currentTheme = ThemeManager.currentTheme;
- // In release builds, if default theme is selected, switch to automatic
- if (!kDebugMode && currentTheme == SeasonalTheme.default_) {
- currentTheme = SeasonalTheme.automatic;
- // Update the setting asynchronously
- WidgetsBinding.instance.addPostFrameCallback((_) {
- ThemeManager.setTheme(SeasonalTheme.automatic);
- });
- }
- final currentThemeName = _getLocalizedThemeName(currentTheme);
- return Container(
- margin: const EdgeInsets.only(top: 12),
- child: Material(
- color: ZenColors.currentUiElements.withValues(alpha: 0.3),
- borderRadius: BorderRadius.circular(12),
- child: InkWell(
- onTap: _showThemeDialog,
- borderRadius: BorderRadius.circular(12),
- child: Container(
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color: ZenColors.currentUiElements.withValues(alpha: 0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Icon(
- ThemeManager.getThemeIcon(currentTheme),
- color: ZenColors.currentPrimaryText,
- size: 24,
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context)!.colorTheme,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 16,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(height: 2),
- Text(
- currentThemeName,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 13,
- ),
- ),
- ],
- ),
- ),
- Icon(
- Icons.arrow_forward_ios,
- color: ZenColors.currentMutedText,
- size: 16,
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }
- Widget _buildLanguageTile() {
- final currentLocale = LocaleManager.currentLocale;
- final currentLanguageName = LocaleManager.getLocaleDisplayName(
- currentLocale,
- );
- return Container(
- margin: const EdgeInsets.only(top: 12),
- child: Material(
- color: ZenColors.currentUiElements.withValues(alpha: 0.3),
- borderRadius: BorderRadius.circular(12),
- child: InkWell(
- onTap: _showLanguageDialog,
- borderRadius: BorderRadius.circular(12),
- child: Container(
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color: ZenColors.currentUiElements.withValues(alpha: 0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Icon(
- Icons.language,
- color: ZenColors.currentPrimaryText,
- size: 24,
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context)!.language,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 16,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(height: 2),
- Text(
- currentLanguageName,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 13,
- ),
- ),
- ],
- ),
- ),
- Icon(
- Icons.arrow_forward_ios,
- color: ZenColors.currentMutedText,
- size: 16,
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }
- Widget _buildDonationTile() {
- return _buildActionTile(
- icon: Icons.favorite,
- title: AppLocalizations.of(context)!.supportDevelopment,
- subtitle: AppLocalizations.of(context)!.supportDevelopmentDesc,
- onTap: _showDonationDialog,
- );
- }
- // Event Handlers
- Future<void> _toggleMusic(bool value) async {
- setState(() {
- _musicEnabled = value;
- });
- await SettingsManager.setMusicEnabled(value);
- if (_hapticsEnabled) {
- await HapticUtils.vibrate(duration: 50);
- }
- }
- Future<void> _setBgmVolume(double value) async {
- setState(() {
- _bgmVolume = value;
- });
- await SettingsManager.setBgmVolume(value);
- SettingsManager.applyBgmVolume();
- }
- Future<void> _setSfxVolume(double value) async {
- setState(() {
- _sfxVolume = value;
- });
- await SettingsManager.setSfxVolume(value);
- SettingsManager.applySfxVolume();
- }
- Future<void> _toggleHaptics(bool value) async {
- setState(() {
- _hapticsEnabled = value;
- });
- await SettingsManager.setHapticsEnabled(value);
- // Give immediate feedback if enabling haptics
- if (value) {
- await HapticUtils.vibrate(duration: 100);
- }
- }
- void _showTutorial() {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 50);
- }
- showDialog(context: context, builder: (context) => _buildTutorialDialog());
- }
- void _showDonationDialog() {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 50);
- }
- showDialog(context: context, builder: (context) => _buildDonationDialog());
- }
- void _showLanguageDialog() {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 50);
- }
- showDialog(context: context, builder: (context) => _buildLanguageDialog());
- }
- void _showThemeDialog() {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 50);
- }
- showDialog(context: context, builder: (context) => _buildThemeDialog());
- }
- // Dialog Builders
- Widget _buildTutorialDialog() {
- return AlertDialog(
- backgroundColor: ZenColors.currentUiElements,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
- title: Text(
- AppLocalizations.of(context)!.howToUseZenTap,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 22,
- fontWeight: FontWeight.bold,
- ),
- ),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildTutorialStep(
- icon: Icons.touch_app,
- text: AppLocalizations.of(context)!.tapToPopBubbles,
- ),
- const SizedBox(height: 16),
- _buildTutorialStep(
- icon: Icons.stars,
- text: AppLocalizations.of(context)!.earnRelaxationPoints,
- ),
- const SizedBox(height: 16),
- _buildTutorialStep(
- icon: Icons.self_improvement,
- text: AppLocalizations.of(context)!.chooseZenMode,
- ),
- const SizedBox(height: 16),
- _buildTutorialStep(
- icon: Icons.pause,
- text: AppLocalizations.of(context)!.tapPauseAnytime,
- ),
- ],
- ),
- actions: [
- ElevatedButton(
- onPressed: () => Navigator.of(context).pop(),
- style: ElevatedButton.styleFrom(
- backgroundColor: ZenColors.currentButtonBackground,
- foregroundColor: ZenColors.currentButtonText,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- ),
- child: Text(AppLocalizations.of(context)!.gotIt),
- ),
- ],
- );
- }
- Widget _buildTutorialStep({required IconData icon, required String text}) {
- return Row(
- children: [
- Icon(icon, color: ZenColors.currentButtonBackground, size: 20),
- const SizedBox(width: 12),
- Expanded(
- child: Text(
- text,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 14,
- ),
- ),
- ),
- ],
- );
- }
- Widget _buildLanguageDialog() {
- final currentLocale = LocaleManager.currentLocale;
- return AlertDialog(
- backgroundColor: ZenColors.currentUiElements,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
- title: Text(
- AppLocalizations.of(context)!.selectLanguage,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 22,
- fontWeight: FontWeight.bold,
- ),
- ),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- children:
- LocaleManager.supportedLocales.map((locale) {
- final isSelected =
- locale.languageCode == currentLocale.languageCode;
- final languageName = LocaleManager.getLocaleDisplayName(locale);
- return Container(
- margin: const EdgeInsets.only(bottom: 8),
- child: Material(
- color:
- isSelected
- ? ZenColors.currentButtonBackground.withValues(
- alpha: 0.1,
- )
- : Colors.transparent,
- borderRadius: BorderRadius.circular(12),
- child: InkWell(
- onTap: () => _selectLanguage(locale),
- borderRadius: BorderRadius.circular(12),
- child: Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color:
- isSelected
- ? ZenColors.currentButtonBackground
- .withValues(alpha: 0.3)
- : ZenColors.currentUiElements.withValues(
- alpha: 0.2,
- ),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Expanded(
- child: Text(
- languageName,
- style: TextStyle(
- color:
- isSelected
- ? ZenColors.currentButtonBackground
- : ZenColors.currentPrimaryText,
- fontSize: 16,
- fontWeight:
- isSelected
- ? FontWeight.w600
- : FontWeight.normal,
- ),
- ),
- ),
- if (isSelected)
- Icon(
- Icons.check,
- color: ZenColors.currentButtonBackground,
- size: 20,
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }).toList(),
- ),
- actions: [
- TextButton(
- onPressed: () => Navigator.of(context).pop(),
- child: Text(
- AppLocalizations.of(context)!.cancel,
- style: TextStyle(color: ZenColors.currentMutedText),
- ),
- ),
- ],
- );
- }
- Widget _buildThemeDialog() {
- final currentTheme = ThemeManager.currentTheme;
- return AlertDialog(
- backgroundColor: ZenColors.currentUiElements,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
- title: Text(
- AppLocalizations.of(context)!.selectTheme,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 22,
- fontWeight: FontWeight.bold,
- ),
- ),
- content: SizedBox(
- width: double.maxFinite,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- // Use a constraint container with max height for scrolling
- ConstrainedBox(
- constraints: BoxConstraints(
- maxHeight: MediaQuery.of(context).size.height * 0.5,
- ),
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children:
- ThemeManager.availableThemes.map((theme) {
- final isSelected = theme == currentTheme;
- final themeName = _getLocalizedThemeName(theme);
- final themeIcon = ThemeManager.getThemeIcon(theme);
- return Container(
- margin: const EdgeInsets.only(bottom: 8),
- child: Material(
- color:
- isSelected
- ? ZenColors.currentButtonBackground
- .withValues(alpha: 0.1)
- : Colors.transparent,
- borderRadius: BorderRadius.circular(12),
- child: InkWell(
- onTap: () => _selectTheme(theme),
- borderRadius: BorderRadius.circular(12),
- child: Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color:
- isSelected
- ? ZenColors.currentButtonBackground
- .withValues(alpha: 0.3)
- : ZenColors.currentUiElements
- .withValues(alpha: 0.2),
- width: 1,
- ),
- ),
- child: Row(
- children: [
- Icon(
- themeIcon,
- color:
- isSelected
- ? ZenColors
- .currentButtonBackground
- : ZenColors.currentPrimaryText,
- size: 20,
- ),
- const SizedBox(width: 12),
- Expanded(
- child: Text(
- themeName,
- style: TextStyle(
- color:
- isSelected
- ? ZenColors
- .currentButtonBackground
- : ZenColors
- .currentPrimaryText,
- fontSize: 16,
- fontWeight:
- isSelected
- ? FontWeight.w600
- : FontWeight.normal,
- ),
- ),
- ),
- if (isSelected)
- Icon(
- Icons.check,
- color:
- ZenColors.currentButtonBackground,
- size: 20,
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }).toList(),
- ),
- ),
- ),
- ],
- ),
- ),
- actions: [
- TextButton(
- onPressed: () => Navigator.of(context).pop(),
- child: Text(
- AppLocalizations.of(context)!.cancel,
- style: TextStyle(color: ZenColors.currentMutedText),
- ),
- ),
- ],
- );
- }
- Widget _buildDonationDialog() {
- return AlertDialog(
- backgroundColor: ZenColors.currentUiElements,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
- title: Row(
- children: [
- Icon(Icons.favorite, color: ZenColors.red, size: 24),
- const SizedBox(width: 12),
- Text(
- AppLocalizations.of(context)!.supportZenTapTitle,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 22,
- fontWeight: FontWeight.bold,
- ),
- ),
- ],
- ),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context)!.supportMessage,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 14,
- height: 1.4,
- ),
- ),
- const SizedBox(height: 20),
- // Ko-fi Button
- _buildDonationButton(
- icon: Icons.coffee,
- title: AppLocalizations.of(context)!.buyMeACoffee,
- subtitle: AppLocalizations.of(context)!.kofiOneTime,
- color: const Color(0xFF13C3FF),
- onTap: () => _openDonationLink('https://ko-fi.com/fsociety_hu'),
- ),
- const SizedBox(height: 12),
- // PayPal Button
- _buildDonationButton(
- icon: Icons.payment,
- title: AppLocalizations.of(context)!.paypalDonation,
- subtitle: AppLocalizations.of(context)!.directDonation,
- color: const Color(0xFF0070BA),
- onTap: () => _openDonationLink('https://paypal.me/fsocietyhu'),
- ),
- const SizedBox(height: 12),
- // GitHub Sponsors Button
- _buildDonationButton(
- icon: Icons.code,
- title: AppLocalizations.of(context)!.githubSponsors,
- subtitle: AppLocalizations.of(context)!.monthlySupport,
- color: const Color(0xFFEA4AAA),
- onTap:
- () =>
- _openDonationLink('https://github.com/sponsors/fszontagh'),
- ),
- const SizedBox(height: 16),
- Text(
- AppLocalizations.of(context)!.thankYouMessage,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 12,
- fontStyle: FontStyle.italic,
- ),
- textAlign: TextAlign.center,
- ),
- ],
- ),
- actions: [
- TextButton(
- onPressed: () => Navigator.of(context).pop(),
- child: Text(
- AppLocalizations.of(context)!.maybeLater,
- style: TextStyle(color: ZenColors.currentMutedText),
- ),
- ),
- ],
- );
- }
- Widget _buildDonationButton({
- required IconData icon,
- required String title,
- required String subtitle,
- required Color color,
- required VoidCallback onTap,
- }) {
- return Material(
- color: color.withValues(alpha: 0.1),
- borderRadius: BorderRadius.circular(12),
- child: InkWell(
- onTap: onTap,
- borderRadius: BorderRadius.circular(12),
- child: Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(color: color.withValues(alpha: 0.3), width: 1),
- ),
- child: Row(
- children: [
- Icon(icon, color: color, size: 20),
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- color: ZenColors.currentPrimaryText,
- fontSize: 14,
- fontWeight: FontWeight.w500,
- ),
- ),
- Text(
- subtitle,
- style: TextStyle(
- color: ZenColors.currentSecondaryText,
- fontSize: 12,
- ),
- ),
- ],
- ),
- ),
- Icon(Icons.open_in_new, color: color, size: 16),
- ],
- ),
- ),
- ),
- );
- }
- // Helper Methods
- String _getLocalizedThemeName(SeasonalTheme theme) {
- final localizations = AppLocalizations.of(context)!;
- switch (theme) {
- case SeasonalTheme.automatic:
- // Get the auto-detected season (not the effective theme)
- final detectedSeason = ThemeManager.autoDetectedSeason;
- String seasonName;
- // Get the season name based on auto-detected season
- switch (detectedSeason) {
- case SeasonalTheme.spring:
- seasonName = localizations.springTheme;
- break;
- case SeasonalTheme.summer:
- seasonName = localizations.summerTheme;
- break;
- case SeasonalTheme.autumn:
- seasonName = localizations.autumnTheme;
- break;
- case SeasonalTheme.winter:
- seasonName = localizations.winterTheme;
- break;
- default:
- seasonName = localizations.defaultTheme;
- break;
- }
- // Concatenate automatic with detected season
- return '${localizations.automaticTheme} ($seasonName)';
- case SeasonalTheme.default_:
- return localizations.defaultTheme;
- case SeasonalTheme.spring:
- return localizations.springTheme;
- case SeasonalTheme.summer:
- return localizations.summerTheme;
- case SeasonalTheme.autumn:
- return localizations.autumnTheme;
- case SeasonalTheme.winter:
- return localizations.winterTheme;
- }
- }
- Future<void> _selectLanguage(Locale locale) async {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 30);
- }
- await LocaleManager.setLocale(locale);
- if (mounted) {
- Navigator.of(context).pop(); // Close language dialog
- setState(() {}); // Refresh the settings screen to show new language
- }
- }
- Future<void> _selectTheme(SeasonalTheme theme) async {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 30);
- }
- await SettingsManager.setSelectedTheme(theme);
- // Switch menu music to match new theme
- AudioManager().playMenuMusic();
- if (mounted) {
- Navigator.of(context).pop(); // Close theme dialog
- setState(() {}); // Refresh the settings screen to show new theme
- }
- }
- Future<void> _openDonationLink(String url) async {
- if (_hapticsEnabled) {
- HapticUtils.vibrate(duration: 30);
- }
- try {
- final Uri uri = Uri.parse(url);
- if (await canLaunchUrl(uri)) {
- await launchUrl(uri, mode: LaunchMode.externalApplication);
- Navigator.of(context).pop(); // Close dialog after opening link
- } else {
- // Show error if URL can't be launched
- if (mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(
- AppLocalizations.of(context)!.couldNotOpenDonationLink,
- ),
- backgroundColor: ZenColors.currentMutedText,
- behavior: SnackBarBehavior.floating,
- ),
- );
- }
- }
- } catch (e) {
- // Show error on exception
- if (mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(
- AppLocalizations.of(context)!.errorOpeningDonationLink,
- ),
- backgroundColor: ZenColors.currentMutedText,
- behavior: SnackBarBehavior.floating,
- ),
- );
- }
- }
- }
- }
|