@@ -30,8 +30,9 @@ class MainScreenState extends State<MainScreen> {
30
30
MainScreenState ({Key key, @required this .currentUserId});
31
31
32
32
final String currentUserId;
33
- final FirebaseMessaging firebaseMessaging = new FirebaseMessaging ();
34
- final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin ();
33
+ final FirebaseMessaging firebaseMessaging = FirebaseMessaging ();
34
+ final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
35
+ FlutterLocalNotificationsPlugin ();
35
36
final GoogleSignIn googleSignIn = GoogleSignIn ();
36
37
37
38
bool isLoading = false ;
@@ -52,7 +53,9 @@ class MainScreenState extends State<MainScreen> {
52
53
53
54
firebaseMessaging.configure (onMessage: (Map <String , dynamic > message) {
54
55
print ('onMessage: $message ' );
55
- showNotification (message['notification' ]);
56
+ Platform .isAndroid
57
+ ? showNotification (message['notification' ])
58
+ : showNotification (message['aps' ]['alert' ]);
56
59
return ;
57
60
}, onResume: (Map <String , dynamic > message) {
58
61
print ('onResume: $message ' );
@@ -64,30 +67,38 @@ class MainScreenState extends State<MainScreen> {
64
67
65
68
firebaseMessaging.getToken ().then ((token) {
66
69
print ('token: $token ' );
67
- Firestore .instance.collection ('users' ).document (currentUserId).updateData ({'pushToken' : token});
70
+ Firestore .instance
71
+ .collection ('users' )
72
+ .document (currentUserId)
73
+ .updateData ({'pushToken' : token});
68
74
}).catchError ((err) {
69
75
Fluttertoast .showToast (msg: err.message.toString ());
70
76
});
71
77
}
72
78
73
79
void configLocalNotification () {
74
- var initializationSettingsAndroid = new AndroidInitializationSettings ('app_icon' );
80
+ var initializationSettingsAndroid =
81
+ new AndroidInitializationSettings ('app_icon' );
75
82
var initializationSettingsIOS = new IOSInitializationSettings ();
76
- var initializationSettings = new InitializationSettings (initializationSettingsAndroid, initializationSettingsIOS);
83
+ var initializationSettings = new InitializationSettings (
84
+ initializationSettingsAndroid, initializationSettingsIOS);
77
85
flutterLocalNotificationsPlugin.initialize (initializationSettings);
78
86
}
79
87
80
88
void onItemMenuPress (Choice choice) {
81
89
if (choice.title == 'Log out' ) {
82
90
handleSignOut ();
83
91
} else {
84
- Navigator .push (context, MaterialPageRoute (builder: (context) => Settings ()));
92
+ Navigator .push (
93
+ context, MaterialPageRoute (builder: (context) => Settings ()));
85
94
}
86
95
}
87
96
88
97
void showNotification (message) async {
89
98
var androidPlatformChannelSpecifics = new AndroidNotificationDetails (
90
- Platform .isAndroid ? 'com.dfa.flutterchatdemo' : 'com.duytq.flutterchatdemo' ,
99
+ Platform .isAndroid
100
+ ? 'com.dfa.flutterchatdemo'
101
+ : 'com.duytq.flutterchatdemo' ,
91
102
'Flutter chat demo' ,
92
103
'your channel description' ,
93
104
playSound: true ,
@@ -96,11 +107,20 @@ class MainScreenState extends State<MainScreen> {
96
107
priority: Priority .High ,
97
108
);
98
109
var iOSPlatformChannelSpecifics = new IOSNotificationDetails ();
99
- var platformChannelSpecifics =
100
- new NotificationDetails (androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
101
- await flutterLocalNotificationsPlugin.show (
102
- 0 , message['title' ].toString (), message['body' ].toString (), platformChannelSpecifics,
110
+ var platformChannelSpecifics = new NotificationDetails (
111
+ androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
112
+
113
+ print (message);
114
+ // print(message['body'].toString());
115
+ // print(json.encode(message));
116
+
117
+ await flutterLocalNotificationsPlugin.show (0 , message['title' ].toString (),
118
+ message['body' ].toString (), platformChannelSpecifics,
103
119
payload: json.encode (message));
120
+
121
+ // await flutterLocalNotificationsPlugin.show(
122
+ // 0, 'plain title', 'plain body', platformChannelSpecifics,
123
+ // payload: 'item x');
104
124
}
105
125
106
126
Future <bool > onBackPress () {
@@ -113,7 +133,8 @@ class MainScreenState extends State<MainScreen> {
113
133
context: context,
114
134
builder: (BuildContext context) {
115
135
return SimpleDialog (
116
- contentPadding: EdgeInsets .only (left: 0.0 , right: 0.0 , top: 0.0 , bottom: 0.0 ),
136
+ contentPadding:
137
+ EdgeInsets .only (left: 0.0 , right: 0.0 , top: 0.0 , bottom: 0.0 ),
117
138
children: < Widget > [
118
139
Container (
119
140
color: themeColor,
@@ -132,7 +153,10 @@ class MainScreenState extends State<MainScreen> {
132
153
),
133
154
Text (
134
155
'Exit app' ,
135
- style: TextStyle (color: Colors .white, fontSize: 18.0 , fontWeight: FontWeight .bold),
156
+ style: TextStyle (
157
+ color: Colors .white,
158
+ fontSize: 18.0 ,
159
+ fontWeight: FontWeight .bold),
136
160
),
137
161
Text (
138
162
'Are you sure to exit app?' ,
@@ -156,7 +180,8 @@ class MainScreenState extends State<MainScreen> {
156
180
),
157
181
Text (
158
182
'CANCEL' ,
159
- style: TextStyle (color: primaryColor, fontWeight: FontWeight .bold),
183
+ style: TextStyle (
184
+ color: primaryColor, fontWeight: FontWeight .bold),
160
185
)
161
186
],
162
187
),
@@ -176,7 +201,8 @@ class MainScreenState extends State<MainScreen> {
176
201
),
177
202
Text (
178
203
'YES' ,
179
- style: TextStyle (color: primaryColor, fontWeight: FontWeight .bold),
204
+ style: TextStyle (
205
+ color: primaryColor, fontWeight: FontWeight .bold),
180
206
)
181
207
],
182
208
),
@@ -205,8 +231,9 @@ class MainScreenState extends State<MainScreen> {
205
231
isLoading = false ;
206
232
});
207
233
208
- Navigator .of (context)
209
- .pushAndRemoveUntil (MaterialPageRoute (builder: (context) => MyApp ()), (Route <dynamic > route) => false );
234
+ Navigator .of (context).pushAndRemoveUntil (
235
+ MaterialPageRoute (builder: (context) => MyApp ()),
236
+ (Route <dynamic > route) => false );
210
237
}
211
238
212
239
@override
@@ -262,7 +289,8 @@ class MainScreenState extends State<MainScreen> {
262
289
} else {
263
290
return ListView .builder (
264
291
padding: EdgeInsets .all (10.0 ),
265
- itemBuilder: (context, index) => buildItem (context, snapshot.data.documents[index]),
292
+ itemBuilder: (context, index) =>
293
+ buildItem (context, snapshot.data.documents[index]),
266
294
itemCount: snapshot.data.documents.length,
267
295
);
268
296
}
@@ -275,7 +303,9 @@ class MainScreenState extends State<MainScreen> {
275
303
child: isLoading
276
304
? Container (
277
305
child: Center (
278
- child: CircularProgressIndicator (valueColor: AlwaysStoppedAnimation <Color >(themeColor)),
306
+ child: CircularProgressIndicator (
307
+ valueColor:
308
+ AlwaysStoppedAnimation <Color >(themeColor)),
279
309
),
280
310
color: Colors .white.withOpacity (0.8 ),
281
311
)
@@ -302,7 +332,8 @@ class MainScreenState extends State<MainScreen> {
302
332
placeholder: (context, url) => Container (
303
333
child: CircularProgressIndicator (
304
334
strokeWidth: 1.0 ,
305
- valueColor: AlwaysStoppedAnimation <Color >(themeColor),
335
+ valueColor:
336
+ AlwaysStoppedAnimation <Color >(themeColor),
306
337
),
307
338
width: 50.0 ,
308
339
height: 50.0 ,
@@ -359,7 +390,8 @@ class MainScreenState extends State<MainScreen> {
359
390
},
360
391
color: greyColor2,
361
392
padding: EdgeInsets .fromLTRB (25.0 , 10.0 , 25.0 , 10.0 ),
362
- shape: RoundedRectangleBorder (borderRadius: BorderRadius .circular (10.0 )),
393
+ shape:
394
+ RoundedRectangleBorder (borderRadius: BorderRadius .circular (10.0 )),
363
395
),
364
396
margin: EdgeInsets .only (bottom: 10.0 , left: 5.0 , right: 5.0 ),
365
397
);
0 commit comments