Skip to content

Context can't be defined in a singleton, so can't handle notifications at all! #1

@yoniker

Description

@yoniker

I'm coming from your tutorial here:

https://blog.logrocket.com/implementing-local-notifications-in-flutter/

The problem in your tutorial is that in the singleton there's no context,so it's impossible to use Navigator to handle notifications.

To see the problem clearly just replace the current selectNotification which does nothing, to the code that was mentioned in the tutorial:

Future selectNotification(String? payload) async {
  await Navigator.push(
    context,
    MaterialPageRoute<void>(builder: (context) => SecondScreen(payload)),
  );
}

to get the error that context was not defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions