littlefish_notifications_fcm 4.0.0
The implementation of firebase async notifications in a package format.
Littlefish Notifications FCM
This package provides a Flutter-abstracted implementation of Firebase Cloud Messaging (FCM) for the Littlefish application. It simplifies the integration and management of push notifications in a Flutter project.
Features
- Firebase Cloud Messaging Integration: Seamlessly integrates FCM for handling push notifications.
- Platform Support: Works on both Android and iOS platforms.
- Customizable Notification Handling: Allows custom handling of foreground, background, and terminated state notifications.
- Topic Subscriptions: Supports subscribing to and unsubscribing from FCM topics.
- Token Management: Provides easy access to the FCM device token.
Installation
Add the package to your pubspec.yaml:
dependencies:
littlefish_notifications_fcm: ^1.0.0
Run flutter pub get to fetch the package.
Usage
Initialization
Initialize the FCM service in your app's entry point:
import 'package:littlefish_notifications_fcm/littlefish_notifications_fcm.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await LittlefishNotificationsFCM.initialize();
runApp(MyApp());
}
Handling Notifications
Listen for incoming notifications:
LittlefishNotificationsFCM.onMessage.listen((notification) {
// Handle foreground notification
print('Received notification: ${notification.title}');
});
Accessing the FCM Token
Retrieve the device's FCM token:
String? token = await LittlefishNotificationsFCM.getToken();
print('FCM Token: $token');
Topic Subscriptions
Subscribe or unsubscribe from topics:
await LittlefishNotificationsFCM.subscribeToTopic('news');
await LittlefishNotificationsFCM.unsubscribeFromTopic('news');
Configuration
Ensure your Firebase project is set up and the google-services.json (Android) or GoogleService-Info.plist (iOS) files are added to your Flutter project. Follow the FlutterFire setup guide for detailed instructions.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.