Skip to content

Commit 2504227

Browse files
authored
docs(firebase_messaging): Update sample code in Cloud Messaging - Server Integration. (#8241)
1 parent c9c7f82 commit 2504227

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/messaging/server-integration.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,24 @@ class Application extends StatefulWidget {
5151
class _Application extends State<Application> {
5252
String _token;
5353
54-
@override
55-
void initState() async {
56-
super.initState();
54+
Future<void> setupToken() async {
5755
// Get the token each time the application loads
58-
String token = await FirebaseMessaging.instance.getToken();
56+
String? token = await FirebaseMessaging.instance.getToken();
5957
6058
// Save the initial token to the database
61-
await saveTokenToDatabase(token);
59+
await saveTokenToDatabase(token!);
6260
6361
// Any time the token refreshes, store this in the database too.
6462
FirebaseMessaging.instance.onTokenRefresh.listen(saveTokenToDatabase);
6563
}
6664
65+
@override
66+
void initState() {
67+
super.initState();
68+
69+
setupToken();
70+
}
71+
6772
@override
6873
Widget build(BuildContext context) {
6974
return Text("...");

0 commit comments

Comments
 (0)