mac_notifications 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

Mac Notifications #

This package helps you to display a notification on macOS platform. You can highly customize this notification.

NOTE: To be able to use this package, you must be on master Flutter channel.

Installation #

See Installing tab to see how to integrate.

Wherever you want to use this plugin, do

import 'package:mac_notifications/mac_notifications.dart';

Use #

Here's a basic usage example. See example folder on (GitHub)[https://github.com/beagle-barks/flutter_mac_notification_plugin/] for more information.

Basic notification #

try {
     MacNotifications.showNotification(
       NocenOptions(
           identifier: 'test-notifications',
           title: 'Hello',
           subtitle: 'This is a notification from Flutter to Mac',
           informative:
               'And it runs smoothly with almost no cost when implementing ;)',),
     );
} on PlatformException {}

Notification with reply #

try {
     MacNotifications.showNotification(
       NocenOptions(
           identifier: 'test-notifications',
           title: 'Hello',
           subtitle: 'This is a notification from Flutter to Mac',
           informative:
               'And it runs smoothly with almost no cost when implementing ;)',
           hasReplyButton: true,
           replyPlaceholder: 'Your answer goes here',
           ),
     );
} on PlatformException {}

Get the reply #

To get the text the user enters in a reply notification, you can simply use a StreamBuilder or StreamSubscription.

StreamBuilder<String>(
  stream: MacNotifications.getAnswers,
  builder: (context, snapshot) {
      if (snapshot.data == null)
         return Text(
           'Your answer goes here.',
           style: TextStyle(
             fontWeight: FontWeight.bold,
           ),
         );
         return Text(
           snapshot.data,
           style: TextStyle(
             fontWeight: FontWeight.bold,
           ),
         );
      },
)

1.0.1 #

  • README.md: Provide an example on how to use replies

1.0.0 #

  • Working example.
  • In the future we plan to integrate local_notifications to provide a "multi-multi-platform" notification manager.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter/services.dart';
import 'package:mac_notifications/nocen_options.dart';
import 'package:mac_notifications/mac_notifications.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Mac Notifications'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text(
                  'Click on this button and wait 3 seconds for a notification. You may be asked for permissions.'),
              FlatButton(
                child: Text('Show  basic notification'),
                textColor: Theme.of(context).accentColor,
                onPressed: () {
                  _showNotification(false);
                },
              ),
              FlatButton(
                child: Text('Show reply notification'),
                textColor: Theme.of(context).accentColor,
                onPressed: () {
                  _showNotification(true);
                },
              ),
              SizedBox(
                height: 12,
              ),
              Container(
                decoration: BoxDecoration(
                  border: Border.all(color: Colors.grey),
                ),
                padding: const EdgeInsets.all(12),
                child: StreamBuilder<String>(
                  stream: MacNotifications.getAnswers,
                  builder: (context, snapshot) {
                    if (snapshot.data == null)
                      return Text(
                        'Your answer goes here.',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      );
                    return Text(
                      snapshot.data,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                      ),
                    );
                  },
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  void _showNotification(bool reply) {
    try {
      MacNotifications.showNotification(
        NocenOptions(
            identifier: 'test-notifications',
            title: 'Hello',
            subtitle: 'This is a notification from Flutter to Mac',
            informative:
                'And it runs smoothly with almost no cost when implementing ;)',
            schedule: true,
            scheduleTimeSeconds: 3,
            hasReplyButton: reply,
            replyPlaceholder: 'Tell me about your day.'),
      );
    } on PlatformException {}
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  mac_notifications: ^1.0.1

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:mac_notifications/mac_notifications.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
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]
65
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Dependencies

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