Код: Выделить всё
void _listenToPrayer() async {
log('Listen To Prayer');
// log(' ${}');
try {
await HiveService.instance.init();
DartPluginRegistrant.ensureInitialized();
// Get prayer data
yearPrayers = HiveService.instance.getPrayers();
if (yearPrayers == null) {
log('No prayer data found.');
return;
}
_getNextPrayer(yearPrayers!, false);
} on FirebaseException catch (e, st) {
log('Firebase error: ${e.message} \n $st');
} catch (e, st) {
log('General error: $e \n $st');
}
< /code>
} < /p>
void _initializeAndStartCountdown() {
DateTime nextPrayerDateTime = _parsePrayerTime(prayerTime);
if (nextPrayerDateTime.isBefore(DateTime.now())) {
Duration passedDuration = DateTime.now().difference(nextPrayerDateTime);
if (passedDuration.inMinutes < 30) {
countdown = _formatPositiveDuration(passedDuration);
_isPositiveTimer = true;
} else {
nextPrayerDateTime = nextPrayerDateTime.add(const Duration(days: 1));
countdown =
_formatDuration(nextPrayerDateTime.difference(DateTime.now()));
_isPositiveTimer = false;
}
} else {
countdown =
_formatDuration(nextPrayerDateTime.difference(DateTime.now()));
_isPositiveTimer = false;
}
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
if (_isPositiveTimer) {
_startCountUpTimer(nextPrayerDateTime);
} else {
_startCountDownTimer(nextPrayerDateTime);
}
});
Подробнее здесь: https://stackoverflow.com/questions/793 ... ce-flutter