'Use Firebase Cloud Messaging in a Flutter Windows app
I have checked both firebase_dart and flutterfire packages but none of them provide a firebase FirebaseMessaging class to use. Is there any way I can use Cloud Messaging in my Flutter Windows app? I want to listen to events from the console in the app and send a Windows notification using the event data.
Solution 1:[1]
There is no support for this platform yet. You can follow the progress of this development here.
One way to send notification is by http request (call this class to send notification)
import 'dart:async';
import 'dart:convert' show Encoding, json; import 'package:http/http.dart' as http;
class PostCall {
Future makeCall({token,nome,status}) async { const postUrl = 'https://fcm.googleapis.com/fcm/send';
final data = {
"notification": {"body": status, "title": name},
"priority": "high",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done"
},
"to": token
};
final headers = {
'content-type': 'application/json',
'Authorization': 'key=YOUR_SERVICE_KEY_FROM_FIREBASE'
};
final response = await http.post(Uri.parse(postUrl),
body: json.encode(data),
encoding: Encoding.getByName('utf-8'),
headers: headers);
if (response.statusCode == 200) {
// on success do sth
return true;
} else {
// on failure do sth
return false;
}
} }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Allysson Mastrangelo |
