|
| 1 | +// Copyright 2020-2025 The Hello World Writer. All rights reserved. |
| 2 | +// https://www.thehelloworldwriter.com |
| 3 | +// |
| 4 | +// Use of this source code is governed by an MIT-style license |
| 5 | +// that can be found in the LICENSE file. |
| 6 | + |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | + |
| 9 | +import '../data/counter_ideas.dart'; |
| 10 | +import '../models/counter.dart'; |
| 11 | +import '../utils/utils.dart'; |
| 12 | + |
| 13 | +/// Screen that displays inspiration ideas for counting with a specific counter color. |
| 14 | +class InspirationScreen extends StatelessWidget { |
| 15 | + const InspirationScreen({required this.counter, super.key}); |
| 16 | + |
| 17 | + final Counter counter; |
| 18 | + |
| 19 | + @override |
| 20 | + Widget build(BuildContext context) { |
| 21 | + final List<String> ideas = counterIdeas[counter.type] ?? []; |
| 22 | + final Color counterColor = counter.color; |
| 23 | + final Color textColor = counterColor.contrastOf(); |
| 24 | + final String colorName = counter.type.name[0].toUpperCase() + counter.type.name.substring(1); |
| 25 | + |
| 26 | + return Scaffold( |
| 27 | + appBar: AppBar( |
| 28 | + title: Text('$colorName Inspiration'), |
| 29 | + backgroundColor: counterColor, |
| 30 | + foregroundColor: textColor, |
| 31 | + iconTheme: IconThemeData(color: textColor), |
| 32 | + ), |
| 33 | + body: ideas.isEmpty ? _buildEmptyState(colorName) : _buildIdeasList(ideas, counterColor), |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + /// Builds the empty state when no ideas are available. |
| 38 | + Widget _buildEmptyState(String colorName) { |
| 39 | + return Center( |
| 40 | + child: Padding( |
| 41 | + padding: const EdgeInsets.all(32.0), |
| 42 | + child: Column( |
| 43 | + mainAxisAlignment: MainAxisAlignment.center, |
| 44 | + children: [ |
| 45 | + Icon( |
| 46 | + Icons.lightbulb_outline, |
| 47 | + size: 64, |
| 48 | + color: Colors.grey[400], |
| 49 | + ), |
| 50 | + const SizedBox(height: 16), |
| 51 | + Text( |
| 52 | + 'No inspiration ideas yet for $colorName.', |
| 53 | + textAlign: TextAlign.center, |
| 54 | + style: TextStyle( |
| 55 | + fontSize: 18, |
| 56 | + color: Colors.grey[600], |
| 57 | + ), |
| 58 | + ), |
| 59 | + const SizedBox(height: 8), |
| 60 | + Text( |
| 61 | + 'Use this counter for anything you\'d like!', |
| 62 | + textAlign: TextAlign.center, |
| 63 | + style: TextStyle( |
| 64 | + fontSize: 16, |
| 65 | + color: Colors.grey[500], |
| 66 | + ), |
| 67 | + ), |
| 68 | + ], |
| 69 | + ), |
| 70 | + ), |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + /// Builds the list of counting ideas. |
| 75 | + Widget _buildIdeasList(List<String> ideas, Color counterColor) { |
| 76 | + return ListView( |
| 77 | + padding: const EdgeInsets.symmetric(vertical: 16), |
| 78 | + children: [ |
| 79 | + // Header text |
| 80 | + Padding( |
| 81 | + padding: const EdgeInsets.fromLTRB(16, 8, 16, 16), |
| 82 | + child: Text( |
| 83 | + 'Running out of ideas? Try counting these:', |
| 84 | + style: TextStyle( |
| 85 | + fontSize: 14, |
| 86 | + color: Colors.grey[600], |
| 87 | + fontStyle: FontStyle.italic, |
| 88 | + ), |
| 89 | + ), |
| 90 | + ), |
| 91 | + // Ideas list |
| 92 | + ...ideas.map( |
| 93 | + (idea) => ListTile( |
| 94 | + leading: Icon( |
| 95 | + Icons.circle, |
| 96 | + size: 12, |
| 97 | + color: counterColor, |
| 98 | + ), |
| 99 | + title: Text(idea), |
| 100 | + visualDensity: VisualDensity.comfortable, |
| 101 | + ), |
| 102 | + ), |
| 103 | + ], |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
0 commit comments