Flutter SDK Integration
Last updated
Last updated
Quick Steps Guidelines
Step 1. Install Flutter
Add the following lines to your project
Step 2. Setup Android
Step 3. Setup iOS
Step 4. Calling Dart Methods
If you use onPrem
set baseUrl
as shown in Step 4.
Flutter SDK integration completed 👏
Please find the Onboarding Checklist for Swift and Flutter below. Follow the titles in the checklist to ensure you have completed each essential step in your onboarding process with Netmera.
To use this package as a library in your Flutter project, follow these steps:
Add the following lines to your project's pubspec.yaml
file under the dependencies
section.
You can install packages from the command line with Flutter:
You don't need to include extra Netmera SDK libraries for both native sides (Android & iOS).
Navigate to Netmera Panel > Developers > Netmera Onboarding and choose Android.
Click on Android > Start to proceed.
Netmera uses Firebase Cloud Messaging (FCM) to deliver push messages to the Android devices. Therefore, you should create and configure a project on Firebase Developers Console.
At the end of the Firebase configuration, you will have a New Private Key folder of your project. That folder must be uploaded to Developers > Netmera Onboarding > Android > Step 2: Create A Firebase Configuration > FCM Service Account Key section on Netmera Panel.
Firebase Cloud Messaging Configuration
Upload FCM Service Account Key on Netmera Panel
Select the appropriate SDK for your application development framework from the following options: Native Android, Flutter, React Native, Unity. Note: The subsequent instructions on this page are specific to the Flutter SDK.
⚠️ Warning: Do not use the API key from your test panel when setting up or deploying your production app. Each panel has its own unique API key. Even if you log in with a different account, this encrypted key stays the same. Using the wrong key can result in data being sent to the incorrect environment, causing potential issues or errors in your application.
In your project's build.gradle file, add the following dependencies.
In your app's build gradle file, add the following dependency.
Add the following into the top of app's build.gradle file.
Create Application Class (Java)
Create an application class that extends FlutterApplication
.
Replace <YOUR GCM SENDER ID>
, <YOUR HMS SENDER ID>
, and <YOUR NETMERA API KEY>
with your actual values.
Inside your Dart class, add the following code to set up event handlers:
Custom Firebase Messaging Integration
If you have a custom Firebase Messaging integration, use the following code:
Important Note:
If you're building your Flutter project with flutter run --release
and need to add the @pragma('vm:entry-point')
annotation to the _firebaseMessagingBackgroundHandler
method, you can modify the code block as follows.
Adding the @pragma('vm:entry-point')
annotation ensures that this method is correctly recognized as an entry point when building your project in release mode. This is important for background message handling in Flutter, and the annotation helps Flutter identify and execute the method as expected.
Custom Huawei Messaging Integration
If you have a custom Huawei Messaging integration, use the following code.
Applications targeting API Level 33 and above are empowered to request push notification permissions from users as needed. This decision is in the hands of the Android operating system.
For all applications with a target level below API Level 33, when the application is running on a device with Android 13 or higher, the operating system will automatically prompt the user for these permissions during the initial creation of notification channels.
Since Netmera SDK creates notification channels after receiving the initialization response, and we advise you to call the init
method at the application level, this permission request will be triggered automatically as soon as the application is launched. However, this automatic request applies only to applications targeting Android API Level 32 and below, and it takes effect on devices running Android 13 or higher.
On devices running Android 12 and earlier, the system already behaves as if this permission has been granted by default.
If you don't request notification permission at runtime, you can request it by calling the requestPushNotificationAuthorization()
method. Note: Notification runtime permissions are required on Android 13 (API 33) or higher. Therefore, before calling the method, make sure your project targets an API of 33 and above.
You can call the areNotificationsEnabled()
method if you need to know the status of permissions.
This method triggers the necessary methods to send a request for permissions to the system at any time.
Push Enable/Disable Notes:
The users triggers the requestNotificationPermissions()
method, the user grants permission (push enable request is sent).
After the customer receives a denial, they send the same request again (it is recommended by Google not to resend it immediately after receiving a denial), and the SDK opens the Notification settings that are specific to that application on the operating system. The user grants notification permission from the settings and returns to the application (push enable request is sent).
The users triggers the requestNotificationPermissions()
method, the user denies permission (push disable request is sent).
After the customer receives a denial, they send the same request again (it is recommended by Google not to resend it immediately after receiving a denial), and the SDK opens the Notification settings that are specific to that application on the operating system. The user cancels (presses the back button) (push disable request is sent).
To get a visual guide on how to integrate Netmera into your iOS app, you may watch our iOS integration video below.
Below you may also see the written steps of creating an Apple Push Notification Certificate.
We send push notifications using APNS (Apple Push Notification Service). Therefore, you need to obtain an Apple Push Notification Certificate from www.developer.apple.com using your account. Once you have the certificate, you should export it using Keychain Access and add it to the iOS page in the panel's left menu under Developer > Push Backend.
Important Notes on Bundle ID:
Make sure to add the certificate generated with the bundle ID of your project to the panel, and set the bundle ID of your project in the panel as well. The bundle ID of your project, the bundle ID of the certificate, and the bundle ID set in the panel should all match.
In case of having problems sending push notifications when you build from Xcode:
Check the certificate type on the Developer > Backend Transfer > iOS page in the menu on the left. If you downloaded the app from the store or are testing it via TestFlight, the certificate type must be "prod". If you are compiling from Xcode, the certificate type must be selected as "dev".
Navigate to the "iOS" folder in your terminal and run the following command to install dependencies:
If you're using Swift, you'll need to include the following imports in your Runner-Bridging-Header.h
file.
If you want to enable Android-like message sending from iOS to Dart, consider configuring your AppDelegate
class as follows.
For instance, if you trigger FNetmeraService.handleWork(ON_PUSH_RECEIVE, dict:["userInfo" : userInfo])
from AppDelegate
, the following Dart method will be triggered
In Flutter applications targeting iOS, it is necessary to request notification permissions. This can be achieved seamlessly within your Flutter codebase. Below is an example code snippet demonstrating how to request notification authorization specifically for iOS using Netmera's Flutter SDK:
Example Project: For a practical demonstration, you can refer to the sample project provided by Netmera on GitHub. The example project showcases how to integrate Netmera's Flutter SDK and includes the code snippet for requesting notification authorization on iOS:
Netmera Flutter Example Project
Enable push notifications for your app by navigating to Signing & Capabilities > Capability > Push Notifications.
The following methods in iOS are used for managing email subscription preferences within the Netmera mobile SDK. Here's an explanation of each method:
This method is used to check whether the user has allowed email subscriptions through the Netmera SDK. It returns a Boolean value.
This method is used to set the user's preference for email subscriptions within the Netmera SDK.
For instructions on using iOS 10 Media Push, please refer to the relevant documentation on page Former iOS Push.
onPrem
If you use onPrem set baseUrl,
Feel free to use the following documentation for further information.
Flutter SDK integration has been successfully completed, and your devices are now ready to receive the following types of push notifications sent via the Netmera Dashboard:
Standard Push Notifications
Interactive Push Notifications (If you've configured and published them using the Dashboard)
Push Notifications with Web View Content
Push Notifications with Deeplinks (If your application supports URL Scheme-based deeplinks and you've configured the application's URL Scheme in the Dashboard.)