pusher_push_notifications 1.0.0-dev.2 copy "pusher_push_notifications: ^1.0.0-dev.2" to clipboard
pusher_push_notifications: ^1.0.0-dev.2 copied to clipboard

discontinued
retracted[pending analysis]

Official Flutter Plugin for Pusher Beams, receive notifications easily on your Flutter application with Pusher Beams.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:pusher_push_notifications/pusher_push_notifications.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await PusherPushNotifications.instance
      .start('your-instance-id'); // Supply your own instanceId

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pusher Beams Flutter Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Pusher Beams Flutter Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  initState() {
    super.initState();

    initPusherPushNotification();
  }

  getSecure() async {
    final BeamsAuthProvider provider = BeamsAuthProvider()
      ..authUrl = 'https://some-auth-url.com/secure'
      ..headers = {'Content-Type': 'application/json'}
      ..queryParams = {'page': '1'}
      ..credentials = 'omit';

    await PusherPushNotifications.instance.setUserId(
        'user-id',
        provider,
        (error) => {
              if (error != null) {print(error)}

              // Success! Do something...
            });
  }

  initPusherPushNotification() async {
    // Let's see our current interests
    print(await PusherPushNotifications.instance.getDeviceInterests());

    // This is not intented to use in web
    if (!kIsWeb) {
      await PusherPushNotifications.instance
          .onInterestChanges((interests) => {print('Interests: $interests')});

      await PusherPushNotifications.instance
          .onMessageReceivedInTheForeground(_onMessageReceivedInTheForeground);
    }
  }

  void _onMessageReceivedInTheForeground(Map<Object?, Object?> data) {
    _showAlert(data["title"].toString(), data["body"].toString());
  }

  void _showAlert(String title, String message) {
    AlertDialog alert = AlertDialog(
        title: Text(title), content: Text(message), actions: const []);

    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            OutlinedButton(
                onPressed: () async {
                  await PusherPushNotifications.instance
                      .addDeviceInterest('bananas');
                },
                child: const Text('I like bananas')),
            OutlinedButton(
                onPressed: () async {
                  await PusherPushNotifications.instance
                      .removeDeviceInterest('bananas');
                },
                child: const Text("I don't like banana anymore")),
            OutlinedButton(
                onPressed: () async {
                  await PusherPushNotifications.instance
                      .addDeviceInterest('apples');
                },
                child: const Text('I like apples')),
            OutlinedButton(
                onPressed: () async {
                  await PusherPushNotifications.instance
                      .addDeviceInterest('garlic');
                },
                child: const Text('I like garlic')),
            OutlinedButton(
                onPressed: getSecure, child: const Text('Get Secure')),
            OutlinedButton(
                onPressed: () async {
                  await PusherPushNotifications.instance.clearDeviceInterests();
                },
                child: const Text('Clear my interests'))
          ],
        ),
      ),
    );
  }
}
0
likes
0
points
3
downloads

Publisher

unverified uploader

Weekly Downloads

Official Flutter Plugin for Pusher Beams, receive notifications easily on your Flutter application with Pusher Beams.

Repository (GitHub)
View/report issues

License

(pending) (license)

Dependencies

flutter, pusher_push_notifications_android, pusher_push_notifications_ios, pusher_push_notifications_platform_interface, pusher_push_notifications_web, uuid

More

Packages that depend on pusher_push_notifications

Packages that implement pusher_push_notifications