Firebase messaging not working [not receiving notfications] but app connected to firebase #8257
              
                Unanswered
              
          
                  
                    
                      kavyabhargava
                    
                  
                
                  asked this question in
                General
              
            Replies: 0 comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I was following a tutorial for Firebase push notifications. I followed all the steps: Connecting app to Firebase, and importing packages (Firebase messaging and Firebase push notifications). I tried sending several notifications, but it did not work.
I know my app is connected to Firebase as I am receiving data from Cloud Firestore. Authentication also works and I am also able to write data to storage:
My main.dart:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
// Added actual values
options: const FirebaseOptions(
apiKey: "have added this ",
appId: "have added this",
messagingSenderId: "have added this",
projectId: "have added this",
storageBucket: "have added this",
),
);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@OverRide
State createState() => _MyAppState();
}
class _MyAppState extends State {
@OverRide
void initState() {
super.initState();
FirebaseMessaging.instance
.getInitialMessage(); /this helps code below work great
FirebaseMessaging.onMessage.listen((message) {
if (message.notification != null) {
print(message.notification!.body);
print(message.notification!.title);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
final routeFromMessage = message.data['route'];
print(routeFromMessage);
});
}
@OverRide
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => GoogleSignInProvider(),
child: OverlaySupport(
child: MaterialApp(
title: 'News_App_admin',
theme: ThemeData(
buttonTheme: const ButtonThemeData(minWidth: 80),
primarySwatch: Colors.blue,
secondaryHeaderColor: const Color.fromARGB(255, 75, 177, 78),
),
home: // MyHomePage(title: 'Home page'),
StreamBuilder(
builder: (ctx, userSnapshot) {
if (userSnapshot.hasError) {
Center(
child: Text('Unknown Error'),
);
}
if (userSnapshot.hasData) {
}
}
Beta Was this translation helpful? Give feedback.
All reactions