dart_notification_center 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

Pub

A lightweight and intuitive observer pattern manager for Dart/Flutter in the style of the iOS Notification Center

Installation #

To use this plugin, add dart_notification_center as a dependency in your pubspec.yaml file.

Import the package using:

import 'package:dart_notification_center/dart_notification_center.dart';

Usage #

A simple example:

...

FlutterNotificationCenter.subscribe(
  channel: 'examples',
  observer: this,
  onNotification: (options) {
    print('Notified: ${options}');
  },
);

FlutterNotificationCenter.post(channel: 'examples', options: 'Congrats you did it!');

FlutterNotificationCenter.unsubscribe(channel: 'examples', observer: this);

...

0.0.0 #

  • Initial version, created by Stagehand

0.1.0 #

  • Implemented version, functional.
  • Needs testing

0.1.1 #

  • Knock down version requirement for test

0.1.2 #

  • Much better. Should integrate well now

0.1.3 #

  • Fixed the subscription method, subscriptions should listen properly now

0.2.0 #

  • Callbacks are now handled asynchronously to improve performance

1.0.0 #

  • Some general package improvements.
  • Removed an assertion on posting that was unnecessary, if not counterproductive.
  • Stable for first full version

1.0.0+1 #

  • Fixed the badge to refer to the correct package.

example/dart_notification_center_example.dart

import 'package:dart_notification_center/dart_notification_center.dart';

main() {
  DartNotificationCenter.registerChannel(channel: 'an_event');

  //this is our notification observer object
  int i = 1;

  //This is our channel name
  String CHANNEL_NAME = 'an_event';

  DartNotificationCenter.subscribe(
    channel: CHANNEL_NAME,
    observer: i,
    onNotification: (result) => print('received: $result'),
  );

  // Expected: received: null
  DartNotificationCenter.post(channel: CHANNEL_NAME);

  // Expected: received: with options!!
  DartNotificationCenter.post(
    channel: CHANNEL_NAME,
    options: 'with options!!',
  );

  DartNotificationCenter.unsubscribe(observer: i, channel: CHANNEL_NAME);

  DartNotificationCenter.unregisterChannel(channel: CHANNEL_NAME);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_notification_center: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_notification_center/dart_notification_center.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_notification_center/dart_notification_center.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
meta ^1.1.6 1.1.7
Dev dependencies
pedantic ^1.0.0
test ^1.0.0