notibee 1.0.0 copy "notibee: ^1.0.0" to clipboard
notibee: ^1.0.0 copied to clipboard

NotiBee — One package. All notifications. Handle Local, Push (FCM), and In-App Notifications in Flutter.

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _lastAction = 'None';
  bool _usePush = false;
  String? _fcmToken;

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

  Future<void> _initializeNotifications() async {
    await NotiBee.init(
      appName: 'NotiBee Example',
      defaultIcon: NotifyIcon.app,
      defaultSound: NotifySound.system,
      usePushNotifications: _usePush,
      useInAppMessaging: _usePush,
    );

    if (_usePush) {
      final token = await NotiBee.getFCMToken();
      setState(() {
        _fcmToken = token;
      });
      debugPrint("FCM Token: $_fcmToken");
    }

    NotiBee.onAction((actionId) {
      setState(() {
        _lastAction = actionId;
      });
      debugPrint('Action clicked: $actionId');
    });
  }

  Future<void> _reInit() async {
    await _initializeNotifications();
    debugPrint('Re-initialized with Push: $_usePush');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('NotiBee Example')),
        body: Center(
          child: SingleChildScrollView(
            padding: const EdgeInsets.all(20),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  'Last Action: $_lastAction',
                  style: const TextStyle(fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 10),
                SwitchListTile(
                  title: const Text("Enable Push Notifications (FCM)"),
                  subtitle: const Text("Toggle this to initialize FCM"),
                  value: _usePush,
                  onChanged: (val) {
                    setState(() {
                      _usePush = val;
                    });
                    _reInit();
                  },
                ),
                if (_fcmToken != null)
                  SelectableText(
                    "FCM Token: $_fcmToken",
                    style: const TextStyle(fontSize: 10, color: Colors.grey),
                  ),
                const Divider(),
                ElevatedButton(
                  onPressed: () {
                    NotiBee.triggerInAppEvent('test_event');
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(
                        content: Text('Triggered event: test_event'),
                      ),
                    );
                  },
                  child: const Text('Trigger In-App "test_event"'),
                ),
                const SizedBox(height: 10),
                const SizedBox(height: 10),
                ElevatedButton(
                  onPressed: () {
                    NotiBee.show(
                      title: 'Hello!',
                      body: 'This is a simple local notification.',
                    );
                  },
                  child: const Text('Show Simple Notification'),
                ),
                const SizedBox(height: 10),
                ElevatedButton(
                  onPressed: () {
                    NotiBee.show(
                      title: 'Custom Icon & Sound',
                      body: 'This notification uses a custom icon and sound.',
                      // Note: Ensure 'chat_icon' exists in drawable and 'bell_sound' in raw/Runner
                      icon: NotifyIcon.custom('bell'),
                      sound: NotifySound.custom('notification'),
                    );
                  },
                  child: const Text('Custom Icon & Sound'),
                ),
                const SizedBox(height: 10),
                ElevatedButton(
                  onPressed: () {
                    NotiBee.schedule(
                      title: 'Scheduled',
                      body: 'This notification appeared after 5 seconds.',
                      after: const Duration(seconds: 5),
                    );
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('Scheduled for 5 seconds')),
                    );
                  },
                  child: const Text('Schedule for 5s'),
                ),
                const SizedBox(height: 10),
                ElevatedButton(
                  onPressed: () {
                    NotiBee.repeat(
                      title: 'Repeating',
                      body:
                          'This notification repeats every minute (min interval).',
                      // Note: Android minimum repeat interval is often 15 mins for exact, but periodic works differently.
                      // For demo, using hourly as per enum or daily. Hourly is safest min.
                      interval: NotifyInterval.hourly,
                    );
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('Repeating hourly set')),
                    );
                  },
                  child: const Text('Repeat Hourly'),
                ),
                const SizedBox(height: 10),
                ElevatedButton(
                  onPressed: () {
                    NotiBee.show(
                      title: 'Action Required',
                      body: 'Please make a choice.',
                      actions: [
                        NotifyAction(id: 'accept', label: 'Accept'),
                        NotifyAction(id: 'decline', label: 'Decline'),
                      ],
                    );
                  },
                  child: const Text('Show with Actions'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
2
likes
140
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

NotiBee — One package. All notifications. Handle Local, Push (FCM), and In-App Notifications in Flutter.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

firebase_core, firebase_in_app_messaging, firebase_messaging, flutter, flutter_local_notifications, flutter_timezone, timezone

More

Packages that depend on notibee