notification_history 1.0.3 copy "notification_history: ^1.0.3" to clipboard
notification_history: ^1.0.3 copied to clipboard

A Flutter package to manage and display the history of notifications received by the app, including Firebase Cloud Messaging (FCM) notifications.This package provides a local database to store notific [...]

Notification History #

A Flutter package for managing and displaying push notification history using Firebase Cloud Messaging (FCM) and local notifications.

Features #

Store notifications in a local SQLite database. Display notification history with read/unread status. Support for FCM and local notifications. Clean architecture with dependency injection using get_it.

Installation #

  1. Add the package to your pubspec.yaml:
dependencies:
  notification_history:
    path: /path/to/notification_history # For local development
    # Or use: git: https://github.com/AlbertStany/PushNotificationHistoryPackageFlutter
    # Or use: version: ^1.0.2
  1. Run flutter pub get.

Setup #

  1. Configure Firebase:

Add google-services.json to android/app/ and GoogleService-Info.plist to ios/Runner/. Initialize Firebase in your app:

await Firebase.initializeApp();
  1. Set Up Dependency Injection:
import 'package:get_it/get_it.dart';
import 'package:notification_history/notification_history.dart';

final getIt = GetIt.instance;

void setupDI() {
  getIt.registerSingleton<NotificationRepository>(SqfliteNotificationRepository.instance);
  getIt.registerSingleton<AddNotification>(AddNotification(getIt<NotificationRepository>()));
  getIt.registerSingleton<GetNotifications>(GetNotifications(getIt<NotificationRepository>()));
  getIt.registerSingleton<MarkNotificationAsRead>(MarkNotificationAsRead(getIt<NotificationRepository>()));
  getIt.registerSingleton<DeleteNotification>(DeleteNotification(getIt<NotificationRepository>()));
  getIt.registerSingleton<MarkAllNotificationsAsRead>(MarkAllNotificationsAsRead(getIt<NotificationRepository>()));
  getIt.registerSingleton<NotificationHandler>(
    NotificationHandler._init(
      addNotification: getIt<AddNotification>(),
      channelId: 'your_channel_id',
      channelName: 'Your Channel Name',
      androidIcon: '@mipmap/your_icon',
    ),
  );
}
  1. Initialize Notifications:
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  setupDI();
  await getIt<NotificationHandler>().initialize();
  runApp(MyApp());
}
  1. Display Notification History:
Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => NotificationHistoryScreen(
      getNotifications: getIt<GetNotifications>(),
      markNotificationAsRead: getIt<MarkNotificationAsRead>(),
      deleteNotification: getIt<DeleteNotification>(),
      markAllNotificationsAsRead: getIt<MarkAllNotificationsAsRead>(),
    ),
  ),
);
  1. Show a Local Notification:
getIt<NotificationHandler>().showNotification(
  'Test Title',
  'Test Body',
  payload: 'test_payload',
);
  1. Android Configuration

Add to android/app/src/main/AndroidManifest.xml:

<application ...>
    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="your_channel_id" />
</application>

Add to android/app/src/main/res/values/strings.xml:

<resources>
    <string name="default_notification_channel_name">Your Channel Name</string>
</resources>
  1. iOS Configuration

Enable Push Notifications in Xcode. Add GoogleService-Info.plist to ios/Runner/.

Example #

See the example/ directory for a sample app.

License #

MIT License

2
likes
120
points
55
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to manage and display the history of notifications received by the app, including Firebase Cloud Messaging (FCM) notifications.This package provides a local database to store notifications and a UI to display them, making it easy.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

cupertino_icons, firebase_core, firebase_messaging, flutter, flutter_local_notifications, get_it, path, sqflite

More

Packages that depend on notification_history