azure_notification_hubs 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

Introduction #

Azure Notification Hubs provide an easy-to-use and scaled-out push engine that allows you to send notifications to any platform (iOS, Android, Windows, Kindle, Baidu, etc.) from any backend (cloud or on-premises). Push notifications is a form of app-to-user communication where users of mobile apps are notified of certain desired information, usually in a pop-up or dialog box on a mobile device.

This plugin allows Flutter developers to extend their apps with Azure Notification Hub functionality. For this plugin to work, one must setup a Notification Hub within Azure and add the necessary capabilities within the project.

Currently, this plugin only functions for iOS. Android support is planned.

Getting started #

Installation #

To install this plugin, add azure_notification_hubs as a dependency in your pubspec.yaml file.

Setup a Notification Hub #

Refer to to create your own Azure Notification Hub.

Add capabilities in your project #

In XCode, find your target's Signing & Capabilities tab. Add Push Notifications and Background Modes. Additionally, in the Background Modes capability, check Background fetch and Remote notifications.

Usage #

  • Instantiate the AzureNotificationHubs
  • Call the instance's init function, passing your:
    • Connection String
    • Notification Hub Name
    • Tags to subscribe to (separated by commas)
  • Call the instance's register function to subscribe to the previously passed tags.
  • Send a Push Notification (e.g. Test Send in the Azure Portal) and receive it on your device
  • Optional: Call the instance's unregister function to unsubscribe from all tags.

Push Notifications only work on a physical device, the simulator will not suffice!

Example #

To run the example, first clone the repo

git clone

Then you must set the NHInfoConnectionString and NHInfoHubName according to the data in your Notification Hub.

  • NHInfoHubName is the name of your Notification Hub.
  • NHInfoConnectionString should be in the following format:

Finally, execute the following inside the example directory:

flutter run

You should be able to enter custom tags to register to upon which the app asks you for permission. You can then test send notifications to the device.

Push Notifications only work on a physical device, the simulator will not suffice!

Contribute #

  • Propose any feature or enhancement
  • Report a bug
  • Open a pull request

1.0.2 #

  • Updated README


import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:azure_notification_hubs/azure_notification_hubs.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

// TODO: Fill in your Azure Notification Hub information
const String NHInfoConnectionString = "TODO1";
const String NHInfoHubName = "TODO1";

const Color ORANGE = Color.fromARGB(255, 255, 127, 80);
const Color WHITE = Color.fromARGB(255, 255, 255, 255);
const Color RED = Color.fromARGB(255, 255, 0, 0);

class _MyAppState extends State<MyApp> {
  AzureNotificationHubs azure;
  TextEditingController tagController = new TextEditingController();
  bool valid;

  void initState() {
    azure = new AzureNotificationHubs();
    valid = NHInfoConnectionString != "TODO" && NHInfoHubName != "TODO";

  void init() {
    try {
      azure.init(NHInfoConnectionString, NHInfoHubName, tagController.text);
    } on PlatformException {}

  void onPressRegister() {
    if (tagController.text == "") {
      print("Tags must not be empty!");
    print("Registering for tags: ${tagController.text}");
    try {
    } on PlatformException {}

  void onPressUnRegister() {
    if (tagController.text == "") {
      print("Tags must not be empty!");
    print("UnRegistering for tags: ${tagController.text}");
    try {
    } on PlatformException {}

  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      debugShowMaterialGrid: false,
      home: Scaffold(
          appBar: AppBar(
            backgroundColor: ORANGE,
            title: const Text('Azure Notification Hubs Example App'),
          body: Container(
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Column(
              children: <Widget>[
                NHInfoConnectionString == "TODO"
                    ? Text(
                        "Please set NHInfoConnectionString in example/main.dart",
                        style: TextStyle(color: RED, fontSize: 18),
                    : Container(),
                NHInfoHubName == "TODO"
                    ? Text(
                        "Please set NHInfoHubName in example/main.dart",
                        style: TextStyle(color: RED, fontSize: 18),
                    : Container(),
                  controller: tagController,
                  decoration: InputDecoration(
                      helperText: "Enter tags to (un-)register here",
                      hintText: "tag1,tag2,tag3,...",
                      focusedBorder: UnderlineInputBorder(
                          borderSide: BorderSide(color: ORANGE))),
                  height: 20,
                  children: <Widget>[
                        onPressed: valid ? onPressRegister : null,
                        color: ORANGE,
                        textColor: WHITE,
                        child: Text("Register")),
                      width: 10,
                        onPressed: valid ? onPressRegister : null,
                        color: ORANGE,
                        textColor: WHITE,
                        child: Text("UnRegister"))

Use this package as a library

1. Depend on it

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

  azure_notification_hubs: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support 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:azure_notification_hubs/azure_notification_hubs.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

6 out of 6 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies