Za poslední dobu vyšlo několik verzí, mnoho návodů je nepoužitelných, protože jsou pro starou verzi.
flutter create -d android --org cz.inited --project-name vetrnik -t app --platforms android vetrnik
Změnit čísla v android/app/build.gradle
Návody, které zmiňují použití souboru google-services.json a úpravy v nativním kódu, jsou zastaralé.
Funguje následující:
flutter pub add firebase_core flutter pub add firebase_messaging
import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async { await Firebase.initializeApp(); print("Handling a background message: ${message.messageId}"); } Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: const FirebaseOptions( apiKey: 'AIzaSyAhPy01BP2IBy1ziA7wzREYLjFJD92yDkE', appId: '1:7198646019:android:10422f8d71216b5e691336', messagingSenderId: '7198646019', projectId: 'vetrnik-57f1f', ), ); FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); String? token = await FirebaseMessaging.instance.getToken(); print("Token:${token}:nekoT"); runApp(const MyApp()); } ...
#!/bin/bash curl -i -H 'Content-type: application/json' \ -H 'Authorization: key=AAAAAa0SnwM:APA91bElV5w7nVAJyWcPuY385I4YJ7tg.......' \ -X POST https://fcm.googleapis.com/fcm/send -d '{ "registration_ids":["foByPOF1TPWRrwN6MZ2feY:APA91bEEmoZnp-kz2pNuB......."], "notification": { "title":"Title of your notification", "body":"content of your notification" } }'