fix fcm
This commit is contained in:
parent
dc09aabbe8
commit
842b7a5041
@ -10,6 +10,8 @@
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<!-- Izin khusus untuk akses foto (media images) di Android 33 ke atas -->
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<!-- Izin notifikasi untuk Android 13+ -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<application
|
||||
android:label="Apskel POS"
|
||||
android:name="${applicationName}"
|
||||
@ -41,6 +43,13 @@
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
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>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
||||
@ -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()));
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
@ -67,6 +67,7 @@ class FcmService {
|
||||
'High Importance Notifications',
|
||||
description: 'This channel is used for important notifications.',
|
||||
importance: Importance.high,
|
||||
playSound: true,
|
||||
);
|
||||
|
||||
await _localNotifications
|
||||
@ -146,9 +147,13 @@ class FcmService {
|
||||
'high_importance_channel',
|
||||
'High Importance Notifications',
|
||||
channelDescription: 'This channel is used for important notifications.',
|
||||
importance: Importance.high,
|
||||
priority: Priority.high,
|
||||
importance: Importance.max,
|
||||
priority: Priority.max,
|
||||
showWhen: true,
|
||||
playSound: true,
|
||||
enableVibration: true,
|
||||
enableLights: true,
|
||||
fullScreenIntent: true,
|
||||
icon: 'ic_notification',
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user