notification_system 0.0.4 copy "notification_system: ^0.0.4" to clipboard
notification_system: ^0.0.4 copied to clipboard

A comprehensive notification handling package for Flutter, supporting Firebase, Local Notifications, and In-App messaging.

Notification System #

pub package

A comprehensive, production-ready notification handling package for Flutter. It seamlessly integrates Firebase Cloud Messaging (FCM), Local Notifications, and In-App messaging into a unified API. Built with clean architecture principles, it offers robust permission handling with caching and localization support.

🚀 Features #

  • 🔥 Firebase Messaging Integration:

    • Handles background, terminated, and foreground messages automatically.
    • Exposes FCM token generation.
    • Automatically bridges FCM notifications to Local Notifications when in foreground.
  • 🔔 Local Notifications:

    • Show system tray notifications on Android and iOS.
    • Configurable channels and importance levels.
  • 💬 In-App Notifications:

    • Show beautiful, non-intrusive toasts/snackbars for app events.
    • Types: Success (Green), Error (Red), Warning (Orange), Info (Blue).
    • Fully customizable via overlay_support.
  • 🛡️ Smart Permission Handling:

    • Custom Pre-Request Dialog: Shows a friendly dialog explaining why permissions are needed before triggering the native OS prompt.
    • Preference Caching: Remembers if the user clicked "Later" to avoid spamming them on every launch.
    • Context-Aware: Only requests native permissions when the user explicitly agrees.
  • 🌍 Localization:

    • Built-in support for English (en) and Arabic (ar).
    • Automatically detects system locale for the permission dialog.
  • 🏗️ Solid Architecture:

    • Compatibility: Uses namespaced SharedPreferences to avoid conflicts with your app's existing dependencies.

📦 Installation #

dependencies:
  notification_system: ^0.0.4

📱 Example #

Check out the example app for a complete implementation demonstrating:

  • Customizing the notification style.
  • Requesting permissions with a rationale dialog.
  • Handling local and in-app notifications.

🔧 Setup #

1. Android & iOS Configuration #

Follow the official guides for Firebase Messaging and flutter_local_notifications to set up:

  • google-services.json / GoogleService-Info.plist
  • AndroidManifest.xml (Permissions, Receivers)
  • Info.plist (APNS permissions)

2. Initialize the Notification System #

In your main.dart, initialize the system before running the app.

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 1. Initialize System
  await NotificationSystem.instance.initialize(
    style: const NotificationStyle(
       successColor: Colors.teal,
    ),
  );

  runApp(const MyApp());
}

3. Initialize Services (Optional) #

The system initializes basic services automatically. You can access them directly:

final firebaseService = NotificationSystem.instance.firebaseNotificationService;
// Use firebaseService...

📖 Usage #

Requesting Permissions #

User NotificationSystem.instance.permissionService to handle the flow.

import 'package:notification_system/notification_system.dart';

Future<void> checkPermissions(BuildContext context) async {
  final permissionService = NotificationSystem.instance.permissionService;
  
  // Returns true if granted (either previously or just now)
  bool granted = await permissionService.requestNotificationPermission(context);
  
  if (granted) {
    print("User has enabled notifications!");
  } else {
    print("User denied or postponed notifications.");
  }
}

Showing In-App Messages #

Trigger global in-app notifications from anywhere.

import 'package:notification_system/notification_system.dart';

void confirmOrder() {
  final generalService = NotificationSystem.instance.generalNotificationService;

  // Show Success
  generalService.showSuccess("Order #1234 placed successfully!");
  
  // Show Error
  generalService.showError("Failed to connect to server.");
  
  // Show Warning
  generalService.showWarning("Your session is about to expire.");
}

🎨 Customization #

You can pass a NotificationStyle object to .initialize() to customize:

  • Colors: successColor, errorColor, warningColor, infoColor.
  • Text Styles: titleStyle, bodyStyle.
  • Permission Dialog: Title, Body, and Button texts.
await NotificationSystem.instance.initialize(
  style: NotificationStyle(
    successColor: Colors.deepPurple,
    errorColor: Colors.deepOrange,
  ),
);
1
likes
160
points
172
downloads

Publisher

verified publisherahmed-alkamel.eyssoft.com

Weekly Downloads

A comprehensive notification handling package for Flutter, supporting Firebase, Local Notifications, and In-App messaging.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

firebase_messaging, flutter, flutter_local_notifications, freezed_annotation, intl, json_annotation, overlay_support, permission_handler, shared_preferences

More

Packages that depend on notification_system