Skip to content

Commit 4402be9

Browse files
committed
OneSignal and CacheService updated
1 parent f94f03e commit 4402be9

File tree

5 files changed

+32
-40
lines changed

5 files changed

+32
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flutter Core
22

3-
Projelerinizde kullanabileceğiniz çekirdek katman. [ Update: 11.02.2025 ]
3+
Projelerinizde kullanabileceğiniz çekirdek katman. [ Update: 20.06.2025 ]
44

55
#
66

lib/core/media_services/video_service.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ class VideoService {
8080
return VideoPlayerController.file(sourceData);
8181
case VideoServiceType.asset:
8282
return VideoPlayerController.asset(sourceData);
83-
default:
84-
return VideoPlayerController.networkUrl(sourceData);
8583
}
8684
}
8785

lib/core/notification_services/onesignal_service.dart

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,56 @@
44
// ignore_for_file: avoid_print
55

66
import 'package:onesignal_flutter/onesignal_flutter.dart';
7-
import '../storage_services/cache_service.dart';
87

98
final oneSignalService = OneSignalService();
109

1110
class OneSignalService {
1211
final onesignalId = "YOUR_ONESIGNAL_ID";
1312

1413
Future<void> init() async {
15-
await OneSignal.shared.consentGranted(true);
16-
OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);
17-
await OneSignal.shared.setAppId(onesignalId);
14+
// OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
15+
// OneSignal.Debug.setAlertLevel(OSLogLevel.none);
16+
await OneSignal.consentRequired(false);
17+
OneSignal.initialize(onesignalId);
1818

19-
final accepted =
20-
await OneSignal.shared.promptUserForPushNotificationPermission();
19+
OneSignal.Notifications.clearAll();
20+
21+
final accepted = await OneSignal.Notifications.requestPermission(true);
2122
print("[C_OneSignal_Accepted]: $accepted");
2223
if (!accepted) return;
24+
await OneSignal.consentGiven(true);
2325

24-
OneSignal.shared.setSubscriptionObserver((changes) {
25-
print("[C_OneSignal_PlayerId]: ${changes.to.userId}");
26-
cacheService.box.put('playerId', changes.to.userId);
26+
OneSignal.User.pushSubscription.addObserver((stateChanges) {
27+
print("[C_PlayerId]: ${OneSignal.User.pushSubscription.id}");
2728
});
2829

2930
// Foreground
30-
OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
31+
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
3132
print("[C_OneSignal_Foreground_Title]: ${event.notification.title}");
3233
print("[C_OneSignal_Foreground_Body]: ${event.notification.body}");
3334
print(
3435
"[C_OneSignal_Foreground_Data]: ${event.notification.additionalData}");
3536

36-
event.complete(null);
37-
// event.complete(event.notification);
37+
event.preventDefault();
3838
});
3939

4040
// Opened
41-
OneSignal.shared.setNotificationOpenedHandler((openedResult) {
41+
OneSignal.Notifications.addClickListener((openedResult) {
4242
print("[C_OneSignal_Opened_Title]: ${openedResult.notification.title}");
4343
print("[C_OneSignal_Opened_Body]: ${openedResult.notification.body}");
4444
print(
4545
"[C_OneSignal_Opened_Data]: ${openedResult.notification.additionalData}");
46+
47+
// mainStore.notiData = openedResult.notification.additionalData;
4648
});
4749
}
4850

4951
Future<void> setExternalUserId(String externalUserId) async {
5052
await removeExternalUserId();
51-
OneSignal.shared.setExternalUserId(externalUserId).then((results) {
52-
print("[C_OneSignal_UserId]: $results");
53-
}).catchError((error) {
54-
print("[C_OneSignal_UserId_Error]: $error");
55-
});
53+
await OneSignal.login(externalUserId);
5654
}
5755

5856
Future<void> removeExternalUserId() async {
59-
await OneSignal.shared.removeExternalUserId();
57+
await OneSignal.logout();
6058
}
6159
}
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
// ignore_for_file: empty_catches
2-
3-
import 'dart:io';
4-
51
import 'package:hive_flutter/hive_flutter.dart';
6-
import 'package:path_provider/path_provider.dart';
72

83
final cacheService = CacheService();
94

@@ -12,25 +7,20 @@ class CacheService {
127
final String cacheName = "project_name_cache";
138

149
Future init() async {
15-
final dir = await getDir();
16-
await Hive.initFlutter(dir.path);
17-
box = await openBox(dir);
10+
await Hive.initFlutter();
11+
box = await openBox();
1812
}
1913

20-
Future<Box> openBox(Directory dir) async {
21-
return await Hive.openBox(cacheName, path: dir.path);
14+
Future<Box> openBox() async {
15+
return await Hive.openBox(cacheName);
2216
}
2317

2418
Future deleteBox() async {
2519
try {
26-
final dir = await getDir();
2720
await Hive.deleteBoxFromDisk(cacheName);
28-
box = await openBox(dir);
29-
} catch (e) {}
30-
}
31-
32-
Future<Directory> getDir() async {
33-
final appTemporaryDirectory = await getTemporaryDirectory();
34-
return Directory('${appTemporaryDirectory.path}/database');
21+
box = await openBox();
22+
} catch (e) {
23+
return false;
24+
}
3525
}
3626
}

lib/core/utils/extensions.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extension DateTimeExtension on DateTime {
1414
String get toISOStringUtc =>
1515
'${DateFormat("yyyy-MM-ddTHH:mm:ss").format(toUtc())}Z';
1616
String get toISOString => DateFormat("yyyy-MM-ddTHH:mm:ss").format(this);
17+
String get toISOStringDate => DateFormat("yyyy-MM-dd").format(this);
1718

1819
String toTimestamp() {
1920
final timestamp = millisecondsSinceEpoch.toString();
@@ -51,3 +52,8 @@ extension StringExtension on String {
5152
}
5253
}
5354
}
55+
56+
extension MapExtension on Map<String, dynamic> {
57+
dynamic get(String key, {dynamic defaultValue}) =>
58+
containsKey(key) ? this[key] : defaultValue;
59+
}

0 commit comments

Comments
 (0)