I need to make an Android app where the user can receive notifications whenever I send them in the Firebase Cloud Messaging console. I am building it with Flutter.
I have gone through all the setup and I think the app is correctly connecting to Firebase, because there are no error logs.
However, when I send messages via Firebase, my app (which is running on local emulator) doesn't show any notifications.
This is the code of my app.
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:joves_lectors/webview_container.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Future<void> initFirebaseMessaging() async {
print(await FirebaseMessaging.instance.getInitialMessage());
FirebaseMessaging.onMessage.listen((message) {
if(message.notification != null) {
print(message.notification.body);
print(message.notification.title);
}
});
}
@override
void initState() {
super.initState();
print(FirebaseMessaging.instance.pluginConstants);
print(FirebaseMessaging.instance.isSupported());
initFirebaseMessaging();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Text("Hello")//WebViewContainer("https://jornades.joveslectors.cat"),
);
}
}
If I go to the Firebase console and send a Cloud Message notification, nothing happens. I've been trying to debug the problem, but I don't know how I can check that my app is connected to Firebase Messaging. I don't get any error messages. This is what my console prints:
I/flutter ( 7980): {AUTO_INIT_ENABLED: true}
I/flutter ( 7980): true
I/flutter ( 7980): null
I don't know if I am missing any steps or making any mistake with my code.
These are my dependencies:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
webview_flutter: ^2.0.9
firebase_core: ^1.3.0
firebase_messaging: ^10.0.2
flutter_local_notifications: ^6.0.0