Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_messaging] and sqflite #1044

Closed
kroikie opened this issue Oct 13, 2019 · 3 comments
Closed

[firebase_messaging] and sqflite #1044

kroikie opened this issue Oct 13, 2019 · 3 comments
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: messaging type: question A question where further information is requested

Comments

@kroikie
Copy link
Collaborator

kroikie commented Oct 13, 2019

I try to send a message from my website to users with Firebase and store the message in the user device with sqflite plugin.

When the application in the foreground, everything works good and message insert in the database. But when the application in the background or completely close it just displays notification and data not inserted in the database.

edit:

After setting click_action for notification, Clicking on the notification data will be saved but if the user dismisses notification data lost.

code

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

@override
void initState() {
    prepareFirebaseCloudMessaging();
    super.initState();
 }
void prepareFirebaseCloudMessaging() {
    if (Platform.isIOS) IOSPermission();
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        notificationDataHandler(message);
      },
      onResume: (Map<String, dynamic> message) async {
        notificationDataHandler(message);
      },
      onLaunch: (Map<String, dynamic> message) async {
        notificationDataHandler(message);
      },
    );
  }

void notificationDataHandler(Map<String, dynamic> message) async {
    try {
    var databasesPath = await getDatabasesPath();
    String path = join(databasesPath, 'MY_DATABASE_FILE.db');
    Database database = await openDatabase(path, version: 1,
        onCreate: (Database db, int version) async {
      await db.execute(
          'CREATE TABLE Messages (id INTEGER PRIMARY KEY, message TEXT, date TEXT, seen INTEGER)');
    });
    Message messageStore = Message(
        null, message["data"]["message"], message["data"]["date"], false);
      await database.insert("Messages", messageStore.toMap());
    database.close();
    }catch(e){
      debugPrint(e.toString());
    }
  }

How Can call dart code after receive notification without user click on it?

@kroikie
Copy link
Collaborator Author

kroikie commented Oct 13, 2019

@mhd-barikhan

The issue at flutter/flutter#39889 has been closed and moved here. Future collaboration on this issue will be done here.

@BondarenkoStas BondarenkoStas changed the title flutter Firebase Messaging and sqflite [firebase_messaging] and sqflite Oct 21, 2019
@BondarenkoStas BondarenkoStas added help wanted type: question A question where further information is requested labels Oct 21, 2019
@iapicca
Copy link

iapicca commented Nov 5, 2019

#1041

@Ehesp Ehesp added impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: messaging labels Apr 23, 2020
@Salakar
Copy link
Member

Salakar commented Nov 5, 2020

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues. It now supports background notification handling for iOS & Android.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone.

@Salakar Salakar closed this as completed Nov 5, 2020
@firebase firebase locked and limited conversation to collaborators Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: messaging type: question A question where further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants