SDKsEarly accessDesigned and in development. No results yet. See what's left on the roadmap.
Flutter push notifications quickstart
Early access · launching soon. This guide adds the Oricato Flutter SDK (oricato_push 1.0.1) to a Flutter app,
sets up Android and iOS, and ends with a test notification on your own phone. It follows the flutter/ folder of
the SDK kit (oricato-sdk-1.0.1) step by step.
oricato_push is a Flutter plugin: Dart code plus its own Android (Java) and iOS (Swift) code. It is built on
firebase_messaging, and it uses flutter_local_notifications to render Android data messages, also from the
background isolate. You do not need the native Android or iOS SDK in a Flutter app. The only extra piece is the
optional iOS Notification Service Extension, which uses the kit’s ios/OricatoPush package (step 3).
The sample app in this guide is Lingora (com.lingora.app). Use your own application ID and bundle ID.
Prerequisites
| Requirement | Version or detail |
|---|---|
| Flutter | 3.27 or newer (Dart 3.6 or newer) |
firebase_core |
3.12 to 4.x |
firebase_messaging |
15.2 to 16.x |
flutter_local_notifications |
18 to 19.x (a dependency of the plugin; flutter pub get tells you if your app pins another major version) |
| Android | minSdk 21 (newer Firebase versions may need 23) |
| iOS | 13 or newer; a real iPhone to receive pushes |
| Firebase | The app is already set up for Firebase Cloud Messaging with flutterfire configure (google-services.json, GoogleService-Info.plist, firebase_options.dart) |
Before you touch the code:
- Create the project in the dashboard. Create one project for this app (Android and iOS share it), then open
Project → Settings → Add Oricato to your app and copy the Project ID, a UUID such as
0192e1aa-1111-7c22-8d33-445566778899. In the samples below it appears as<ORICATO_PROJECT_ID>. - Copy the API address from the same screen. In production it is
https://api.oricato.com: no path, no/api/v1, no trailing slash. In the samples it appears as<ORICATO_API_ADDRESS>. - Upload a least-privilege Firebase key. In Google Cloud Console for the app’s Firebase project, create a
service account with only the role Firebase Cloud Messaging API Admin, create a JSON key, and upload it in
the dashboard under Project settings → Firebase key. Do not use the default
firebase-adminsdk-…key. See Firebase and APNs credentials. - iOS: upload an APNs authentication key (
.p8) in Firebase console → Project settings → Cloud Messaging → Apple app configuration. Without it every iOS send fails withapns_auth_error.
Step 1: Add the package
Copy the oricato_push folder from the kit (oricato-sdk-1.0.1/flutter/oricato_push) into your app’s repository,
for example to packages/oricato_push. Then add it to the app’s pubspec.yaml:
dependencies:
firebase_core: ^4.11.0 # keep your current versions if they are inside the ranges above
firebase_messaging: ^16.4.1
oricato_push:
path: packages/oricato_push # relative to this pubspec.yaml
Run:
flutter pub get
Step 2: Set up Android
-
Turn on core library desugaring (needed by
flutter_local_notifications) inandroid/app/build.gradle.kts:android { compileOptions { isCoreLibraryDesugaringEnabled = true } } dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4") }If your app still uses Groovy (
android/app/build.gradle):android { compileOptions { coreLibraryDesugaringEnabled true } } dependencies { coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.4" } -
Add a small icon. Add a white-on-transparent drawable such as
android/app/src/main/res/drawable/ic_stat_notification.png(all densities, or an.xmlvector) and pass'ic_stat_notification'asdefaultSmallIconin step 4. A message can name another icon (fx_icon); unknown names fall back to the default icon, then to the app icon. -
Keep resources the server names by name. R8 resource shrinking removes drawables and sounds that are only referenced by name, so add
android/app/src/main/res/raw/oricato_keep.xml:<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@drawable/ic_stat_*,@raw/*" /> -
Put channel sounds in
android/app/src/main/res/raw/. For example,chime.mp3becomes the sound namechimein the dashboard. The plugin creates your Android notification channels from the channel list in your project settings. A channel whose sound resource is missing is not created: its messages use the built-in fallback channelfx_default, and an error is logged. See Android notification channels. -
Leave
AndroidManifest.xmlas it is. The plugin’s own manifest declares only these permissions, and they are merged into your app automatically:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />Receiving works through the messaging service that
firebase_messagingbrings with it, so a Flutter app does not declarecom.oricato.push.OricatoMessagingService. That service belongs to the native Android SDK only (see the Android quickstart). -
Keep
singleTopfor deep links. Launch URLs open withACTION_VIEW. For links into your own app, keepandroid:launchMode="singleTop"onMainActivity(the Flutter default) and handle the link with your router.
The plugin uses WorkManager for its receipt flush job. WorkManager initializes itself; if your app provides a custom
Configuration.Provider, nothing else is needed.
Step 3: Set up iOS
-
Open
ios/Runner.xcworkspace→ Runner target → Signing & Capabilities and add Push Notifications and Background Modes → Remote notifications. -
Foreground presentation follows
firebase_messaging. Add this afterFirebase.initializeAppin step 4:await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, ); -
Release builds accept only an
https://API address. Debug builds also allowhttp://for local testing (OricatoInitOptions.allowHttpInDebug, defaulttrue). -
Optional, recommended: add a Notification Service Extension for images and delivery receipts while the app is not running. Without it, iOS reports opened for every notification but delivered only while the app is in the foreground, and shows no images.
-
Copy the kit’s
ios/OricatoPushfolder into your repository, for example toios/Packages/OricatoPush. -
In Xcode (
Runner.xcworkspace) choose File → New → Target… → Notification Service Extension, name itNotificationService, and choose Don’t Activate for the scheme. -
Choose File → Add Package Dependencies… → Add Local…, select the
OricatoPushfolder, and add the productOricatoPushNotificationServiceto the extension target only (choose None for Runner). -
Replace the generated
NotificationService.swiftwith:import OricatoPushNotificationService class NotificationService: OricatoNotificationService {} -
In the extension’s
Info.plist, add the keyOricatoApiBaseURL(String) with your API address, for examplehttps://api.oricato.com. -
In Dart, call
await Oricato.setDeliveryReportedByExtension(true);right afterOricato.initialize(step 4), so the app stops reporting delivered itself. -
If the build then fails with “Cycle inside Runner”, open Runner → Build Phases and drag Embed Foundation Extensions above Run Script / Thin Binary. This is a known Flutter and app extension issue.
An app that already has another provider’s Notification Service Extension uses that one; iOS allows one per app. See the iOS quickstart for combining them.
-
Step 4: Initialize the SDK in main()
The background handler must be a top-level function annotated with @pragma('vm:entry-point'). If your app
already has one, add the Oricato.handleBackgroundMessage line to it. It returns true for Oricato pushes and
false for everything else.
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:oricato_push/oricato_push.dart';
import 'firebase_options.dart';
@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// Renders Android data messages and records `delivered`. Works without
// `Oricato.initialize` in this isolate (it uses the persisted settings).
if (await Oricato.handleBackgroundMessage(message)) return;
// … your own background handling for other pushes …
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
// Apps without their own handler can pass
// `oricatoFirebaseMessagingBackgroundHandler` instead.
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true, badge: true, sound: true,
);
await Oricato.initialize(
'<ORICATO_PROJECT_ID>', // Project ID from the dashboard (a UUID)
'<ORICATO_API_ADDRESS>', // API address, e.g. https://api.oricato.com
options: const OricatoInitOptions(
defaultSmallIcon: 'ic_stat_notification',
),
);
// await Oricato.setDeliveryReportedByExtension(true); // only with the iOS extension
Oricato.onNotificationOpened((n) {
// n.messageId, n.title, n.body, n.launchUrl, n.additionalData
// e.g. route on n.additionalData['type']
});
runApp(const MyApp());
}
If your app has no background handler of its own, register the ready-made one:
FirebaseMessaging.onBackgroundMessage(oricatoFirebaseMessagingBackgroundHandler);
What to know about initialize:
- Its signature is
Oricato.initialize(String projectId, String apiBaseUrl, {OricatoInitOptions options}). It throws anArgumentErrorwhen the Project ID is not a UUID or the address is not a valid URL. - It returns after local setup; the first registration with the server runs in the background. Call it on every app
start (it is idempotent) and after
Firebase.initializeApp(). - The options you pass are persisted and also used by the background isolate. Pass
launchUrlsAutoOpen: falsehere iffx_urlshould never open automatically. - The handler you register with
onNotificationOpenedalso receives the latest unhandled open from the last five minutes, such as the tap that cold-started the app.
OricatoInitOptions
| Field | Type | Default | What it does |
|---|---|---|---|
manageLocalNotifications |
bool |
true |
Android: Oricato initializes flutter_local_notifications in the main isolate and handles taps on the notifications it renders. |
handleFirebaseMessaging |
bool |
true |
Oricato listens to FirebaseMessaging.onMessage / onMessageOpenedApp and calls getInitialMessage() itself. |
defaultSmallIcon |
String? |
null |
Android drawable name of the default monochrome small icon. Falls back to the app icon. |
launchUrlsAutoOpen |
bool |
true |
Open fx_url when a notification is tapped. |
logLevel |
OricatoLogLevel? |
null |
Initial log level; null keeps the current or persisted level. |
allowHttpInDebug |
bool |
true |
Allow a plain http:// API address in debuggable builds. Release builds always need HTTPS. |
Ask for notification permission
Ask at a good moment in your onboarding, not on the first frame:
final status = await Oricato.requestPermission();
// OricatoPermissionStatus.granted, denied, notDetermined or provisional
This shows the Android 13+ POST_NOTIFICATIONS prompt or the iOS authorization prompt and reports the result. The
SDK reads the permission again every time the app comes back to the foreground, so an answer given in another
prompt or in phone Settings is reported too. See Notification permission.
Step 5: Report the language your app shows
The server picks the translation of a message by the subscription’s language. Report the locale your UI actually
uses, for example in your root widget’s State:
@override
void didChangeDependencies() {
super.didChangeDependencies();
Oricato.setLanguage(Localizations.localeOf(context).toLanguageTag());
}
Codes are normalized (pt-BR → pt, zh-TW → zh-hant). Without this call the SDK uses the device locale
(PlatformDispatcher.instance.locale); Oricato.setLanguage(null) follows the device locale again. See
Languages and localized messages.
Step 6: Apps that already use firebase_messaging or flutter_local_notifications
By default Oricato listens to FirebaseMessaging.onMessage and onMessageOpenedApp, calls getInitialMessage(),
and initializes flutter_local_notifications on Android. getInitialMessage() returns a message only once, and
flutter_local_notifications has one tap callback. If your app uses them itself (for example for locally
scheduled reminders), turn those parts off and forward the events:
await Oricato.initialize('<ORICATO_PROJECT_ID>', '<ORICATO_API_ADDRESS>',
options: const OricatoInitOptions(
handleFirebaseMessaging: false,
manageLocalNotifications: false,
defaultSmallIcon: 'ic_stat_notification',
),
);
FirebaseMessaging.onMessage.listen((m) async {
if (await Oricato.handleForegroundMessage(m)) return;
// … your foreground handling …
});
FirebaseMessaging.onMessageOpenedApp.listen((m) async {
if (await Oricato.handleMessageOpenedApp(m)) return;
// …
});
final initial = await FirebaseMessaging.instance.getInitialMessage();
if (!await Oricato.handleInitialMessage(initial)) {
// … your cold-start handling …
}
final plugin = FlutterLocalNotificationsPlugin();
await plugin.initialize(
const InitializationSettings(
android: AndroidInitializationSettings('ic_stat_notification'),
iOS: DarwinInitializationSettings(),
),
onDidReceiveNotificationResponse: (response) {
if (Oricato.handleNotificationResponse(response)) return;
// … your own notification taps …
},
);
await Oricato.handleLaunchDetails(
await plugin.getNotificationAppLaunchDetails());
This sample also imports package:flutter_local_notifications/flutter_local_notifications.dart. Every hook returns
true when the event was an Oricato notification. All hooks are idempotent (an open is handled once per message
ID), so forwarding something Oricato also saw is harmless.
Verify it works
Use a real phone; iOS push needs a real iPhone. Test on both Android and iOS, because the two platforms fail in different ways.
-
Turn on debug logging while you test, and watch the Flutter console:
await Oricato.setLogLevel(OricatoLogLevel.debug);Levels are
none,error,warn,info,debugandverbose. The SDK never logs secrets. -
Show the subscription ID in a debug screen so you can find this phone in the dashboard:
final id = await Oricato.getSubscriptionId(); debugPrint('Oricato subscription: $id'); -
Run the app once and allow notifications.
-
In the dashboard, open the project → Verify setup. The live checklist shows Firebase key works → Your app connected (your phone’s model appears) → press Send test notification. It sends “It works!” to this phone only, is not counted in statistics, and ticks arrived and, after you tap it, opened.
-
Under Keep this phone for testing, name the phone and press Mark as test device. The composer’s “Try it on your phone first” then sends to your test devices (Audience → Test devices).
-
Tap the notification and check that your
onNotificationOpenedhandler runs, both with the app in the background and after a cold start.
Troubleshooting
Nothing arrives while the app is in the background or closed (Android).
The background handler must be a top-level function (not a method or a closure) annotated with
@pragma('vm:entry-point'), and it must be registered with FirebaseMessaging.onBackgroundMessage in main() as
in step 4. Without the annotation, release builds can strip the function and the background isolate cannot run it.
If your app already has a handler, make sure it calls Oricato.handleBackgroundMessage(message) first.
Cold-start taps never reach onNotificationOpened.
getInitialMessage() returns a message only once. If your app or another package calls it first, Oricato never sees
the tap. Set handleFirebaseMessaging: false and forward with Oricato.handleInitialMessage (step 6). The same
applies to flutter_local_notifications: if your app initializes it, set manageLocalNotifications: false and
forward with handleNotificationResponse and handleLaunchDetails.
A foreground handler cannot hide a notification on iOS.
This is a known platform limit. On Android, returning false from Oricato.onForegroundNotification suppresses
the notification. On iOS the display follows setForegroundNotificationPresentationOptions.
“Wrong Project ID” in the log. The server answered HTTP 404: the Project ID or the API address is wrong. Copy both again from Project → Settings → Add Oricato to your app. The SDK stops calling the server until the next app start.
Android: the app never connects, and the FCM token is null.
Look for BAD CONFIG from Firebase Installations in adb logcat. This happens when the Android API key in Google
Cloud Console is restricted to Android apps but your app’s SHA-1 certificate fingerprint (debug, release and Play App
Signing) is not on the list. Add the missing SHA-1 fingerprints for your package name, or relax the restriction,
then reinstall the app.
iOS: sends fail with apns_auth_error.
No APNs authentication key (.p8) is uploaded in Firebase, or it belongs to another Apple team. Upload it in
Firebase console → Project settings → Cloud Messaging → Apple app configuration, then send a new test.
Android: notifications arrive without sound or as silent.
Android fixes a channel’s sound, vibration and importance when the channel is created. To change them, create a new
channel ID in your project’s channel list (and ship its sound in res/raw); editing an existing ID has no effect on
phones that already have it. Some OEM builds also demote notifications to silent on their own: on TECNO phones with
HiOS, for example, check the app’s notification settings on the phone and allow banners and sound.
iOS: no images, or delivered stays low.
Add the Notification Service Extension (step 3) and call Oricato.setDeliveryReportedByExtension(true). Without
it, iOS reports delivered only for pushes received while the app is in the foreground.
For more cases, see Troubleshooting delivery.
Next steps
- Users, external IDs and tags:
Oricato.setExternalUserIdandOricato.setTags. - Languages and localized messages.
- Delivery receipts and analytics:
Oricato.trackEventfor conversions. - API keys and App Check:
Oricato.setAppCheckTokenProvider. - Migrate from OneSignal: run
onesignal_flutterandoricato_pushside by side during one release.