mac_notifications 1.1.0+1 copy "mac_notifications: ^1.1.0+1" to clipboard
mac_notifications: ^1.1.0+1 copied to clipboard

discontinuedreplaced by: flutter_local_notifications

Display macOS notifications from Flutter and get answer from a reply.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:flutter/services.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(
        MacNotificationOptions(
            identifier:
                'test-notifications${DateTime.now().millisecondsSinceEpoch}',
            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 {}
  }
}
12
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Display macOS notifications from Flutter and get answer from a reply.

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on mac_notifications