diff --git a/example/SampleProject/test/widget_test.dart b/example/SampleProject/test/widget_test.dart deleted file mode 100644 index 3d372eb7..00000000 --- a/example/SampleProject/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:ant_media_flutter_example/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} diff --git a/lib/firebase_api.dart b/lib/firebase_api.dart new file mode 100644 index 00000000..f7205bb4 --- /dev/null +++ b/lib/firebase_api.dart @@ -0,0 +1,46 @@ +import 'package:firebase_messaging/firebase_messaging.dart'; + +// You can configure the firebase push notifications with flutter-fire (https://firebase.flutter.dev/docs/overview) after which you can use it in the example app like this: + +//import 'package:ant_media_flutter/firebase_api.dart'; + +// void main() async{ +// WidgetsFlutterBinding.ensureInitialized(); +// await Firebase.initializeApp( +// options: DefaultFirebaseOptions.currentPlatform, +// ); +// await FirebaseApi().initNotifications(); +// return runApp( +// const MaterialApp( +// home: MyApp(), +// debugShowCheckedModeBanner: false, +// ) +// ); +// } + + +Future<void> handleBackgroundMessage(RemoteMessage message) async { + print("Title: ${message.notification?.title}"); + print("Body: ${message.notification?.body}"); + print("Payload: ${message.data}"); +} + +Future<void> handleForegroundMessage(RemoteMessage message) async { + print("Title: ${message.notification?.title}"); + print("Body: ${message.notification?.body}"); + print("Payload: ${message.data}"); +} + +class FirebaseApi{ + + final _firebaseMessaging = FirebaseMessaging.instance; + + Future<void> initNotifications() async { + await _firebaseMessaging.requestPermission(); + final fCMToken = await _firebaseMessaging.getToken(); + print('Token: $fCMToken'); + await FirebaseMessaging.instance.subscribeToTopic("antmedia"); + FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage); + FirebaseMessaging.onMessage.listen(handleForegroundMessage); + } +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 1b84d05d..c8be58e4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,8 @@ dependencies: path_provider: ^2.0.11 path_provider_macos: ^2.0.7 flutter_background: ^1.2.0 + firebase_core: ^3.10.1 + firebase_messaging: ^15.1.6 dev_dependencies: flutter_test: