tutorial_overlay.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. import 'package:flutter/material.dart';
  2. import '../../utils/colors.dart';
  3. import '../../utils/haptic_utils.dart';
  4. import '../../utils/settings_manager.dart';
  5. class TutorialOverlay extends StatefulWidget {
  6. final VoidCallback onComplete;
  7. const TutorialOverlay({
  8. super.key,
  9. required this.onComplete,
  10. });
  11. @override
  12. State<TutorialOverlay> createState() => _TutorialOverlayState();
  13. }
  14. class _TutorialOverlayState extends State<TutorialOverlay>
  15. with TickerProviderStateMixin {
  16. late AnimationController _pulseController;
  17. late AnimationController _fadeController;
  18. late Animation<double> _pulseAnimation;
  19. late Animation<double> _fadeAnimation;
  20. int _currentStep = 0;
  21. final int _totalSteps = 3;
  22. final List<TutorialStep> _steps = [
  23. TutorialStep(
  24. title: 'Welcome to ZenTap!',
  25. description: 'Tap anywhere on the screen to pop relaxing bubbles',
  26. icon: Icons.touch_app,
  27. position: TutorialPosition.center,
  28. ),
  29. TutorialStep(
  30. title: 'Earn Relaxation Points',
  31. description: 'Each bubble you pop gives you points to track your zen journey',
  32. icon: Icons.stars,
  33. position: TutorialPosition.center,
  34. ),
  35. TutorialStep(
  36. title: 'Ready to Relax?',
  37. description: 'Try Zen Mode for endless peaceful tapping without scores',
  38. icon: Icons.self_improvement,
  39. position: TutorialPosition.center,
  40. ),
  41. ];
  42. @override
  43. void initState() {
  44. super.initState();
  45. _pulseController = AnimationController(
  46. duration: const Duration(milliseconds: 1500),
  47. vsync: this,
  48. )..repeat(reverse: true);
  49. _fadeController = AnimationController(
  50. duration: const Duration(milliseconds: 500),
  51. vsync: this,
  52. );
  53. _pulseAnimation = Tween<double>(
  54. begin: 0.8,
  55. end: 1.2,
  56. ).animate(CurvedAnimation(
  57. parent: _pulseController,
  58. curve: Curves.easeInOut,
  59. ));
  60. _fadeAnimation = Tween<double>(
  61. begin: 0.0,
  62. end: 1.0,
  63. ).animate(CurvedAnimation(
  64. parent: _fadeController,
  65. curve: Curves.easeInOut,
  66. ));
  67. _fadeController.forward();
  68. }
  69. @override
  70. void dispose() {
  71. _pulseController.dispose();
  72. _fadeController.dispose();
  73. super.dispose();
  74. }
  75. @override
  76. Widget build(BuildContext context) {
  77. final step = _steps[_currentStep];
  78. return FadeTransition(
  79. opacity: _fadeAnimation,
  80. child: Container(
  81. color: ZenColors.black.withOpacity(0.85),
  82. child: SafeArea(
  83. child: Stack(
  84. children: [
  85. // Tutorial content
  86. Positioned.fill(
  87. child: Column(
  88. mainAxisAlignment: MainAxisAlignment.center,
  89. children: [
  90. // Animated icon
  91. AnimatedBuilder(
  92. animation: _pulseAnimation,
  93. builder: (context, child) {
  94. return Transform.scale(
  95. scale: _pulseAnimation.value,
  96. child: Container(
  97. padding: const EdgeInsets.all(30),
  98. decoration: BoxDecoration(
  99. shape: BoxShape.circle,
  100. color: ZenColors.buttonBackground.withValues(alpha: 0.2),
  101. border: Border.all(
  102. color: ZenColors.buttonBackground,
  103. width: 2,
  104. ),
  105. ),
  106. child: Icon(
  107. step.icon,
  108. size: 60,
  109. color: ZenColors.buttonBackground,
  110. ),
  111. ),
  112. );
  113. },
  114. ),
  115. const SizedBox(height: 40),
  116. // Title
  117. Padding(
  118. padding: const EdgeInsets.symmetric(horizontal: 40),
  119. child: Text(
  120. step.title,
  121. style: const TextStyle(
  122. color: ZenColors.primaryText,
  123. fontSize: 28,
  124. fontWeight: FontWeight.bold,
  125. letterSpacing: 0.5,
  126. ),
  127. textAlign: TextAlign.center,
  128. ),
  129. ),
  130. const SizedBox(height: 20),
  131. // Description
  132. Padding(
  133. padding: const EdgeInsets.symmetric(horizontal: 40),
  134. child: Text(
  135. step.description,
  136. style: TextStyle(
  137. color: ZenColors.secondaryText,
  138. fontSize: 16,
  139. height: 1.5,
  140. ),
  141. textAlign: TextAlign.center,
  142. ),
  143. ),
  144. const SizedBox(height: 60),
  145. // Progress indicator
  146. Row(
  147. mainAxisAlignment: MainAxisAlignment.center,
  148. children: List.generate(_totalSteps, (index) {
  149. return Container(
  150. margin: const EdgeInsets.symmetric(horizontal: 4),
  151. width: 12,
  152. height: 12,
  153. decoration: BoxDecoration(
  154. shape: BoxShape.circle,
  155. color: index <= _currentStep
  156. ? ZenColors.buttonBackground
  157. : ZenColors.mutedText.withValues(alpha: 0.3),
  158. ),
  159. );
  160. }),
  161. ),
  162. const SizedBox(height: 40),
  163. // Action buttons
  164. Padding(
  165. padding: const EdgeInsets.symmetric(horizontal: 40),
  166. child: Row(
  167. children: [
  168. if (_currentStep > 0)
  169. Expanded(
  170. child: OutlinedButton(
  171. onPressed: _previousStep,
  172. style: OutlinedButton.styleFrom(
  173. foregroundColor: ZenColors.primaryText,
  174. side: const BorderSide(
  175. color: ZenColors.mutedText,
  176. ),
  177. shape: RoundedRectangleBorder(
  178. borderRadius: BorderRadius.circular(12),
  179. ),
  180. padding: const EdgeInsets.symmetric(vertical: 16),
  181. ),
  182. child: const Text(
  183. 'Previous',
  184. style: TextStyle(fontSize: 16),
  185. ),
  186. ),
  187. ),
  188. if (_currentStep > 0) const SizedBox(width: 16),
  189. Expanded(
  190. flex: 2,
  191. child: ElevatedButton(
  192. onPressed: _nextStep,
  193. style: ElevatedButton.styleFrom(
  194. backgroundColor: ZenColors.buttonBackground,
  195. foregroundColor: ZenColors.buttonText,
  196. shape: RoundedRectangleBorder(
  197. borderRadius: BorderRadius.circular(12),
  198. ),
  199. padding: const EdgeInsets.symmetric(vertical: 16),
  200. elevation: 4,
  201. ),
  202. child: Text(
  203. _currentStep == _totalSteps - 1
  204. ? 'Start Relaxing!'
  205. : 'Continue',
  206. style: const TextStyle(
  207. fontSize: 16,
  208. fontWeight: FontWeight.w600,
  209. ),
  210. ),
  211. ),
  212. ),
  213. ],
  214. ),
  215. ),
  216. ],
  217. ),
  218. ),
  219. // Skip button
  220. Positioned(
  221. top: 20,
  222. right: 20,
  223. child: TextButton(
  224. onPressed: _skipTutorial,
  225. style: TextButton.styleFrom(
  226. foregroundColor: ZenColors.mutedText,
  227. ),
  228. child: const Text(
  229. 'Skip',
  230. style: TextStyle(fontSize: 16),
  231. ),
  232. ),
  233. ),
  234. ],
  235. ),
  236. ),
  237. ),
  238. );
  239. }
  240. void _nextStep() async {
  241. if (SettingsManager.isHapticsEnabled) {
  242. await HapticUtils.vibrate(duration: 50);
  243. }
  244. if (_currentStep < _totalSteps - 1) {
  245. setState(() {
  246. _currentStep++;
  247. });
  248. } else {
  249. await _completeTutorial();
  250. }
  251. }
  252. void _previousStep() async {
  253. if (SettingsManager.isHapticsEnabled) {
  254. await HapticUtils.vibrate(duration: 50);
  255. }
  256. if (_currentStep > 0) {
  257. setState(() {
  258. _currentStep--;
  259. });
  260. }
  261. }
  262. void _skipTutorial() async {
  263. if (SettingsManager.isHapticsEnabled) {
  264. await HapticUtils.vibrate(duration: 50);
  265. }
  266. await _completeTutorial();
  267. }
  268. Future<void> _completeTutorial() async {
  269. await SettingsManager.setTutorialShown(true);
  270. await _fadeController.reverse();
  271. widget.onComplete();
  272. }
  273. }
  274. class TutorialStep {
  275. final String title;
  276. final String description;
  277. final IconData icon;
  278. final TutorialPosition position;
  279. TutorialStep({
  280. required this.title,
  281. required this.description,
  282. required this.icon,
  283. required this.position,
  284. });
  285. }
  286. enum TutorialPosition {
  287. center,
  288. top,
  289. bottom,
  290. }