Reputation: 189
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);
},
);
}
Manifest:
<intent-filter>
<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'.
Upvotes: 19
Views: 18318
Reputation: 1
Use FirebaseStorage.instanceFor
instead of the default constructor
Upvotes: -1
Reputation: 29
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);
},
Upvotes: 2
Reputation: 1946
Try FirebaseMessaging.instance
instead of FirebaseMessaging()
, it should work.
Upvotes: 72