settings_screen.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. import 'package:flutter/material.dart';
  2. import '../utils/colors.dart';
  3. import '../utils/haptic_utils.dart';
  4. import '../utils/settings_manager.dart';
  5. import 'components/animated_background.dart';
  6. class SettingsScreen extends StatefulWidget {
  7. const SettingsScreen({super.key});
  8. @override
  9. State<SettingsScreen> createState() => _SettingsScreenState();
  10. }
  11. class _SettingsScreenState extends State<SettingsScreen> {
  12. bool _musicEnabled = true;
  13. bool _hapticsEnabled = true;
  14. double _bgmVolume = 0.4;
  15. double _sfxVolume = 0.6;
  16. @override
  17. void initState() {
  18. super.initState();
  19. _loadSettings();
  20. }
  21. Future<void> _loadSettings() async {
  22. setState(() {
  23. _musicEnabled = SettingsManager.isMusicEnabled;
  24. _hapticsEnabled = SettingsManager.isHapticsEnabled;
  25. _bgmVolume = SettingsManager.bgmVolume;
  26. _sfxVolume = SettingsManager.sfxVolume;
  27. });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. backgroundColor: ZenColors.appBackground,
  33. body: AnimatedBackground(
  34. child: SafeArea(
  35. child: Column(
  36. children: [
  37. // Header
  38. Padding(
  39. padding: const EdgeInsets.all(16.0),
  40. child: Row(
  41. children: [
  42. IconButton(
  43. onPressed: () => Navigator.of(context).pop(),
  44. icon: const Icon(
  45. Icons.arrow_back,
  46. color: ZenColors.primaryText,
  47. size: 28,
  48. ),
  49. style: IconButton.styleFrom(
  50. backgroundColor: ZenColors.black.withOpacity(0.3),
  51. shape: const CircleBorder(),
  52. ),
  53. ),
  54. const SizedBox(width: 16),
  55. const Text(
  56. 'Settings',
  57. style: TextStyle(
  58. color: ZenColors.primaryText,
  59. fontSize: 28,
  60. fontWeight: FontWeight.bold,
  61. letterSpacing: 1.0,
  62. ),
  63. ),
  64. ],
  65. ),
  66. ),
  67. // Settings List
  68. Expanded(
  69. child: Padding(
  70. padding: const EdgeInsets.symmetric(horizontal: 20.0),
  71. child: Column(
  72. children: [
  73. const SizedBox(height: 20),
  74. // Audio Section
  75. _buildSectionHeader('Audio'),
  76. _buildSettingTile(
  77. icon: Icons.music_note,
  78. title: 'Background Music',
  79. subtitle: 'Enable relaxing ambient sounds',
  80. value: _musicEnabled,
  81. onChanged: _toggleMusic,
  82. ),
  83. _buildVolumeSlider(
  84. icon: Icons.volume_up,
  85. title: 'Music Volume',
  86. value: _bgmVolume,
  87. onChanged: _setBgmVolume,
  88. ),
  89. const SizedBox(height: 10),
  90. _buildVolumeSlider(
  91. icon: Icons.volume_up,
  92. title: 'Sound Effects Volume',
  93. value: _sfxVolume,
  94. onChanged: _setSfxVolume,
  95. ),
  96. const SizedBox(height: 30),
  97. // Feedback Section
  98. _buildSectionHeader('Feedback'),
  99. _buildSettingTile(
  100. icon: Icons.vibration,
  101. title: 'Haptic Feedback',
  102. subtitle: 'Feel gentle vibrations on tap',
  103. value: _hapticsEnabled,
  104. onChanged: _toggleHaptics,
  105. ),
  106. const SizedBox(height: 30),
  107. // Tutorial Section
  108. _buildSectionHeader('Help'),
  109. _buildActionTile(
  110. icon: Icons.help_outline,
  111. title: 'Show Tutorial',
  112. subtitle: 'Learn how to use ZenTap',
  113. onTap: _showTutorial,
  114. ),
  115. const Spacer(),
  116. // About Section
  117. Padding(
  118. padding: const EdgeInsets.only(bottom: 20),
  119. child: Column(
  120. children: [
  121. Text(
  122. 'ZenTap v1.0.1',
  123. style: TextStyle(
  124. color: ZenColors.mutedText,
  125. fontSize: 14,
  126. ),
  127. ),
  128. const SizedBox(height: 8),
  129. Text(
  130. 'A stress relief tapping game',
  131. style: TextStyle(
  132. color: ZenColors.mutedText,
  133. fontSize: 12,
  134. fontStyle: FontStyle.italic,
  135. ),
  136. ),
  137. ],
  138. ),
  139. ),
  140. ],
  141. ),
  142. ),
  143. ),
  144. ],
  145. ),
  146. ),
  147. ),
  148. );
  149. }
  150. Widget _buildSectionHeader(String title) {
  151. return Align(
  152. alignment: Alignment.centerLeft,
  153. child: Text(
  154. title,
  155. style: TextStyle(
  156. color: ZenColors.secondaryText,
  157. fontSize: 16,
  158. fontWeight: FontWeight.w600,
  159. letterSpacing: 0.5,
  160. ),
  161. ),
  162. );
  163. }
  164. Widget _buildSettingTile({
  165. required IconData icon,
  166. required String title,
  167. required String subtitle,
  168. required bool value,
  169. required ValueChanged<bool> onChanged,
  170. }) {
  171. return Container(
  172. margin: const EdgeInsets.only(top: 12),
  173. padding: const EdgeInsets.all(16),
  174. decoration: BoxDecoration(
  175. color: ZenColors.uiElements.withOpacity(0.3),
  176. borderRadius: BorderRadius.circular(12),
  177. border: Border.all(
  178. color: ZenColors.uiElements.withOpacity(0.2),
  179. width: 1,
  180. ),
  181. ),
  182. child: Row(
  183. children: [
  184. Icon(
  185. icon,
  186. color: ZenColors.primaryText,
  187. size: 24,
  188. ),
  189. const SizedBox(width: 16),
  190. Expanded(
  191. child: Column(
  192. crossAxisAlignment: CrossAxisAlignment.start,
  193. children: [
  194. Text(
  195. title,
  196. style: const TextStyle(
  197. color: ZenColors.primaryText,
  198. fontSize: 16,
  199. fontWeight: FontWeight.w500,
  200. ),
  201. ),
  202. const SizedBox(height: 2),
  203. Text(
  204. subtitle,
  205. style: TextStyle(
  206. color: ZenColors.secondaryText,
  207. fontSize: 13,
  208. ),
  209. ),
  210. ],
  211. ),
  212. ),
  213. Switch(
  214. value: value,
  215. onChanged: onChanged,
  216. activeColor: ZenColors.buttonBackground,
  217. activeTrackColor: ZenColors.buttonBackground.withOpacity(0.3),
  218. inactiveThumbColor: ZenColors.mutedText,
  219. inactiveTrackColor: ZenColors.mutedText.withOpacity(0.2),
  220. ),
  221. ],
  222. ),
  223. );
  224. }
  225. Widget _buildActionTile({
  226. required IconData icon,
  227. required String title,
  228. required String subtitle,
  229. required VoidCallback onTap,
  230. }) {
  231. return Container(
  232. margin: const EdgeInsets.only(top: 12),
  233. child: Material(
  234. color: ZenColors.uiElements.withOpacity(0.3),
  235. borderRadius: BorderRadius.circular(12),
  236. child: InkWell(
  237. onTap: onTap,
  238. borderRadius: BorderRadius.circular(12),
  239. child: Container(
  240. padding: const EdgeInsets.all(16),
  241. decoration: BoxDecoration(
  242. borderRadius: BorderRadius.circular(12),
  243. border: Border.all(
  244. color: ZenColors.uiElements.withOpacity(0.2),
  245. width: 1,
  246. ),
  247. ),
  248. child: Row(
  249. children: [
  250. Icon(
  251. icon,
  252. color: ZenColors.primaryText,
  253. size: 24,
  254. ),
  255. const SizedBox(width: 16),
  256. Expanded(
  257. child: Column(
  258. crossAxisAlignment: CrossAxisAlignment.start,
  259. children: [
  260. Text(
  261. title,
  262. style: const TextStyle(
  263. color: ZenColors.primaryText,
  264. fontSize: 16,
  265. fontWeight: FontWeight.w500,
  266. ),
  267. ),
  268. const SizedBox(height: 2),
  269. Text(
  270. subtitle,
  271. style: TextStyle(
  272. color: ZenColors.secondaryText,
  273. fontSize: 13,
  274. ),
  275. ),
  276. ],
  277. ),
  278. ),
  279. Icon(
  280. Icons.arrow_forward_ios,
  281. color: ZenColors.mutedText,
  282. size: 16,
  283. ),
  284. ],
  285. ),
  286. ),
  287. ),
  288. ),
  289. );
  290. }
  291. Future<void> _toggleMusic(bool value) async {
  292. setState(() {
  293. _musicEnabled = value;
  294. });
  295. await SettingsManager.setMusicEnabled(value);
  296. if (_hapticsEnabled) {
  297. await HapticUtils.vibrate(duration: 50);
  298. }
  299. }
  300. Future<void> _setBgmVolume(double value) async {
  301. setState(() {
  302. _bgmVolume = value;
  303. });
  304. await SettingsManager.setBgmVolume(value);
  305. SettingsManager.applyBgmVolume();
  306. }
  307. Future<void> _setSfxVolume(double value) async {
  308. setState(() {
  309. _sfxVolume = value;
  310. });
  311. await SettingsManager.setSfxVolume(value);
  312. }
  313. Future<void> _toggleHaptics(bool value) async {
  314. setState(() {
  315. _hapticsEnabled = value;
  316. });
  317. await SettingsManager.setHapticsEnabled(value);
  318. // Give immediate feedback if enabling haptics
  319. if (value) {
  320. await HapticUtils.vibrate(duration: 100);
  321. }
  322. }
  323. void _showTutorial() {
  324. if (_hapticsEnabled) {
  325. HapticUtils.vibrate(duration: 50);
  326. }
  327. showDialog(
  328. context: context,
  329. builder: (context) => _buildTutorialDialog(),
  330. );
  331. }
  332. Widget _buildTutorialDialog() {
  333. return AlertDialog(
  334. backgroundColor: ZenColors.uiElements,
  335. shape: RoundedRectangleBorder(
  336. borderRadius: BorderRadius.circular(20),
  337. ),
  338. title: const Text(
  339. 'How to Use ZenTap',
  340. style: TextStyle(
  341. color: ZenColors.primaryText,
  342. fontSize: 22,
  343. fontWeight: FontWeight.bold,
  344. ),
  345. ),
  346. content: Column(
  347. mainAxisSize: MainAxisSize.min,
  348. crossAxisAlignment: CrossAxisAlignment.start,
  349. children: [
  350. _buildTutorialStep(
  351. icon: Icons.touch_app,
  352. text: 'Tap anywhere on the screen to pop bubbles',
  353. ),
  354. const SizedBox(height: 16),
  355. _buildTutorialStep(
  356. icon: Icons.stars,
  357. text: 'Earn Relaxation Points in Play mode',
  358. ),
  359. const SizedBox(height: 16),
  360. _buildTutorialStep(
  361. icon: Icons.self_improvement,
  362. text: 'Choose Zen Mode for pure relaxation',
  363. ),
  364. const SizedBox(height: 16),
  365. _buildTutorialStep(
  366. icon: Icons.pause,
  367. text: 'Tap pause anytime to take a break',
  368. ),
  369. ],
  370. ),
  371. actions: [
  372. ElevatedButton(
  373. onPressed: () => Navigator.of(context).pop(),
  374. style: ElevatedButton.styleFrom(
  375. backgroundColor: ZenColors.buttonBackground,
  376. foregroundColor: ZenColors.buttonText,
  377. shape: RoundedRectangleBorder(
  378. borderRadius: BorderRadius.circular(12),
  379. ),
  380. ),
  381. child: const Text('Got it!'),
  382. ),
  383. ],
  384. );
  385. }
  386. Widget _buildVolumeSlider({
  387. required IconData icon,
  388. required String title,
  389. required double value,
  390. required ValueChanged<double> onChanged,
  391. }) {
  392. return Container(
  393. margin: const EdgeInsets.only(top: 8),
  394. padding: const EdgeInsets.all(16),
  395. decoration: BoxDecoration(
  396. color: ZenColors.uiElements.withOpacity(0.3),
  397. borderRadius: BorderRadius.circular(12),
  398. border: Border.all(
  399. color: ZenColors.uiElements.withOpacity(0.2),
  400. width: 1,
  401. ),
  402. ),
  403. child: Row(
  404. children: [
  405. Icon(
  406. icon,
  407. color: ZenColors.primaryText,
  408. size: 24,
  409. ),
  410. const SizedBox(width: 16),
  411. Expanded(
  412. child: Column(
  413. crossAxisAlignment: CrossAxisAlignment.start,
  414. children: [
  415. Text(
  416. title,
  417. style: const TextStyle(
  418. color: ZenColors.primaryText,
  419. fontSize: 16,
  420. fontWeight: FontWeight.w500,
  421. ),
  422. ),
  423. const SizedBox(height: 8),
  424. Slider(
  425. value: value,
  426. onChanged: onChanged,
  427. min: 0.0,
  428. max: 1.0,
  429. divisions: 10,
  430. label: '${(value * 100).round()}%',
  431. activeColor: ZenColors.buttonBackground,
  432. inactiveColor: ZenColors.mutedText.withOpacity(0.2),
  433. ),
  434. ],
  435. ),
  436. ),
  437. ],
  438. ),
  439. );
  440. }
  441. Widget _buildTutorialStep({
  442. required IconData icon,
  443. required String text,
  444. }) {
  445. return Row(
  446. children: [
  447. Icon(
  448. icon,
  449. color: ZenColors.buttonBackground,
  450. size: 20,
  451. ),
  452. const SizedBox(width: 12),
  453. Expanded(
  454. child: Text(
  455. text,
  456. style: TextStyle(
  457. color: ZenColors.secondaryText,
  458. fontSize: 14,
  459. ),
  460. ),
  461. ),
  462. ],
  463. );
  464. }
  465. }