import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class PushNotificationService
{
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
Future initialize(context) async
{
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
},
onLaunch: (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
},
onResume: (Map<String, dynamic> message) async {
retrieveRideRequestInfo(getRideRequestId(message), context);
},
);
}
<intent-filter> //maifest
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT"
/>
</intent-filter>
Error: The class 'FirebaseMessaging' doesn't have a default constructor. Try using one of the named constructors defined in 'FirebaseMessaging'.
Try FirebaseMessaging.instance
instead of FirebaseMessaging()
, it should work.
try to add add dependencies firebase_core 1.4.0
import 'package:firebase_core/firebase_core.dart';
@override
void initState() {
// TODO: implement initState
super.initState();
Firebase.initializeApp();
}
onPressed: () async {
String token = await FirebaseMessaging.instance.getToken();
print(token);
},
use FirebaseStorage.instanceFor instead of the default constructor it's work for me
Use older version of FirebaseMessaging as i used firebase_messaging: ^4.0.0+1. It works for me.. Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.