Initial commit: SubManager Flutter App
주요 구현 완료 기능: - 구독 관리 (추가/편집/삭제/카테고리 분류) - 이벤트 할인 시스템 (기본값 자동 설정) - SMS 자동 스캔 및 구독 정보 추출 - 알림 시스템 (타임존 처리 안정화) - 환율 변환 지원 (KRW/USD) - 반응형 UI 및 애니메이션 - 다국어 지원 (한국어/영어) 버그 수정: - NotificationService tz.local 초기화 오류 해결 - MainScreenSummaryCard 레이아웃 오버플로우 수정 - 구독 추가 시 LateInitializationError 완전 해결 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
263
lib/providers/notification_provider.dart
Normal file
263
lib/providers/notification_provider.dart
Normal file
@@ -0,0 +1,263 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../providers/subscription_provider.dart';
|
||||
|
||||
class NotificationProvider extends ChangeNotifier {
|
||||
final FlutterSecureStorage _secureStorage = const FlutterSecureStorage();
|
||||
static const String _paymentNotificationKey = 'payment_notification_enabled';
|
||||
static const String _unusedServiceNotificationKey =
|
||||
'unused_service_notification_enabled';
|
||||
static const String _reminderDaysKey = 'reminder_days';
|
||||
static const String _reminderHourKey = 'reminder_hour';
|
||||
static const String _reminderMinuteKey = 'reminder_minute';
|
||||
static const String _dailyReminderKey = 'daily_reminder_enabled';
|
||||
|
||||
bool _isEnabled = false;
|
||||
bool _isPaymentEnabled = false;
|
||||
bool _isUnusedServiceNotificationEnabled = false;
|
||||
int _reminderDays = 3; // 기본값: 3일 전
|
||||
int _reminderHour = 10; // 기본값: 오전 10시
|
||||
int _reminderMinute = 0; // 기본값: 0분
|
||||
bool _isDailyReminderEnabled = false; // 기본값: 반복 알림 비활성화
|
||||
|
||||
// 웹 플랫폼 여부 확인 (웹에서는 알림이 지원되지 않음)
|
||||
bool get _isWeb => kIsWeb;
|
||||
|
||||
// SubscriptionProvider 인스턴스 (알림 재예약 시 사용)
|
||||
SubscriptionProvider? _subscriptionProvider;
|
||||
|
||||
bool get isEnabled => _isEnabled;
|
||||
bool get isPaymentEnabled => _isPaymentEnabled;
|
||||
bool get isUnusedServiceNotificationEnabled =>
|
||||
_isUnusedServiceNotificationEnabled;
|
||||
int get reminderDays => _reminderDays;
|
||||
int get reminderHour => _reminderHour;
|
||||
int get reminderMinute => _reminderMinute;
|
||||
bool get isDailyReminderEnabled => _isDailyReminderEnabled;
|
||||
|
||||
NotificationProvider() {
|
||||
_loadSettings();
|
||||
}
|
||||
|
||||
// SubscriptionProvider 설정 (알림 재예약 시 사용)
|
||||
void setSubscriptionProvider(SubscriptionProvider provider) {
|
||||
_subscriptionProvider = provider;
|
||||
}
|
||||
|
||||
Future<void> _loadSettings() async {
|
||||
final paymentValue =
|
||||
await _secureStorage.read(key: _paymentNotificationKey);
|
||||
final unusedValue =
|
||||
await _secureStorage.read(key: _unusedServiceNotificationKey);
|
||||
final reminderDaysValue = await _secureStorage.read(key: _reminderDaysKey);
|
||||
final reminderHourValue = await _secureStorage.read(key: _reminderHourKey);
|
||||
final reminderMinuteValue =
|
||||
await _secureStorage.read(key: _reminderMinuteKey);
|
||||
final dailyReminderValue =
|
||||
await _secureStorage.read(key: _dailyReminderKey);
|
||||
|
||||
_isPaymentEnabled = paymentValue == 'true';
|
||||
_isUnusedServiceNotificationEnabled = unusedValue == 'true';
|
||||
_reminderDays =
|
||||
reminderDaysValue != null ? int.tryParse(reminderDaysValue) ?? 3 : 3;
|
||||
_reminderHour =
|
||||
reminderHourValue != null ? int.tryParse(reminderHourValue) ?? 10 : 10;
|
||||
_reminderMinute = reminderMinuteValue != null
|
||||
? int.tryParse(reminderMinuteValue) ?? 0
|
||||
: 0;
|
||||
_isDailyReminderEnabled = dailyReminderValue == 'true';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
try {
|
||||
_isEnabled = await NotificationService.isNotificationEnabled();
|
||||
_isPaymentEnabled =
|
||||
await NotificationService.isPaymentNotificationEnabled();
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('알림 설정 초기화 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setEnabled(bool value) async {
|
||||
try {
|
||||
_isEnabled = value;
|
||||
await NotificationService.setNotificationEnabled(value);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('알림 활성화 설정 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setPaymentEnabled(bool value) async {
|
||||
try {
|
||||
// 설정값이 변경된 경우에만 처리
|
||||
if (_isPaymentEnabled != value) {
|
||||
_isPaymentEnabled = value;
|
||||
await NotificationService.setPaymentNotificationEnabled(value);
|
||||
|
||||
// 웹에서는 알림 기능 비활성화
|
||||
if (_isWeb) {
|
||||
debugPrint('웹 플랫폼에서는 알림 기능이 지원되지 않습니다.');
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
// 알림이 활성화된 경우에만 알림 재예약 (비활성화 시에는 필요 없음)
|
||||
if (value) {
|
||||
// 알림 설정 변경 시 모든 구독의 알림 재예약
|
||||
// 지연 실행으로 UI 응답성 향상
|
||||
Future.microtask(() => _rescheduleNotificationsIfNeeded());
|
||||
} else {
|
||||
// 알림이 비활성화되면 모든 알림 취소
|
||||
try {
|
||||
await NotificationService.cancelAllNotifications();
|
||||
} catch (e) {
|
||||
debugPrint('알림 취소 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('결제 알림 설정 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setUnusedServiceNotificationEnabled(bool value) async {
|
||||
try {
|
||||
_isUnusedServiceNotificationEnabled = value;
|
||||
await _secureStorage.write(
|
||||
key: _unusedServiceNotificationKey,
|
||||
value: value.toString(),
|
||||
);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('미사용 서비스 알림 설정 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 알림 시점 설정 (1일전, 2일전, 3일전)
|
||||
Future<void> setReminderDays(int days) async {
|
||||
try {
|
||||
// 값이 변경된 경우에만 처리
|
||||
if (_reminderDays != days) {
|
||||
_reminderDays = days;
|
||||
await _secureStorage.write(
|
||||
key: _reminderDaysKey,
|
||||
value: days.toString(),
|
||||
);
|
||||
|
||||
// 웹에서는 알림 기능 비활성화
|
||||
if (_isWeb) {
|
||||
debugPrint('웹 플랫폼에서는 알림 기능이 지원되지 않습니다.');
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
// 1일 전으로 설정되면 반복 알림 자동 비활성화
|
||||
if (days == 1 && _isDailyReminderEnabled) {
|
||||
await setDailyReminderEnabled(false);
|
||||
} else if (_isPaymentEnabled) {
|
||||
// 알림이 활성화된 경우에만 처리
|
||||
// 알림 설정 변경 시 모든 구독의 알림 재예약 (백그라운드에서 처리)
|
||||
Future.microtask(() => _rescheduleNotificationsIfNeeded());
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('알림 시점 설정 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 알림 시간 설정
|
||||
Future<void> setReminderTime(int hour, int minute) async {
|
||||
try {
|
||||
// 값이 변경된 경우에만 처리
|
||||
if (_reminderHour != hour || _reminderMinute != minute) {
|
||||
_reminderHour = hour;
|
||||
_reminderMinute = minute;
|
||||
await _secureStorage.write(
|
||||
key: _reminderHourKey,
|
||||
value: hour.toString(),
|
||||
);
|
||||
await _secureStorage.write(
|
||||
key: _reminderMinuteKey,
|
||||
value: minute.toString(),
|
||||
);
|
||||
|
||||
// 웹에서는 알림 기능 비활성화
|
||||
if (_isWeb) {
|
||||
debugPrint('웹 플랫폼에서는 알림 기능이 지원되지 않습니다.');
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
// 알림이 활성화된 경우에만 처리
|
||||
if (_isPaymentEnabled) {
|
||||
// 알림 설정 변경 시 모든 구독의 알림 재예약 (백그라운드에서 처리)
|
||||
Future.microtask(() => _rescheduleNotificationsIfNeeded());
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('알림 시간 설정 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 반복 알림 설정
|
||||
Future<void> setDailyReminderEnabled(bool value) async {
|
||||
try {
|
||||
// 값이 변경된 경우에만 처리
|
||||
if (_isDailyReminderEnabled != value) {
|
||||
_isDailyReminderEnabled = value;
|
||||
await _secureStorage.write(
|
||||
key: _dailyReminderKey,
|
||||
value: value.toString(),
|
||||
);
|
||||
|
||||
// 웹에서는 알림 기능 비활성화
|
||||
if (_isWeb) {
|
||||
debugPrint('웹 플랫폼에서는 알림 기능이 지원되지 않습니다.');
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
|
||||
// 알림이 활성화된 경우에만 처리
|
||||
if (_isPaymentEnabled) {
|
||||
// 알림 설정 변경 시 모든 구독의 알림 재예약 (백그라운드에서 처리)
|
||||
Future.microtask(() => _rescheduleNotificationsIfNeeded());
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('반복 알림 설정 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 알림 설정 변경 시 모든 구독의 알림 일정 재예약
|
||||
Future<void> _rescheduleNotificationsIfNeeded() async {
|
||||
try {
|
||||
// 웹 플랫폼에서는 지원하지 않음
|
||||
if (_isWeb) {
|
||||
debugPrint('웹 플랫폼에서는 알림 기능이 지원되지 않습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 구독 목록을 가져올 수 있고, 알림이 활성화된 경우에만 재예약
|
||||
if (_subscriptionProvider != null && _isPaymentEnabled) {
|
||||
final subscriptions = _subscriptionProvider!.subscriptions;
|
||||
await NotificationService.reschedulAllNotifications(subscriptions);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('알림 재예약 중 오류 발생: $e');
|
||||
// 오류가 발생해도 앱 동작에 영향을 주지 않도록 처리
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user