FCM notifications only remain in the top bar (Flutter)

0

Good afternoon everyone,

Currently I have an app made with Flutter but the notifications fall on the top bar and not on the way they did in the beginning (I'm sending them from the Firebase Cloud Messaging console).

I want PopUp to come out like this without having to lower the top bar.

As I said at the beginning it happens to me so much when I send a simple message from the console of firebase (only I put title and body of the message) and if I send it from a function in Firebase Cloud Functions.

AndroidManifest: (In one part I have this loaded)

<activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </activity>

Configuration in the Main.dart part

_firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) {
        print('on message $message');

      },
      onResume: (Map<String, dynamic> message) {
        print('on resume $message');

      },
      onLaunch: (Map<String, dynamic> message) {
        print('on launch $message');

      },
    );
    _firebaseMessaging.requestNotificationPermissions( const IosNotificationSettings(sound: true,badge: true,alert: true));
    _firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings setting){
      print('Setting registered: $setting');
    });
    
asked by Gonza G 29.10.2018 в 21:31
source

1 answer

0

I was reading a bit about that FCM plugin, I only see that the notifications arrive to the system tray by default, that's why the notification is not shown as popup, for that you can use another plugin that is the Local notifications, so that a Once you receive the message, you can show the popup:

link

Your code would look something like this:

      onMessage: (Map<String, dynamic> message) {
            print('on message $message');

                //...

                _showBigTextNotification();


          },


   ....

        Future _showBigTextNotification() async {
        var bigTextStyleInformation = new BigTextStyleInformation(
            'Lorem <i>ipsum dolor sit</i> amet, consectetur <b>adipiscing elit</b>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
            htmlFormatBigText: true,
            contentTitle: 'overridden <b>big</b> content title',
            htmlFormatContentTitle: true,
            summaryText: 'summary <i>text</i>',
            htmlFormatSummaryText: true);
        var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
            'big text channel id',
            'big text channel name',
            'big text channel description',
            style: AndroidNotificationStyle.BigText,
            styleInformation: bigTextStyleInformation);
        var platformChannelSpecifics =
            new NotificationDetails(androidPlatformChannelSpecifics, null);
        await flutterLocalNotificationsPlugin.show(
            0, 'big text title', 'silent body', platformChannelSpecifics);
      }

Do not forget to import the plugin and initialize it, you can follow this sample code:

link

NOTE:

You can validate if you are in the background or not, use the flag mounted , if you are in false you throw the local notification.

    
answered by 01.11.2018 / 02:12
source