Skip to content

Flutter quick start

Add push notifications to a Flutter app in five steps. The maintained takeed_flutter package is available from pub.dev and works on Android (through Firebase) and iOS (through Apple directly). Your Flutter project doesn't need google-services.json: Takeed gives the SDK the public Firebase settings after you connect the Firebase project in the dashboard.

On this page

Note

Coming from OneSignal? The calls have the same names under Takeed. See Moving from OneSignal.

1Add your keys in the dashboard#

Open Applications → choose the app → Settings → Notifications → Firebase and Apple keys → Add key.

Android: the Firebase service account JSON (Project settings → Service accounts → Generate new private key). It's secret: stored encrypted and never shown again. Takeed then reads the project's Android apps (package names) from Firebase itself and shows them on the key. When the SDK first connects from an Android package that is not there yet, Takeed reuses or creates the matching Android app in that Firebase project and returns its generated settings. You don't register the Android app or add google-services.json to Flutter yourself.

Firebase Management API must be enabled and the service account must be allowed to read and create Firebase apps. If Takeed can't manage the project, it says why; google-services.json remains an advanced fallback for an Android app that already exists.

iOS: in Apple Developer → Certificates, Identifiers & Profiles → Keys, create a key with Apple Push Notifications service (APNs), then enter the .p8 file, its Key ID, your Team ID and the app's Bundle ID. The Bundle ID must be identical in Apple Developer, Xcode and Takeed.

Copy the App ID from the top of the app page.

Branches. Every branch uses the app's keys. To give a branch its own (for example a branch shipped as a separate app on another Firebase project), choose it under Used by. Each device is matched automatically, the branch's own key first.

2Add the package#

yaml
dependencies:
  takeed_flutter: ^2.1.2

On Android there's nothing else to add: no google-services.json, no Google services Gradle plugin, no firebase_messaging. Add a white-on-transparent drawable named ic_stat_notification for the status bar icon; otherwise the app icon is used.

Configure Xcode for iOS notifications#

  1. From the Flutter project, open ios/Runner.xcworkspace in Xcode. Do not open Runner.xcodeproj.
  2. Select the blue Runner project, then the Runner target → Signing & Capabilities.
  3. Select your Apple Developer Team, keep Automatically manage signing enabled, and confirm that Bundle Identifier exactly matches the Bundle ID saved in Takeed and Apple Developer.
  4. Click + Capability and add Push Notifications to the Runner target. Xcode should add the aps-environment entitlement. Background Modes is not required for Takeed's normal alert notifications.
  5. In Apple Developer, create an APNs .p8 signing key if you don't already have one, then add its .p8 file, Key ID, Team ID and Bundle ID under the app's notification settings in Takeed. One team-scoped APNs key can serve multiple apps on the same Apple team; each Bundle ID still needs its own Apple key entry in Takeed so devices are matched to the correct APNs topic.
  6. Run flutter clean, flutter pub get, then cd ios && pod install. Open the workspace again and build the Runner target.

For the final check, install on a physical iPhone, allow notifications when your app asks, and send a test from Takeed. Debug builds use the APNs sandbox; TestFlight and App Store builds use production.

3Start the SDK#

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

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Takeed.initialize('YOUR-APP-ID');            // or: initialize('…', branch: 'north')
  runApp(const MyApp());
}

The device registers right away, even before the user allows notifications.

4Permission, users and taps#

dart
// Ask when it makes sense in your app. true = open settings if it was denied before.
await Takeed.Notifications.requestPermission(true);

// After your own sign-in, so your backend can send to this user on all their devices.
await Takeed.login(user.id);
// ...and on sign-out:
await Takeed.logout();

// Tags you can target when sending.
await Takeed.User.addTags({'plan': 'gold', 'city': 'Basra'});

// Taps and button presses, including the tap that opened the app.
Takeed.Notifications.addClickListener((event) {
  final data = event.notification.additionalData;   // the "data" you sent
  final button = event.result.actionId;            // button id, or null for the notification
});

Identity verification (app → Security): pass identityHash: to login, the hex HMAC-SHA256 of the user ID with the app's identity secret, computed by your backend. It stops anyone from claiming someone else's ID. Never put the secret in the app.

While the app is open, notifications are shown by default. To decide yourself:

dart
Takeed.Notifications.addForegroundWillDisplayListener((event) {
  isOnChatScreen ? event.preventDefault() : event.display();
});

5iOS images and buttons#

Images, action buttons and delivery receipts need a Notification Service Extension:

  1. In Xcode choose File → New → Target → Notification Service Extension.
  2. Name it NotificationService, use the same Apple team, and accept Activate when Xcode asks.
  3. Set the extension's iOS deployment target to iOS 12 or later, and keep its generated Bundle ID under the Runner Bundle ID, for example com.example.app.NotificationService.
  4. Replace the generated NotificationService.swift with the package file extension/NotificationService.swift.
  5. Run cd ios && pod install again, then build the Runner scheme.

No App Group is needed. If you only need plain title/body notifications, this extension is optional.

Send a test#

From Test notifications, send a notification to everyone, or send it from your backend:

bash
curl https://takeed-iq.com/api/v1/notifications \
  -H "Authorization: Key $TAKEED_KEY" -H "Content-Type: application/json" \
  -d '{"app_id": "YOUR-APP-ID", "included_segments": ["All"],
       "headings": {"en": "Hello"}, "contents": {"en": "It works"}}'

See Sending notifications for targeting, buttons, images and scheduling.

If nothing arrives#

The SDK logs problems with debugPrint, prefixed Takeed:.

Log Fix
no Firebase settings for com.your.app Check that the correct service account is connected and Firebase Management API is enabled, then reopen the app. Takeed should create or reuse this package automatically. Use google-services.json only as the fallback if project management is unavailable.
no push token Firebase couldn't start: usually the line above, or no Google Play services on the device.
unknown_platform_config No key in the app matches the device's Firebase project or Bundle ID.
not_found Wrong App ID in initialize.

Delivery errors from Firebase or Apple appear in each notification's details in Notification log.

The full SDK reference (every call, subscription state, troubleshooting) is in the package README.

Try it on your own number: your first organization comes with 5 free WhatsApp codes.

Create account