Scheduled Notifications in Flutter — Setting Up Timed Alerts
FlutterPulseThis article was translated specially for the channel FlutterPulseYou'll find lots of interesting things related to Flutter on this channel. Don't hesitate to subscribe!🚀

Notifications are a crucial part of any app, but what if you want to send alerts at a specific time? With scheduled notifications, you can:
✅ Send reminders for tasks, events, or deadlines.
✅ Trigger daily notifications at a set time (e.g., a morning motivational quote).
✅ Schedule one-time or recurring notifications for better user engagement.
In this guide, we'll implement scheduled notifications in Flutter using the flutter_local_notifications package. 🚀
Step 1: Install Dependencies
In your pubspec.yaml, add:
dependencies:
flutter_local_notifications: latest_version
timezone: latest_version
Run:
flutter pub get
Step 2: Configure Local Notifications
2.1 Initialize Notification Plugin
Modify main.dart:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initializeNotifications();
runApp(MyApp());
}
Future<void> initializeNotifications() async {
const AndroidInitializationSettings androidSettings =
AndroidInitializationSettings('@mipmap/ic_launcher');
final InitializationSettings initSettings = InitializationSettings(
android: androidSettings,
);
await flutterLocalNotificationsPlugin.initialize(initSettings);
}Step 3: Set Up Timezone Support
Since scheduled notifications require accurate time zones, configure the timezone package:
3.1 Add Timezone Setup
Modify main.dart:
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
Future<void> setupTimezone() async {
tz.initializeTimeZones();
tz.setLocalLocation(tz.getLocation('Asia/Kolkata')); // Change to your timezone
}
Call setupTimezone() inside initializeNotifications().
Step 4: Schedule a Notification
4.1 Function to Schedule a Notification
Create a function that triggers a one-time notification at a specific time:
Future<void> scheduleNotification() async {
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
"Scheduled Alert",
"This is your reminder!",
_nextInstanceOfTime(10, 0), // Schedule for 10:00 AM
const NotificationDetails(
android: AndroidNotificationDetails(
'scheduled_channel_id',
'Scheduled Notifications',
importance: Importance.high,
priority: Priority.high,
),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
}
tz.TZDateTime _nextInstanceOfTime(int hour, int minute) {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduledDate =
tz.TZDateTime(tz.local, now.year, now.month, now.day, hour, minute);
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(Duration(days: 1)); // Next day
}
return scheduledDate;
}Call scheduleNotification() when the user sets a reminder.
Step 5: Scheduling Recurring Notifications
5.1 Daily Notification at a Fixed Time
Future<void> scheduleDailyNotification() async {
await flutterLocalNotificationsPlugin.zonedSchedule(
1,
"Daily Reminder",
"Don't forget to check your progress!",
_nextInstanceOfTime(8, 0), // Every day at 8:00 AM
const NotificationDetails(
android: AndroidNotificationDetails(
'daily_channel_id',
'Daily Notifications',
importance: Importance.high,
priority: Priority.high,
),
),
androidAllowWhileIdle: true,
matchDateTimeComponents: DateTimeComponents.time,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
}5.2 Weekly Notification (e.g., every Monday at 9:00 AM)
Future<void> scheduleWeeklyNotification() async {
await flutterLocalNotificationsPlugin.zonedSchedule(
2,
"Weekly Check-in",
"Time for your weekly review!",
_nextInstanceOfWeekday(1, 9, 0), // Monday at 9:00 AM
const NotificationDetails(
android: AndroidNotificationDetails(
'weekly_channel_id',
'Weekly Notifications',
importance: Importance.high,
priority: Priority.high,
),
),
androidAllowWhileIdle: true,
matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
}
tz.TZDateTime _nextInstanceOfWeekday(int weekday, int hour, int minute) {
tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduledDate =
tz.TZDateTime(tz.local, now.year, now.month, now.day, hour, minute);
while (scheduledDate.weekday != weekday) {
scheduledDate = scheduledDate.add(Duration(days: 1));
}
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(Duration(days: 7));
}
return scheduledDate;
}Step 6: Cancel Scheduled Notifications
To allow users to manage their reminders, you can cancel:
🔹 A specific notification:
await flutterLocalNotificationsPlugin.cancel(0);
🔹 All scheduled notifications:
await flutterLocalNotificationsPlugin.cancelAll();
Step 7: Testing Scheduled Notifications
7.1 Test on Emulator/Device
To verify notifications:
1️⃣ Schedule a test notification:
scheduleNotification(); // Calls the function from Step 4.1
2️⃣ Run your app, then put it in the background or lock the device.
3️⃣ Wait for the scheduled time, and you should see the notification appear.
7.2 Debugging Issues
🔹 Ensure flutter_local_notifications and timezone are properly configured.
🔹 Confirm that notifications are enabled on the device.
🔹 Check log output for errors:
flutter run --verbose
Conclusion
🎉 You've successfully implemented scheduled notifications in Flutter! Now your app can:
✅ Send reminders at specific times.
✅ Schedule daily & weekly notifications.
✅ Cancel scheduled notifications dynamically.
🔥 What's Next?
- Add local storage to allow users to manage notifications.
- Implement custom sounds and rich media in scheduled alerts.
- Integrate with Google Calendar API for event-based notifications.
Have questions? Drop a comment! 🚀 Keep building amazing Flutter apps! 💙
If you found this story helpful, you can support me at Buy Me a Coffee!