This commit is contained in:
Efril 2026-05-07 18:03:41 +07:00
parent dc09aabbe8
commit 842b7a5041
3 changed files with 16 additions and 89 deletions

View File

@ -10,6 +10,8 @@
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<!-- Izin khusus untuk akses foto (media images) di Android 33 ke atas --> <!-- Izin khusus untuk akses foto (media images) di Android 33 ke atas -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<!-- Izin notifikasi untuk Android 13+ -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application <application
android:label="Apskel POS" android:label="Apskel POS"
android:name="${applicationName}" android:name="${applicationName}"
@ -41,6 +43,13 @@
<meta-data <meta-data
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
<!-- FCM: default notification icon dan channel -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
</application> </application>
<!-- Required to query activities that can process text, see: <!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and https://developer.android.com/training/package-visibility and

View File

@ -1,87 +0,0 @@
// CONTOH PENGGUNAAN FCM SERVICE
// File ini hanya untuk referensi, tidak perlu diimport ke app
import 'package:apskel_pos_flutter_v2/common/service/fcm_service.dart';
import 'package:apskel_pos_flutter_v2/injection.dart';
/// Contoh 1: Ambil FCM token
Future<void> exampleGetToken() async {
final fcmService = getIt<FcmService>();
final token = await fcmService.getToken();
print('FCM Token: $token');
// Kirim token ke server untuk push notification
// await apiClient.sendTokenToServer(token);
}
/// Contoh 2: Subscribe ke topic
Future<void> exampleSubscribeToTopic() async {
final fcmService = getIt<FcmService>();
// Subscribe ke topic "all_users"
await fcmService.subscribeToTopic('all_users');
// Subscribe ke topic berdasarkan outlet_id
await fcmService.subscribeToTopic('outlet_123');
}
/// Contoh 3: Unsubscribe dari topic
Future<void> exampleUnsubscribeFromTopic() async {
final fcmService = getIt<FcmService>();
await fcmService.unsubscribeFromTopic('outlet_123');
}
/// Contoh 4: Gunakan di BLoC
///
/// class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
/// final FcmService _fcmService;
///
/// NotificationBloc(this._fcmService) : super(NotificationInitial()) {
/// on<GetFcmToken>(_onGetFcmToken);
/// on<SubscribeToTopic>(_onSubscribeToTopic);
/// }
///
/// Future<void> _onGetFcmToken(
/// GetFcmToken event,
/// Emitter<NotificationState> emit,
/// ) async {
/// final token = await _fcmService.getToken();
/// emit(NotificationTokenLoaded(token));
/// }
///
/// Future<void> _onSubscribeToTopic(
/// SubscribeToTopic event,
/// Emitter<NotificationState> emit,
/// ) async {
/// await _fcmService.subscribeToTopic(event.topic);
/// emit(NotificationTopicSubscribed(event.topic));
/// }
/// }
/// Contoh 5: Gunakan di Repository
///
/// @LazySingleton(as: IAuthRepository)
/// class AuthRepository implements IAuthRepository {
/// final FcmService _fcmService;
/// final ApiClient _apiClient;
///
/// AuthRepository(this._fcmService, this._apiClient);
///
/// @override
/// Future<Either<Failure, User>> login(String email, String password) async {
/// try {
/// final response = await _apiClient.login(email, password);
///
/// // Kirim FCM token ke server setelah login berhasil
/// final fcmToken = await _fcmService.getToken();
/// if (fcmToken != null) {
/// await _apiClient.updateFcmToken(fcmToken);
/// }
///
/// return Right(response);
/// } catch (e) {
/// return Left(ServerFailure(e.toString()));
/// }
/// }
/// }

View File

@ -67,6 +67,7 @@ class FcmService {
'High Importance Notifications', 'High Importance Notifications',
description: 'This channel is used for important notifications.', description: 'This channel is used for important notifications.',
importance: Importance.high, importance: Importance.high,
playSound: true,
); );
await _localNotifications await _localNotifications
@ -146,9 +147,13 @@ class FcmService {
'high_importance_channel', 'high_importance_channel',
'High Importance Notifications', 'High Importance Notifications',
channelDescription: 'This channel is used for important notifications.', channelDescription: 'This channel is used for important notifications.',
importance: Importance.high, importance: Importance.max,
priority: Priority.high, priority: Priority.max,
showWhen: true, showWhen: true,
playSound: true,
enableVibration: true,
enableLights: true,
fullScreenIntent: true,
icon: 'ic_notification', icon: 'ic_notification',
); );