[Flutter/dart] Send a test message of Firebase Messaging
Overview
When you use Firebase Messaging, you'll want to send a test to your device.
It took a little time, so I will summarize how to do it.
Method
How to send a test message
Test messages are created in Cloud Messaging> Create Notifications in the Firebase console. Enter the "Notification Title" and "Notification Text" appropriately, and click "Send Test Message" on the right side. This will bring up a screen where you can enter your FCM token. If you enter the token of your device here, you can send a message only to that device.
get token
Here's how to get a token with dart. This process is executed when the app is launched to get the token of the device.
import 'package:firebase_messaging/firebase_messaging.dart';
final messaging=FirebaseMessaging.instance;
String _token=await messaging.getToken();
Enter this value in the previous console and send the message.
Caution
By default, you will not be notified when the app is running in the foreground.
Put the app in the background for confirmation.
(I didn't notice this and spent a lot of wasted time.)
Lastly
In the case where you send a message only to specific users who meet certain conditions, it is necessary to obtain the token once using the above method as well.
Recent Posts
See AllWhat want to do I want to create an input form using TextField. For example, if the input content is a monetary amount, I would like to...
What want to do There is a variable that remain unchanged once the initial value is determined. However, it cannot be determined yet when...
What want to do As the title suggests. Place two widgets in one line on the screen One in the center of the screen and the other on the...
Comments