| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196 |
- 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.4',
- 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
- switch (Localizations.localeOf(context).languageCode) {
- case 'de':
- return 'Automatisch ($seasonName)';
- case 'hu':
- return 'Automatikus ($seasonName)';
- default:
- return 'Automatic ($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,
- ),
- );
- }
- }
- }
- }
|