pnta_flutter 1.1.0 copy "pnta_flutter: ^1.1.0" to clipboard
pnta_flutter: ^1.1.0 copied to clipboard

Official PNTA Flutter plugin to make push notifications suck less.

example/lib/main.dart

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

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

  await PntaFlutter.initialize(
    'prj_k3e0Givq', // replace with your project id
    metadata: {
      'user_id': '123',
      'user_email': 'user@example.com',
    },
    autoHandleLinks: true,
    showSystemUI: true,
  );

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: PntaFlutter.navigatorKey,
      home: HomePage(),
      routes: {
        '/profile': (context) => ProfilePage(),
      },
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String? _lastNotification;

  @override
  void initState() {
    super.initState();

    PntaFlutter.foregroundNotifications.listen((payload) {
      setState(() => _lastNotification = 'Foreground: ${payload.toString()}');
    });

    PntaFlutter.onNotificationTap.listen((payload) {
      setState(() => _lastNotification = 'Tap: ${payload.toString()}');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('PNTA Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(Icons.notifications, size: 64, color: Colors.blue),
            SizedBox(height: 16),
            Text(
              'Push notifications ready!',
              style: Theme.of(context).textTheme.headlineSmall,
            ),
            SizedBox(height: 8),
            Text(
                'Device token: ${PntaFlutter.deviceToken != null ? "Available" : "Not available"}'),
            if (PntaFlutter.deviceToken != null)
              SelectableText(
                PntaFlutter.deviceToken!,
                style: TextStyle(fontSize: 10, fontFamily: 'monospace'),
              ),
            if (_lastNotification != null) ...[
              SizedBox(height: 16),
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 24),
                child: SelectableText(
                  _lastNotification!,
                  style: TextStyle(fontSize: 10, fontFamily: 'monospace'),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}

class ProfilePage extends StatelessWidget {
  const ProfilePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Profile')),
      body: Center(
        child: Text('Profile page opened via deep link!'),
      ),
    );
  }
}
2
likes
160
points
534
downloads

Publisher

verified publisherpnta.io

Weekly Downloads

Official PNTA Flutter plugin to make push notifications suck less.

Homepage
Repository (GitHub)

Topics

#notifications #push #fcm #apns

Documentation

Documentation
API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface, url_launcher

More

Packages that depend on pnta_flutter