I’m building my first Flutter app for Android and iOS and I’m stuck with scheduled notifications on Android.
- What works: immediate notifications (show(…)) display fine after the user enables notifications.
- What doesn’t: time-based (scheduled/weekly) notifications never fire at the selected weekday & time.
- Permissions: On Android, the app asks for notification permission and I’ve also enabled Alarms & reminders (Schedule exact alarms) in system settings. Both are ON.
Environment
- flutter_local_notifications: ^19.4.0
- timezone: ^0.10.1
- flutter_timezone: ^4.1.1
- Device(s): [Android Studio + Medium Device API 36, Samsung Galaxy S23 + Android 15
What I expect
When the user picks a weekday and time (e.g., Monday at 09:00), a notification should appear then, and repeat weekly.
What actually happens
Nothing fires at the scheduled time. No crashes. Immediate notifications using the same channel work reliably.
Code:
Settings_Screen
import 'package:my_app/config/notifications.dart';
// --- Notifications ---
const Divider(height: 32),
SwitchListTile(
title: const Text('Benachrichtigungen aktivieren'),
value: _notifEnabled,
onChanged: _toggleNotifications,
),
if (_notifEnabled) ...[
_buildExactStatusTile(), // neu
const SizedBox(height: 8),
const Text('Wochentag', style: TextStyle(fontWeight: FontWeight.bold)),
Wrap(
spacing: 8,
children: List.generate(7, (i) {
final int day = i + 1; // 1=Mo ... 7=So
const labels = ['Mo','Di','Mi','Do','Fr','Sa','So'];
return ChoiceChip(
label: Text(labels[i]),
selected: _notifWeekday == day,
onSelected: (_) async {
setState(() => _notifWeekday = day);
await _persistNotificationPrefs();
await _applyNotificationSchedule();
},
);
}),
),
const SizedBox(height: 16),
ListTile(
leading: const Icon(Icons.access_time),
title: Text(
_notifTime == null
? 'Uhrzeit auswählen'
: 'Uhrzeit: ${_notifTime!.format(context)}',
),
onTap: _pickNotificationTime,
),
if (_notifWeekday == null || _notifTime == null)
const Padding(
padding: EdgeInsets.only(top: 8),
child: Text(
'Hinweis: Bitte Wochentag und Uhrzeit wählen, damit die Erinnerung geplant wird.',
style: TextStyle(color: Colors.grey),
),
),
],
],
),
notifications
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:timezone/data/latest_all.dart' as tzdata;
static tz.TZDateTime _nextWeekdayTime({
required int weekday,
required int hour,
required int minute,
Duration grace = const Duration(seconds: 30),
}) {
final now = tz.TZDateTime.now(tz.local);
final todayAt = tz.TZDateTime(tz.local, now.year, now.month, now.day, hour, minute);
final daysUntil = (weekday - now.weekday) % 7;
var scheduled = todayAt.add(Duration(days: daysUntil));
if (scheduled.isBefore(now.add(grace))) {
scheduled = scheduled.add(const Duration(days: 7));
}
return scheduled;
}
static Future scheduleWeekly({
required int id,
required String title,
required String body,
required int weekday,
required int hour,
required int minute,
String? payload,
}) async {
final when = _nextWeekdayTime(weekday: weekday, hour: hour, minute: minute);
final mode = await _pickAndroidScheduleMode();
main
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:my_app/config/notifications.dart' show NotificationsService;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
tz.initializeTimeZones();
final name = await FlutterTimezone.getLocalTimezone(); // "Europe/Berlin" etc.
tz.setLocalLocation(tz.getLocation(name));
await NotificationsService.init();
AndroidManifest
What I’ve tried
-
Confirmed Notifications permission is granted (Android 13+).
-
Enabled Alarms & reminders (Schedule exact alarms) in system settings (Android 12+).
-
Tested with androidAllowWhileIdle: true.
-
Verified the channel is not blocked and importance is max.
-
Disabled battery optimizations for the app.
-
Tested on emulator and physical device.
-
Double-checked that the computed scheduled time is in the future and has the correct weekday.
-
Confirmed Notifications permission is granted (Android 13+).
-
Enabled Alarms & reminders (Schedule exact alarms) in system settings (Android 12+).
-
Tested with androidAllowWhileIdle: true.
-
Verified the channel is not blocked and importance is max.
-
Disabled battery optimizations for the app.
-
Tested on emulator and physical device.
-
Double-checked that the computed scheduled time is in the future and has the correct weekday.