728x90
반응형
캘린더에 일정을 등록하는 것만으로는 부족하다.
알림까지 울려야 진짜 일정 관리가 된다.
이번 글에서는 flutter_local_notifications
패키지를 사용해 Flutter 앱에서 이벤트 알림 기능을 구현하는 방법을 살펴본다.
🔔 패키지 설치 및 설정
// pubspec.yaml
dependencies:
flutter_local_notifications: ^16.2.0
Android와 iOS 각각에 대해 설정이 다르기 때문에, 공식 문서를 참고하여 platform-specific 설정도 함께 해줘야 한다.
📦 기본 초기화
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
void initializeNotification() async {
const AndroidInitializationSettings androidSettings =
AndroidInitializationSettings('@mipmap/ic_launcher');
const InitializationSettings initSettings =
InitializationSettings(android: androidSettings);
await flutterLocalNotificationsPlugin.initialize(initSettings);
}
앱 실행 시 한 번 초기화를 해두면 알림 예약이 가능해진다.
🕒 특정 시간에 알림 예약
Future scheduleNotification({
required int id,
required String title,
required String body,
required DateTime scheduledTime,
}) async {
await flutterLocalNotificationsPlugin.zonedSchedule(
id,
title,
body,
tz.TZDateTime.from(scheduledTime, tz.local),
const NotificationDetails(
android: AndroidNotificationDetails(
'event_channel',
'Event Notifications',
importance: Importance.max,
priority: Priority.high,
),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.dateAndTime,
);
}
timezone
패키지를 함께 사용하면 정밀한 알림 예약이 가능하다.
📅 예시: 이벤트 등록 시 알림도 예약
// 예: 내일 오전 9시에 알림 설정
final eventTime = DateTime.now().add(Duration(days: 1)).copyWith(hour: 9, minute: 0);
scheduleNotification(
id: 1001,
title: '미팅 알림',
body: '오전 9시 회의가 있어요!',
scheduledTime: eventTime,
);
이벤트 ID를 기준으로 알림을 예약하면 나중에 수정/삭제도 관리할 수 있다.
📌 실전 팁
- 알림 ID는 메모/이벤트 ID와 연동해 관리
- 스케줄 변경 시
cancel(id)
후 다시 예약 - 앱이 꺼져 있어도 작동하도록 AndroidManifest 권한 추가 필요
🧘 마무리하며
알림은 단순한 기능이 아니다.
그건 사용자의 하루를 움직이는 트리거다.
Flutter로 만드는 캘린더 앱에 로컬 알림을 추가해보자. 기억이 아닌, 알림으로 일정이 완성된다.
✍️ 이 글은 터미널 밖으로 나온 개발자의 Flutter 캘린더 앱 만들기 여정입니다.
728x90
반응형
'Flutter > Flutter 캘린더 앱 만들기' 카테고리의 다른 글
이벤트 반복 설정 구현 — 매주, 매달 반복 어떻게 할까? (0) | 2025.06.04 |
---|---|
할 일 완료 체크 및 삭제 기능 추가 (2) | 2025.06.03 |
오늘 날짜 강조 및 마커 표시 기능 구현하기 (1) | 2025.06.01 |
주간/월간 보기 전환 — 다양한 뷰 모드 지원하기 (0) | 2025.05.31 |
이벤트 등록 기능 만들기 — 날짜에 할 일 연결하기 (0) | 2025.05.30 |