Coder Social home page Coder Social logo

victorzhang2014 / notificationcentre Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 8 KB

A lightweight publisher/observer open-source library used for messaging run through the entire Flutter application. Inspired by NotificationCenter in iOS and EventBus on in Android.

License: MIT License

Dart 100.00%
eventbus flutter notificationcenter

notificationcentre's Introduction

NotificationCenter

A lightweight publisher/observer open-source library used for messaging to run through the entire Flutter applications. Inspired by NotificationCenter in iOS and EventBus on in Android.

Getting started

The NotificationCentre in Flutter is inspired by NotificationCenter in iOS and EventBus in Android, since it is used anywhere inside iOS (Swift/Objective-C) codebase, we are very familiar with the model of publisher&observer. Thinking of you, as an Android developer who has knowledge and is such familiar with EventBus.

Features

  • Observer: to observe events if there were messages being posted.
  • Publisher: to publish the event to all observers.

Usage

To add an observer, we suggest that you put the below code inside initState(), but you can still add the observer somewhere.

  @override
  void initState() { 
      super.initState(); 
      NotificationCenter().addObserver(NOTIFICATION_NAME_USER_SIGNED_IN, this, () {
          // Do something after the user has signed in.
      });
  }

To remove an observer, we suggest that you put the below code inside dispose(), but you can still remove the observer elsewhere.

  @override
  void dispose() { 
      NotificationCenter().removeObserver(NOTIFICATION_NAME_USER_SIGNED_IN, this);
      super.dispose();
  }

To post the message throughout the entire application, you can use the below code with ease.

  NotificationCenter().postNotification(
      NOTIFICATION_NAME_PURCHASE_COMPLETED, 
      data: {"data": YOUR_DATA, "type": "completed"},
  );

Note

For the NotificationName, it is just an ordinary String value, it can be any strings. Just keep in mind, the NotificationName you defined is equal to when you call these three methods: addObserver(), removeObserver(), and postNotification(), pass through the NotificationName you set.

notificationcentre's People

Contributors

victor-of avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.