Skip to content

Commit

Permalink
update @pragma('vm:entry-point')
Browse files Browse the repository at this point in the history
  • Loading branch information
afni.afdillah@live.com authored and afni.afdillah@live.com committed Jul 28, 2024
1 parent 0954a78 commit a2f34e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 47 deletions.
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'services/local_storage_service.dart';

final navigatorKey = GlobalKey<NavigatorState>();

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
LoggerService.logger.i('Handling a background message: ${message.messageId}');
if (message.data.isNotEmpty) {
Expand All @@ -37,12 +38,12 @@ void main() async {
} catch (error) {
LoggerService.logger.e(error);
} finally {
if (!kIsWeb) {
// Initialize Firebase App Messaging
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
name: 'BaFiA_PushNotif',
);
if (!kIsWeb) {
await ApiFirebase().initNotifications();
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/services/api_firebase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:url_launcher/url_launcher.dart';
import '../main.dart';
import 'local_storage_service.dart';
//import 'package:url_launcher/url_launcher.dart';
//import '../main.dart';
//import 'local_storage_service.dart';
import 'logger_service.dart';

class ApiFirebase {
Expand Down Expand Up @@ -57,7 +57,7 @@ class ApiFirebase {
LoggerService.logger.i('Subscribed to topic: bafia-info');
}

Future<void> handleMessage(RemoteMessage? message) async {
/* Future<void> handleMessage(RemoteMessage? message) async {
if (message == null) return;
final link = message.data['link'];
Expand Down Expand Up @@ -97,5 +97,5 @@ class ApiFirebase {
}
});
}
}
} */
}
14 changes: 14 additions & 0 deletions lib/services/bg_worker_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:workmanager/workmanager.dart';
import 'logger_service.dart';
import 'local_storage_service.dart';

void callbackDispatcher() {
Workmanager().executeTask((task, inputData) async {
LoggerService.logger.i('Handling a background task: $task');
if (inputData != null && inputData.isNotEmpty) {
LoggerService.logger.i('Task also contained data: $inputData');
await LocalStorageService.saveMessageData(inputData);
}
return Future.value(true);
});
}
48 changes: 8 additions & 40 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
dbus:
dependency: transitive
description:
name: dbus
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
url: "https://pub.dev"
source: hosted
version: "0.7.10"
dev_build:
dependency: transitive
description:
Expand Down Expand Up @@ -286,30 +278,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: "0a9068149f0225e81642b03562e99776106edbd967816ee68bc16310d457c60e"
url: "https://pub.dev"
source: hosted
version: "17.2.1+1"
flutter_local_notifications_linux:
dependency: transitive
description:
name: flutter_local_notifications_linux
sha256: "33f741ef47b5f63cc7f78fe75eeeac7e19f171ff3c3df054d84c1e38bedb6a03"
url: "https://pub.dev"
source: hosted
version: "4.0.0+1"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
name: flutter_local_notifications_platform_interface
sha256: "85f8d07fe708c1bdcf45037f2c0109753b26ae077e9d9e899d55971711a4ea66"
url: "https://pub.dev"
source: hosted
version: "7.2.0"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -858,14 +826,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
timezone:
dependency: transitive
description:
name: timezone
sha256: "2236ec079a174ce07434e89fcd3fcda430025eb7692244139a9cf54fdcf1fc7d"
url: "https://pub.dev"
source: hosted
version: "0.9.4"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -962,6 +922,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.1"
workmanager:
dependency: "direct main"
description:
name: workmanager
sha256: ed13530cccd28c5c9959ad42d657cd0666274ca74c56dea0ca183ddd527d3a00
url: "https://pub.dev"
source: hosted
version: "0.5.2"
xdg_directories:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies:
path: ^1.9.0
firebase_core: ^3.2.0
firebase_messaging: ^15.0.3
flutter_local_notifications: ^17.2.1+1
#flutter_local_notifications: ^17.2.1+1
intl: ^0.19.0
syncfusion_flutter_gauges: ^26.1.41
image_picker: ^1.1.2
Expand All @@ -62,6 +62,7 @@ dependencies:
flutter_pdfview: ^1.3.2
printing: ^5.13.1
pdf: ^3.11.0
workmanager: ^0.5.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit a2f34e1

Please sign in to comment.