1
1
import 'dart:async' ;
2
-
2
+ import 'dart:convert' ;
3
+ import 'package:http/http.dart' as http;
3
4
import 'package:firebase_database/firebase_database.dart' ;
5
+ import 'package:firebase_messaging/firebase_messaging.dart' ;
4
6
import 'package:flutter/material.dart' ;
5
7
import 'package:flutter_twitter_clone/helper/utility.dart' ;
6
8
import 'package:firebase_database/firebase_database.dart' as dabase;
@@ -10,9 +12,12 @@ import 'package:flutter_twitter_clone/model/user.dart';
10
12
import 'package:flutter_twitter_clone/state/appState.dart' ;
11
13
12
14
class NotificationState extends AppState {
15
+ String fcmToken;
13
16
dabase.Query query;
14
17
List <User > userList = [];
15
18
19
+ final FirebaseMessaging _firebaseMessaging = FirebaseMessaging ();
20
+
16
21
List <NotificationModel > _notificationList;
17
22
18
23
List <NotificationModel > get notificationList => _notificationList;
@@ -137,4 +142,35 @@ class NotificationState extends AppState {
137
142
print ("Notification Removed" );
138
143
}
139
144
}
145
+
146
+ void initfirebaseService (){
147
+ _firebaseMessaging.configure (
148
+ onMessage: (Map <String , dynamic > message) async {
149
+ print ("onMessage: $message " );
150
+ // _showItemDialog(message);
151
+ },
152
+ onLaunch: (Map <String , dynamic > message) async {
153
+ print ("onLaunch: $message " );
154
+ // _navigateToItemDetail(message);
155
+ },
156
+ onResume: (Map <String , dynamic > message) async {
157
+ print ("onResume: $message " );
158
+ // _navigateToItemDetail(message);
159
+ },
160
+ );
161
+ _firebaseMessaging.requestNotificationPermissions (
162
+ const IosNotificationSettings (
163
+ sound: true , badge: true , alert: true , provisional: true ));
164
+ _firebaseMessaging.onIosSettingsRegistered
165
+ .listen ((IosNotificationSettings settings) {
166
+ print ("Settings registered: $settings " );
167
+ });
168
+ _firebaseMessaging.getToken ().then ((String token) {
169
+ assert (token != null );
170
+ fcmToken = token;
171
+ print (token);
172
+ });
173
+ }
174
+
175
+
140
176
}
0 commit comments