Simplest way to display notifications in flutter?

831

One of the easiest way to have local notifications on an app is to use the Toast library. It is very popular due to ease of use, few bugs across platforms and many recent code examples.

Only caveat: Please check that the look and feel of toast is what you have in mind. By default it is a notification that pops out at the bottom of the screen. (You can override default behavior but that requires more code ex:How to display Toast at center of screen)

The only "difficulty" of toast is that you might have to deal with state at the widget level (maybe inter- widget but that can be avoided in many use cases). The example given is pretty self explanatory imho. https://pub.dev/packages/fluttertoast/example

If not enough from official doc, or want stateless examples, feel free to check this link on SO. How to create Toast in Flutter? One of the 31 answers in there should be a code that should be pretty close to something you are comfortable with.

Now here is a list of other type of notifications. If toast does not suit your UX/UI needs, this might give you ideas. https://ux.stackexchange.com/questions/91406/what-is-the-difference-between-alert-notification-banner-and-toast-message

Share:
831
Anshul Raj
Author by

Anshul Raj

I'm into computers since my childhood and I've been coding since ~ Grade 5. Currently, I'm an advanced Python Programmer. Also, I'm an intermediate at Dart (Dart/Flutter). Programming is my passion, something that I can never leave.

Updated on December 29, 2022

Comments

  • Anshul Raj
    Anshul Raj over 1 year

    How can I show notifications in a Flutter app?

    I've tried various packages like flutter_local_notifications and awesome_notifications. But I am unable to use them properly.

    Also, I want simple and local notifications. So cloud notifications are not really suitable for my need.

    • Maikzen
      Maikzen almost 3 years
      Flutter_local_notifications is the best package for notifications (Android and iOS) if you dont need cloud notifications. Learn to use correctly by tutorials or something. Any particular question you can share here.
    • Anshul Raj
      Anshul Raj almost 3 years
      @MiguelEscobarCalderon Pardon me if my question was not clear. My problem was that I couldn't follow the tutorials precisely (I couldn't figure out where to add which lines from the tutorial). I can't get the flutter_local_notifications plugin to work. So I was looking for a simple and easy-to-follow tutorial for that. Also, many of the tutorials are outdated now.
    • Alexandre Jean
      Alexandre Jean almost 3 years
      Might want to edit your question title to something like "Simplest way to display notifications in Flutter? No cloud, maybe stateless." I assume this is what you look for.
  • Anshul Raj
    Anshul Raj almost 3 years
    Can I still get toast notifications if the app is running in the background? Also, it seems that toast is something that you get when you're using the app. But I wanted to send a notification that will appear on the status bar.
  • Alexandre Jean
    Alexandre Jean almost 3 years
    This is more a background task code job than a notification code job then :) -- running "push notifications" aka "reminders" you need a stronger back end. Like Firebase, AWS, HAsura, etc... or you use local notifications. Else might want to look at pub.dev/packages/workmanager it might have the tools you need. Here are some links from resources I watch, but I never ran that code without a BaaS, youtube.com/watch?v=cV0pByqNV6A and youtube.com/watch?v=lka6D_J7GC4 or stackoverflow.com/questions/61169302/…
  • Alexandre Jean
    Alexandre Jean almost 3 years
    You might want to read the official docs about background tasks. Also please note that app running on the background is different than "app killed". flutter.dev/docs/development/packages-and-plugins/…. App killed push notifications can also be done ex: stackoverflow.com/questions/55813075/…
  • Anshul Raj
    Anshul Raj almost 3 years
    Running background tasks is not a big problem for me. But showing a notification is. I just couldn't get it (local notification plugin) to work. I can't understand where to place which piece of code from the description.
  • Anshul Raj
    Anshul Raj almost 3 years