push_notification_kit 0.4.0 copy "push_notification_kit: ^0.4.0" to clipboard
push_notification_kit: ^0.4.0 copied to clipboard

Auth-agnostic Flutter push notifications: FCM token lifecycle, rich notifications (images & action buttons), deep links, and pluggable backend registration. Bring your own auth via a TokenProvider.

example/lib/main.dart

import 'dart:async';

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

/// Minimal example wiring. In a real app you would initialize Firebase first
/// (Firebase.initializeApp) and supply real auth + backend endpoints.
void main() {
  runApp(const ExampleApp());
}

class ExampleApp extends StatefulWidget {
  const ExampleApp({super.key});

  @override
  State<ExampleApp> createState() => _ExampleAppState();
}

class _ExampleAppState extends State<ExampleApp> {
  final _authController = StreamController<bool>.broadcast();
  final _log = <String>[];
  PushKit? _push;

  @override
  void initState() {
    super.initState();
    _push = PushKit(
      registrar: HttpDeviceRegistrar(
        registerUrl: Uri.parse('https://api.example.com/users/add-push-token'),
        tokenProvider: CallbackTokenProvider(
          getToken: () async => 'demo-access-token',
        ),
      ),
      authState: _authController.stream,
      channel: const NotificationChannelConfig(
        channelId: 'default',
        channelName: 'Notifications',
      ),
      onTap: (m) => _append('tap → ${m.deepLink}'),
      onAction: (id, m) => _append('action $id → ${m.deepLink}'),
      onForegroundMessage: (m) => _append('foreground: ${m.title}'),
      foregroundPolicy: ForegroundPolicy.callbackOnly,
    );
    // In a real app, call after Firebase.initializeApp():
    // await _push!.init();
  }

  void _append(String line) => setState(() => _log.insert(0, line));

  @override
  void dispose() {
    _push?.dispose();
    _authController.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('push_notification_kit example')),
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(12),
              child: Row(
                children: [
                  ElevatedButton(
                    onPressed: () => _authController.add(true),
                    child: const Text('Sign in'),
                  ),
                  const SizedBox(width: 8),
                  OutlinedButton(
                    onPressed: () => _authController.add(false),
                    child: const Text('Sign out'),
                  ),
                ],
              ),
            ),
            const Divider(),
            Expanded(
              child: ListView(
                children: _log.map((l) => ListTile(title: Text(l))).toList(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
130
points
167
downloads

Documentation

API reference

Publisher

verified publisherconapps.net

Weekly Downloads

Auth-agnostic Flutter push notifications: FCM token lifecycle, rich notifications (images & action buttons), deep links, and pluggable backend registration. Bring your own auth via a TokenProvider.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

firebase_messaging, flutter, flutter_local_notifications, http, path_provider

More

Packages that depend on push_notification_kit