needsRefresh method
Check if permissions need refresh 🔧 Set to 30 seconds for DEVELOPMENT, change to 5 minutes for PRODUCTION
Implementation
Future<bool> needsRefresh() async {
try {
final prefs = await SharedPreferences.getInstance();
final lastUpdate = prefs.getString('permissions_last_updated');
if (lastUpdate == null) {
print('⏰ No cached permissions found, needs refresh');
return true;
}
final lastUpdateTime = DateTime.parse(lastUpdate);
final difference = DateTime.now().difference(lastUpdateTime);
// ✅ DEVELOPMENT: 30 seconds
// 🚀 PRODUCTION: Change to Duration(minutes: 5)
const refreshInterval = Duration(seconds: 30);
final needsRefresh = difference > refreshInterval;
if (needsRefresh) {
print('⏰ Permissions expired (${difference.inSeconds}s old), needs refresh');
} else {
print('✅ Permissions still fresh (${difference.inSeconds}s old)');
}
return needsRefresh;
} catch (e) {
print('❌ Error checking refresh: $e');
return true;
}
}