Skip to content

Flutter SDK

Deliver sponsored push notifications in your Flutter app on Android. The plugin is a thin wrapper — registration, notification display and tracking all run in the native Android SDK.

Android only. There is no iOS implementation.

What you need first

  • Flutter 3.0+ with an Android build target.
  • A Firebase project with google-services.json in android/app/ and the com.google.gms.google-services plugin applied.
  • Your Firebase service-account JSON uploaded to your dlserve placement in the dashboard. We send through your own Firebase project, so until that file is uploaded devices register fine and nothing is ever delivered.

1. Add the dlserve repository

The plugin depends on the native core ai.dlserve:dlserve-android:0.2.0, served from https://maven.dlserve.ai. Declare the repository in your app's Android project; the plugin deliberately does not declare it for you, because a repository declared inside a plugin module is a build failure on current Gradle setups.

Flutter's current template keeps repositories in android/build.gradle.kts:

kotlin
allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://maven.dlserve.ai")
            content { includeGroup("ai.dlserve") }
        }
    }
}

Older projects have the same block in Groovy, in android/build.gradle:

groovy
allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://maven.dlserve.ai'
            content { includeGroup 'ai.dlserve' }
        }
    }
}

If your project instead resolves repositories in android/settings.gradle.kts under dependencyResolutionManagement, put the same maven { ... } block there — in that mode Gradle refuses a repository declared anywhere else.

2. Add the plugin

dlserve_flutter is not published to pub.dev yet — ask your dlserve contact for it and add it as a path dependency in pubspec.yaml:

yaml
dependencies:
  dlserve_flutter:
    path: ../dlserve_flutter

Then run flutter pub get.

3. Initialize

dart
import 'package:dlserve_flutter/dlserve_flutter.dart';

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    Dlserve.init('your-app-id');
  }
}

your-app-id is the App ID shown on your placement in the dashboard. Device registration, FCM token management and notification display are all handled natively from there.

4. Ask for the notification permission (Android 13+)

Android 13 and newer post nothing until the user grants POST_NOTIFICATIONS. Request it with whichever permission package your app already uses, before you expect notifications to appear.

Sponsored notifications post to their own "Sponsored offers" channel, which the user can turn off without touching your app's other notifications.

Users and tags

dart
Dlserve.login('user-123');
Dlserve.logout();
Dlserve.setTags({'plan': 'premium', 'trial': null}); // a null value deletes the key

Limits: user id ≤ 256 characters, ≤ 20 tags, key ≤ 64 characters, value ≤ 128 characters.

logout() is local-only — it clears the stored user id on the device, sends nothing, and is not an opt-out.

API reference

MethodDescription
Dlserve.init(String appId)Initialize and register the device. Call once, early.
Dlserve.login(String externalId)Associate a user id.
Dlserve.logout()Clear the association. Local only.
Dlserve.setTags(Map<String, String?> tags)Set tags; a null value deletes the key.

All methods return Future<void> and complete when the native call returns.

Turning notifications off for a device is available in the native Android SDK (Dlserve.setPushEnabled) and is not exposed through this plugin yet; users can still turn off the "Sponsored offers" channel in Android settings.

FCM routing

The plugin delegates FCM message handling to the native Android SDK. Sponsored pushes are displayed with a "Sponsored" label; everything else passes through to your app's own handler untouched.

Troubleshooting

What you seeWhyFix
Could not find ai.dlserve:dlserve-android:0.2.0The repository is missing from your Android projectStep 1
Build was configured to prefer settings repositories over project repositoriesIt was declared in the wrong file for your resolution modeStep 1, the settings form
Devices register, nothing arrivesThe service-account JSON is not on the placementUpload it in the dashboard
No device appears at allThe google-services plugin or google-services.json is missing"What you need first"

Next: Android (Kotlin) · Troubleshooting