-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
88 lines (74 loc) · 2.83 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'dart:async';
import 'package:blueshift_flutter_plugin_example/pages/inbox_page.dart';
import 'package:blueshift_plugin/blueshift_plugin.dart';
import 'package:blueshift_flutter_plugin_example/pages/deeplink_page.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
import 'pages/home_page.dart';
import 'pages/login_page.dart';
import 'utils/routes.dart';
Future<void> _handleRemoteMessage(RemoteMessage message) async {
print("Push Notification recieved on the Flutter");
Blueshift.handlePushNotification(message.data);
}
Future<void> main() async {
initialiseFirebase();
runApp(MyApp());
}
Future<void> initialiseFirebase() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: 'project-62519831960',
options: DefaultFirebaseOptions.currentPlatform,
);
// https://github.com/firebase/flutterfire/issues/6011
await FirebaseMessaging.instance.getToken();
// listen for notification while the app is in background or terminated.
FirebaseMessaging.onBackgroundMessage(_handleRemoteMessage);
var _messaging = FirebaseMessaging.instance;
String? token = await _messaging.getToken();
print("The firebase token is " + (token ?? "NA"));
String? APNStoken = await _messaging.getAPNSToken();
print("The APNS token is " + (APNStoken ?? "NA"));
// For handling the received notifications
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("Firebase push clicked");
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
_handleRemoteMessage(message);
});
Blueshift.getInstance.oniOSPushNotificationClick.listen((Object payload) {
print("Blueshift iOS Push Notification recieved on the Flutter");
print(payload);
});
//iOS config - Show push notification when app is running in foreground
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification
badge: true,
sound: true,
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.light,
theme: ThemeData(primarySwatch: Colors.blue),
darkTheme:
ThemeData(brightness: Brightness.dark, primarySwatch: Colors.grey),
// initialRoute: "/home",
routes: {
"/": (context) => const LoginPage(),
MyRoutes.loginRoute: (context) => const LoginPage(),
MyRoutes.homeRoute: (context) => const MyHomePage(),
MyRoutes.inboxRoute: (context) => InboxPage(),
MyRoutes.deeplinkRoute: (context) => DeeplinkPage(
deeplink: '',
),
},
);
}
}