flutter_push_notifications

Last updated:

0 purchases

flutter_push_notifications Image
flutter_push_notifications Images
Add to Cart

Description:

flutter push notifications

Flutter push notifications #
The goal of this plugin is to make it easy to execute actions directly from PUSH notifications.
Sample uses for this plugin are:


Accepting/Rejecting a work offer, sent as PUSH notification


Reporting an assignment with defaults when you get a notification that assignment has finished


Sending a confirmation that you received 15 assignments that were assigned to you


Replying to a message directly from a widget when you get a message as PUSH notification


Usage #
To use this plugin, add flutter_push_notifications as a dependency in your pubspec.yaml file.
Getting Started #
Check out the example directory for a sample app using
Android Integration #
To integrate your plugin into the Android part of your app, follow these steps:


Using the Firebase Console add an Android app to your project: Follow the assistant, download the generated google-services.json file and place it inside android/app.


Add the classpath to the [project]/android/build.gradle file.


dependencies {
// Example existing classpath
classpath 'com.android.tools.build:gradle:3.5.0'
// Add the google services classpath
classpath 'com.google.gms:google-services:4.3.3'
}
copied to clipboard

Add the apply plugin to the [project]/android/app/build.gradle file.

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
copied to clipboard
iOS Integration #


Generate the certificates required by Apple for receiving push notifications following this guide in the Firebase docs. You can skip the section titled "Create the Provisioning Profile".


Using the Firebase Console add an iOS app to your project: Follow the assistant, download the generated GoogleService-Info.plist file, open ios/Runner.xcworkspace with Xcode, and within Xcode place the file inside ios/Runner. Don't follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.


In Xcode, select Runner in the Project Navigator. In the Capabilities Tab turn on Push Notifications and Background Modes, and enable Background fetch and Remote notifications under Background Modes.


Follow the steps in the "Upload your APNs certificate" section of the Firebase docs.


If you need to disable the method swizzling done by the FCM iOS SDK (e.g. so that you can use this plugin with other notification plugins) then add the following to your application's Info.plist file.


<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
copied to clipboard
After that, add the following lines to the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method in the AppDelegate.m of your iOS project
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
copied to clipboard
Dart/Flutter Integration #
From your Dart code, you need to import the plugin and instantiate it:
import 'package:flutter_push_notifications/flutter_push_notifications.dart';

final FlutterPushNotifications _flutterPushNotifications = FlutterPushNotifications();
copied to clipboard
Next, you should probably request permissions for receiving Push Notifications. For this, call _flutterPushNotifications.requestNotificationPermissions(). This will bring up a permissions dialog for the user to confirm on iOS. It's a no-op on Android.
To get firebase token use:
_flutterPushNotifications.getToken().then((token) { });
copied to clipboard
For get data from clicked notification action use:
_flutterPushNotifications.onPushPress.listen((message) { });
copied to clipboard
example sending data from firebase:
{
"notification": {
"title": "Työvuorosi on päättynyt",
"text": "15.1. 8:00 - 16:00 Some great assignment",
"click_action":"NOTIFICATION_CATEGORY"
},
"to" : "DEVICE_TOKEN",
"data": {
"data": {
"route": "/assignments/123456"
}
}
}
copied to clipboard
Each NOTIFICATION_CATEGORY associated with the list of NotificationAction.
NotificationAction class allows you to set visible title of action, behavior and activation mode.
By default push notification will activate the app and action will have "clickable" behavior.
The "behavior" can be "default" which means action will have just "clickable" behavior and also can be "textInput" which means action will be presented as text input.
The "activationMode" can be "foreground" and "background". "Foreground" activation mode will open the app and you can process the data in the app. "Background" activation mode allows you to process the data in the background.
class NotificationAction {
String title;
String identifier;
/// foreground, background
String activationMode;
/// default, textInput
String behavior;

...
}
copied to clipboard
NotificationCategory class accepts identifier and list of actions which are associated with this category:
class NotificationCategory {
String identifier;
List<NotificationAction> actions;

...
}
copied to clipboard
Example of creating categories with the list of actions:
List<NotificationAction> viewActions = List<NotificationAction>();
NotificationAction action1 = NotificationAction(
title: 'First title',
identifier: 'FIRST_ACTION'
);
viewActions.add(action1);
NotificationAction action2 = NotificationAction(
title: 'Second title',
identifier: 'SECOND_ACTION'
);
viewActions.add(action2);
NotificationCategory firstCategory = NotificationCategory('FIRST_CATEGORY', viewActions);
List<NotificationAction> sendActions = List<NotificationAction>();
NotificationAction sendAction = NotificationAction(
title: 'Text input action',
identifier: 'TEXT_INPUT_ACTION',
behavior: 'textInput'
);
sendActions.add(sendAction)
NotificationCategory secondCategory = NotificationCategory('SECOND_CATEGORY', sendActions);
copied to clipboard
Finally you should register your categories:
_flutterPushNotifications.registerNotificationCategory([firstCategory, secondCategory]);
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.