Skip to content

Commit 18768d0

Browse files
committed
fix: get rid of the popup
1 parent 58edc51 commit 18768d0

File tree

1 file changed

+4
-103
lines changed

1 file changed

+4
-103
lines changed

lib/home_page.dart

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'dart:convert';
44
import 'dart:async'; // Add this import for Timer
55
import 'package:intl/intl.dart';
66
import 'predictions_page.dart';
7-
import 'package:shared_preferences/shared_preferences.dart';
87
import 'package:firebase_remote_config/firebase_remote_config.dart';
98

109
class HomePage extends StatefulWidget {
@@ -19,9 +18,7 @@ class _HomePageState extends State<HomePage> {
1918
bool _isConnected = false;
2019
int _reconnectAttempts = 0;
2120
static const int maxReconnectAttempts = 5;
22-
static const String _hasSeenWishesKey = 'has_seen_christmas_wishes';
2321
final _remoteConfig = FirebaseRemoteConfig.instance;
24-
static const String _showPopupKey = 'show_christmas_popup';
2522
Timer? _configCheckTimer;
2623

2724
// Pool data
@@ -56,24 +53,8 @@ class _HomePageState extends State<HomePage> {
5653
minimumFetchInterval: const Duration(hours: 1),
5754
));
5855
debugPrint('Config settings set successfully');
59-
60-
await _remoteConfig.setDefaults({
61-
_showPopupKey: false,
62-
});
63-
debugPrint('Defaults set: show_popup = false');
64-
65-
final fetchStatus = await _remoteConfig.fetchAndActivate();
66-
debugPrint('Fetch and activate completed. Success: $fetchStatus');
67-
68-
final showPopup = _remoteConfig.getBool(_showPopupKey);
69-
debugPrint('Remote config value for show_popup: $showPopup');
70-
71-
if (showPopup) {
72-
debugPrint('Showing Christmas popup based on remote config');
73-
_showChristmasWishesIfNeeded();
74-
} else {
75-
debugPrint('Popup disabled by remote config');
76-
}
56+
await _remoteConfig.fetchAndActivate();
57+
debugPrint('Remote config initialized successfully');
7758
} catch (e, stackTrace) {
7859
debugPrint('Failed to initialize remote config: $e');
7960
debugPrint('Stack trace: $stackTrace');
@@ -83,93 +64,13 @@ class _HomePageState extends State<HomePage> {
8364
Future<void> _checkAndUpdateConfig() async {
8465
try {
8566
debugPrint('Checking for config updates...');
86-
final updated = await _remoteConfig.fetchAndActivate();
87-
final showPopup = _remoteConfig.getBool(_showPopupKey);
88-
debugPrint('Config update status: $updated, show_popup: $showPopup');
89-
90-
if (updated && showPopup) {
91-
debugPrint('Config updated and popup enabled, checking if should show');
92-
_showChristmasWishesIfNeeded();
93-
}
67+
await _remoteConfig.fetchAndActivate();
68+
debugPrint('Config updated successfully');
9469
} catch (e) {
9570
debugPrint('Failed to fetch remote config: $e');
9671
}
9772
}
9873

99-
Future<void> _showChristmasWishesIfNeeded() async {
100-
final prefs = await SharedPreferences.getInstance();
101-
final hasSeenWishes = prefs.getBool(_hasSeenWishesKey) ?? false;
102-
debugPrint('Has user seen wishes before? $hasSeenWishes');
103-
104-
if (!hasSeenWishes) {
105-
debugPrint('User has not seen wishes, showing popup');
106-
WidgetsBinding.instance.addPostFrameCallback((_) {
107-
_showChristmasWishes();
108-
});
109-
await prefs.setBool(_hasSeenWishesKey, true);
110-
debugPrint('Marked wishes as seen in preferences');
111-
} else {
112-
debugPrint('User has already seen wishes, skipping popup');
113-
}
114-
}
115-
116-
void _showChristmasWishes() {
117-
showDialog(
118-
context: context,
119-
builder: (BuildContext context) {
120-
return Dialog(
121-
shape: RoundedRectangleBorder(
122-
borderRadius: BorderRadius.circular(20),
123-
),
124-
child: Container(
125-
padding: const EdgeInsets.all(24),
126-
decoration: BoxDecoration(
127-
borderRadius: BorderRadius.circular(20),
128-
gradient: const LinearGradient(
129-
begin: Alignment.topLeft,
130-
end: Alignment.bottomRight,
131-
colors: [Color(0xFF1E3C72), Color(0xFF2A5298)],
132-
),
133-
),
134-
child: Column(
135-
mainAxisSize: MainAxisSize.min,
136-
children: [
137-
const Icon(
138-
Icons.favorite,
139-
color: Colors.red,
140-
size: 48,
141-
),
142-
const SizedBox(height: 16),
143-
Text(
144-
'Buon Natale Pupina!',
145-
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
146-
color: Colors.white,
147-
fontWeight: FontWeight.bold,
148-
),
149-
),
150-
const SizedBox(height: 16),
151-
Text(
152-
'Un piccolo aiuto per decidere quando andare a nuotare\n❤️ Spero ti sarà utile! ❤️',
153-
textAlign: TextAlign.center,
154-
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
155-
color: Colors.white,
156-
),
157-
),
158-
const SizedBox(height: 24),
159-
TextButton(
160-
onPressed: () => Navigator.of(context).pop(),
161-
child: const Text(
162-
'Ti amo tanto',
163-
style: TextStyle(color: Colors.white),
164-
),
165-
),
166-
],
167-
),
168-
),
169-
);
170-
},
171-
);
172-
}
17374

17475
void _connectWebSocket() {
17576
_channel?.sink.close();

0 commit comments

Comments
 (0)