title: Flutter push notification is working only when app is in background
body: <p>My problem is regarding the push notification using Flutter and firebase_messaging plugin</p>
  <p><strong>Problem:</strong></p>
  <p>I have integrated <a href="https://pub.dev/packages/firebase_messaging" rel="noreferrer">firebase_messaging</a> plugin to my flutter app for push notification.
  I can guarantee that the setup is correct to the best of my knowledge as i am receiving push notification. The problem occurs when pushes are received only when my app is running in the background(like minimizing but available in the system memory). <strong>Pushes are not received</strong> when app is in foreground or is killed.</p>
  <p>To provide a solution on what I have tried, I could not figure out actually needs to be done.</p>
  <p>I have followed tutorials on this and applied every single step to overcome the problem but to no avail.</p>
  <p>I am using nodeJS to handle the firebase-admin and serviceaccountkey file as I need device_tokens from my DB.</p>
  <p>NodeJS</p>
  <pre><code> const firebase = require('firebase-admin');
   const serviceAccount = require('../controller/firebase/serviceAccountKey.json');
   firebase.initializeApp({
    credential: firebase.credential.cert(serviceAccount)
   });
  
   //Function to actually implement the push
   const pushNotificationInitiatorSubscription = (resultValue) =&gt; {
   let devicesTokenString = resultValue[0]['device_token'];
   const firebaseToken = devicesTokenString;
   const payLoad = {
     notification: {
     title: 'New Subscription',
     body: 'You have a new subscription to your material ' + resultValue[0]['course_name']
   }
  };
  const option = {
   priority: 'high'
  };
  
  firebase.messaging().sendToDevice(firebaseToken, payLoad, option).then(success =&gt; {
    // console.log(success.results[0]['error']);
    // console.log(success.results[1]['error']);
    // console.log(success);
  }).catch(err =&gt; {
   console.log(err);
  })
  </code></pre>
  <p>Flutter</p>
  <pre><code>import 'package:firebase_messaging/firebase_messaging.dart';
  
  class FirebaseCloudMessage {
   static FirebaseCloudMessage _instance = new FirebaseCloudMessage.internal();
   FirebaseCloudMessage.internal();
   factory FirebaseCloudMessage() =&gt; _instance;
  
   final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  
   configureFirebaseListeners() {
    print('Here');
    _firebaseMessaging.configure(
      onMessage: (Map&lt;String, dynamic&gt; message) async {
    print(&quot;Message $message&quot;);
    // return message;
  }, onLaunch: (Map&lt;String, dynamic&gt; message) async {
    print(&quot;Message $message&quot;);
    // return message;
  }, onResume: (Map&lt;String, dynamic&gt; message) async {
    print(&quot;Message $message&quot;);
    // return message;
  });
  }
  }
  </code></pre>
  <p>Help would be appreciated. Thanks</p>