LogDrop
Sdk

LogDrop Flutter SDK

The LogDrop Flutter SDK provides a Dart-friendly API on top of the native iOS and Android SDKs.

It lets you initialize LogDrop once in your Flutter app and automatically forward logs, crashes and network data to the LogDrop backend.


1. SDK Installation

The Flutter SDK is the logdrop_flutter_sdk package. It runs on the native iOS and Android SDKs, so after adding the package you also set the App ID in the native projects, as described in Native Configuration.

Minimum requirements: Android 6.0 and iOS 15.0. Your app's iOS deployment target must be 15.0 or later.

1.1. Add the package to pubspec.yaml

In your Flutter project, open pubspec.yaml and add:
dependencies:
  flutter:
    sdk: flutter

  logdrop_flutter_sdk: ^3.1.0
The latest version is resolved automatically at build time.
Then run:
flutter pub get

2. Initialization

LogDropFlutter.init() starts LogDrop in the Dart layer and registers the handlers that report Flutter and Dart errors. Call it early, before runApp, so that errors during startup are captured. It takes no App ID: you set that in the native projects in Native Configuration.

Initialize LogDrop in your main() method using LogDropFlutter.init after ensuring bindings are initialized.

In your lib/main.dart:
import 'package:flutter/material.dart';
import 'package:logdrop_flutter_sdk/logdrop_flutter.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await LogDropFlutter.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'LogDrop SDK Demo',
      debugShowCheckedModeBanner: false,
      home: const Scaffold(
        body: Center(
          child: Text('Hello LogDrop'),
        ),
      ),
    );
  }
}

End-to-end tracing

From SDK 3.0.7, requests your Dart code makes also carry a W3C traceparent header, so you can follow them into a backend traced by LogDrop. See Tracing.


3. Native Configuration

Since the Flutter SDK bridges to native layers, you must configure your LogDrop Application ID (App ID / API Key) and settings (like base URL) in your native iOS and Android projects. Use the Mobile SDK App ID from Project Settings → App ID in the LogDrop panel.

3.1. Android Setup

On Android, you add the LogDrop repositories and the LogDrop Gradle plugin, which uploads ProGuard/R8 mapping files so that crash reports from release builds are readable. You then start the native Android SDK from your Application class.

Edit your project-level android/build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral()
        maven(uri("https://artifactory.logdrop.io/repository/logdrop-gradle-plugin/"))
    }
    dependencies {
        classpath("io.logdrop.gradle:plugin:1.1.3")
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://artifactory.logdrop.io/repository/android-logdrop-sdk/" }
        maven { url "https://artifactory.logdrop.io/repository/logdrop-gradle-plugin/" }
    }
}

Edit your app-level android/app/build.gradle:

apply plugin: "io.logdrop.gradle.plugin"
// or
plugins {
    ... // other plugins
    id("io.logdrop.gradle.plugin")
}
android {
    ...
    defaultConfig {
        buildConfigField("String", "LOGDROP_BASE_URL", "YOUR_SERVER_URL")
        buildConfigField("String", "LOGDROP_APP_ID", "YOUR_APP_ID")
        buildConfigField("boolean", "LOGDROP_LOGCAT_ENABLED", "true")
    }
}

Create a file named logdrop-services.json under the android/app folder. It tells the LogDrop Gradle plugin which LogDrop project and App ID belong to your package name:

{
  "base_url": "https://server.logdrop.io",
  "projects": {
    "YOUR_APP_PACKAGE_NAME": {
      "app_id": "YOUR_APP_ID"
    }
  }
}

Edit your YourApp.kt file in the Android module of your Flutter project as follows. This starts the native Android SDK with the values you set in build.gradle:

import android.app.Application
import com.logdrop_flutter_sdk.LogDropFlutter

class YourApp : Application() {
    override fun onCreate() {
        super.onCreate()
        LogDropFlutter.initLogDrop(
            logcatEnabled = BuildConfig.LOGDROP_LOGCAT_ENABLED,
            appId = BuildConfig.LOGDROP_APP_ID,
            baseUrl = BuildConfig.LOGDROP_BASE_URL,
            context = this.applicationContext
        )
    }
}

3.2. iOS Setup

On iOS, you store the App ID, base URL and logging setting in Info.plist, then start the native iOS SDK with those values from AppDelegate.swift.

Add the following keys to your Runner/Info.plist file:

<key>LogDropBaseUrl</key>
<string>YOUR_API_URL</string>

<key>LogDropAppId</key>
<string>YOUR_APP_ID</string>

<key>LogDropLoggingEnabled</key>
<true/>

Update AppDelegate.swift:

import Flutter
import UIKit
import logdrop_flutter_sdk

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      let infoDict = Bundle.main.infoDictionary
      let appId = infoDict?["LogDropAppId"] as? String ?? ""
      let baseUrl = infoDict?["LogDropBaseUrl"] as? String ?? ""
      let loggingEnabled = infoDict?["LogDropLoggingEnabled"] as? Bool ?? true
     
      LogDropFlutter.initialize(
        appId: appId,
        baseUrl: baseUrl,
        loggingEnabled: loggingEnabled,
        pushAppGroupSuiteName: "group.com.yourcompany.yourapp"
      )

      GeneratedPluginRegistrant.register(with: self)
      return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

4. Crash Tracking

The Flutter SDK automatically registers crash tracking listeners for both Flutter framework errors and uncaught Dart errors under the hood during LogDropFlutter.init(...).

The native iOS and Android layers handle platform-level native crashes (see their respective SDK docs for symbol/mapping files upload). Without those files, native stack traces from release builds are not readable.

Make sure the native LogDrop SDK is initialized before these handlers through the Android and iOS native setup described above.


5. Logging Methods

Logging methods record your own messages in LogDrop, so you can see what the app did before a problem. Each call sets a level (error, warning, info or debug), a tag that names the part of the app, the message and, optionally, a LogFlow. After upload, the logs appear on the panel's Logs page.

Use the LogDrop logging API from anywhere in your Flutter code:
// Without flow
LogDrop.logError(tag: 'PaymentActivity', message: 'Payment failed');        // Error
LogDrop.logWarning(tag: 'Network', message: 'Slow network');                 // Warning
LogDrop.logInfo(tag: 'Auth', message: 'User logged in');                     // Info
LogDrop.logDebug(tag: 'Parser', message: 'Parsing response');                // Debug

// With flow
final flow = LogFlow(
  name: 'SuccessTransaction',
  id: transactionId,
  customAttributes: {
    'amount': '149.90',
    'currency': 'TRY',
  },
);

LogDrop.logInfo(tag: 'Transaction', message: 'Transaction completed successfully.', logFlow: flow);

Logs are stored locally on the device first.

To trigger an upload to the server:

LogDrop.sendLogs();
  • Schedules a background job that runs approximately 60 seconds later.
  • If a job is already scheduled or running, additional calls do not create new jobs.

6. LogFlow

LogFlow lets you group related logs under a specific business flow or transaction. A flow has a name, an ID and optional attributes. Pass the same flow to every log of one piece of work, such as one checkout, so the panel can show those logs together.

final flow = LogFlow(
  name: 'CartCheckout',
  id: checkoutId,
  customAttributes: {
    'itemsCount': '3',
    'total': '249.90',
    'currency': 'TRY',
  },
);

LogDrop.logInfo(tag: 'Checkout', message: 'Checkout started.', logFlow: flow);
LogDrop.logInfo(tag: 'Checkout', message: 'Payment step opened.', logFlow: flow);
LogDrop.logInfo(tag: 'Checkout', message: 'Checkout completed.', logFlow: flow);

In the LogDrop panel you can filter and analyze logs by flowName and flowId.


7. Push Notification Integration

With push integrated, you can send alert, rich, in-app, deep-link and internal-browser messages to the app from the panel. The panel's Fetch Logs also uses a silent LogDrop push to ask a device to upload its logs. For this, the app passes its push token and LogDrop's messages to the SDK.

Keep your application's existing push provider integration. Forward its token and messages identified by LogDrop.isLogDropPush(...) to the Flutter bridge.

7.1. Android with FlutterFire Messaging

On Android, LogDrop pushes arrive through Firebase Cloud Messaging (FCM), or through Huawei Mobile Services (HMS) on Huawei devices. The SDK needs the device's push token to reach the device, and each LogDrop message to show it or to run a fetch-logs request. LogDrop.isLogDropPush(...) picks out LogDrop's messages, so your app's other messages are left alone.

Register the background handler at top level. Forward LogDrop messages from both foreground and background handlers, and register both the current FCM token and future token updates.

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:logdrop_flutter_sdk/logdropsdk.dart';

Map<String, String> _logDropData(RemoteMessage message) =>
    message.data.map((key, value) => MapEntry(key, value.toString()));

@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();

  final data = _logDropData(message);
  if (await LogDrop.isLogDropPush(data)) {
    LogDrop.onRemoteMessageReceived(data);
  }
}

Future<void> registerLogDropPushHandlers() async {
  FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

  final messaging = FirebaseMessaging.instance;
  final token = await messaging.getToken();
  if (token != null) {
    LogDrop.onNewFcmPushToken(token);
  }

  messaging.onTokenRefresh.listen(LogDrop.onNewFcmPushToken);
  FirebaseMessaging.onMessage.listen((message) async {
    final data = _logDropData(message);
    if (await LogDrop.isLogDropPush(data)) {
      LogDrop.onRemoteMessageReceived(data);
    }
  });
}

Call registerLogDropPushHandlers() during startup after initializing LogDrop and Firebase. For HMS, forward the provider token with LogDrop.onNewHmsPushToken(token) and use the same message forwarding methods.

7.2. iOS APNs Forwarding

On iOS, LogDrop pushes arrive through Apple Push Notification service (APNs). The SDK needs the APNs device token to reach the device, and the remote notifications to handle LogDrop's messages, including silent fetch-logs requests.

Forward the APNs token and remote notifications from AppDelegate.swift:

override func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
    LogDropFlutter.onNewApnsToken(apnsToken: deviceToken)
}

override func application(
    _ application: UIApplication,
    didReceiveRemoteNotification userInfo: [AnyHashable: Any],
    fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
    LogDropFlutter.onRemoteMessageReceived(userInfo: userInfo)
    completionHandler(.newData)
}

7.3. iOS Notification Service Extension

A Notification Service Extension lets LogDrop process and record an alert push even when the app is not running. The app and the extension share data through an App Group, so both must use the same App Group identifier.

Complete the iOS Notification Service Extension and App Group setup. Use the same App Group identifier in LogDropFlutter.initialize(...), both target entitlements, and the extension configuration:

With Swift Package Manager, add the LogDrop-iOS package to the extension with Up to Next Major Version from 2.1.0. Xcode then uses the same LogDrop version as the plugin, so the extension needs no update when you upgrade the plugin.

With CocoaPods, add the iOS SDK that ships with the plugin to the extension target in ios/Podfile, then run pod install:

target 'NotificationServiceExtension' do
  use_frameworks!
  pod 'LogDrop', :path => '.symlinks/plugins/logdrop_flutter_sdk/ios/ios-sdk'
end
import LogDropSDK

final class NotificationService: LogDropNotificationServiceExtension {
    override func logDropConfiguration() -> LogDropConfig? {
        LogDropConfig.Builder()
            .setAppId("YOUR_APP_ID")
            .setBaseUrl("YOUR_BASE_URL") // Optional: for self-hosted LogDrop
            .setPushAppGroupSuiteName("group.com.yourcompany.yourapp")
            .build()
    }
}

7.4. Show a Pending Push Action

In-app messages and internal-browser pushes open inside your app, not in the notification tray. LogDrop keeps them in a queue until your app asks to show them.

When the application UI becomes active, ask LogDrop to present a queued in-app popup or internal-browser action:

final result = await LogDrop.showPendingPushPopup();
// shown / nothingToShow / notInitialized

A deep link opens a specific screen of your app from a link, a LogDrop push or an in-app message. Your app does the routing; forwarding the URL lets LogDrop track the deep link.

Keep routing links through your existing Flutter router. After the application receives and resolves a URL, forward that URL once to LogDrop:

await LogDrop.trackDeepLink(uri.toString());

Use the same call for cold-start and already-running link deliveries.


9. User Identification (UUID Customization)

By default, logs are tied to a device identifier. Set your own user ID, for example after the user signs in, when you want to find that user's data in the panel. You can then search for it as User UUID on the Devices page.

To associate logs with your own user ID:

LogDrop.userUpdate('user-1234@example.com');
You can use any stable, unique identifier, for example:
  • Email address

  • Internal customer ID

  • Other application-specific user ID

    All subsequent logs will be associated with this user in the LogDrop panel.


10. Custom Events

Use custom events to track application-specific actions that are not covered by LogDrop's built-in events. Send a stable event name together with optional JSON-compatible properties. You do not need to set anything up in the panel first.

10.1. Track a Custom Event

Call trackCustomEvent when the action happens, with the event name and, optionally, a map of properties that describe it.

await LogDrop.trackCustomEvent('purchase_completed', {
  'coupon_code': 'SUMMER10',
  'amount': 49.9,
  'item_count': 2,
  'is_first_order': true,
});

Properties are optional. To track an event without properties:

await LogDrop.trackCustomEvent('onboarding_completed');

Provide only the readable event name and properties. Event and property codes shown in the panel are managed by LogDrop.

10.2. Supported Property Values

Custom properties may contain strings, numbers, booleans, null, nested maps, and lists. Map keys must be strings.

await LogDrop.trackCustomEvent('product_viewed', {
  'sku': 'LD-100',
  'viewed_at': DateTime.now().toUtc().toIso8601String(),
  'product': {
    'name': 'LogDrop Hoodie',
    'price': 79.95,
  },
  'categories': ['merch', 'hoodies'],
  'variants': [
    {'color': 'black', 'size': 'M'},
    {'color': 'green', 'size': 'L'},
  ],
  'campaign': null,
});

Flutter's method channel accepts codec-compatible values. Convert DateTime instances to ISO-8601 strings before passing them. Nested maps and lists remain structured values.

10.3. Naming and Property Types

LogDrop groups custom events by name and records the type of each property. Follow these rules so that one action always arrives as the same event, with the same property types.

  • Use stable and consistent names. For example, do not alternate between purchase_completed and purchaseCompleted for the same event.
  • Do not put IDs, timestamps, or other dynamic values in the event name. Add them as properties instead.
  • Do not use the name of a LogDrop default event for a custom event.
  • Keep each property's type stable. For example, always send amount as a number rather than sometimes sending a number and sometimes a string.
  • Reusing the same event name updates the same custom event schema. Changing the name creates a different custom event.

If a property is later sent with a different type, LogDrop keeps the event but marks the property as a type conflict in the panel. Type conflict tracking helps find integration mistakes; it should not be used as a replacement for a stable event contract.

10.4. Limits and Validation

The native SDK checks every event against these limits before it sends the event.

  • Event names can contain up to 128 characters.
  • Property names can contain up to 128 characters.
  • One event can contain up to 100 top-level properties.
  • The complete properties JSON can contain up to 16 KB in UTF-8, including property names, primitive values, nested objects, and arrays.
  • Event names and property names cannot be empty.
  • Property values must be JSON-compatible.

If validation fails, the native SDK rejects the complete event and writes the reason to the SDK log. Names, properties, and payloads are never silently truncated.

10.5. Panel Behavior

No custom event definition is required before tracking. After the first valid event reaches LogDrop, the Events page shows the event, its generated code, observed properties, property types, and any type conflicts. You can then use the event in event details and Event Analytics funnels.


11. Custom User Attributes

Custom user attributes let you attach stable profile information to the current LogDrop device and use it for segment-based push targeting in the panel. Customer Journeys also use them as the recipient and consent fields of SMS and WhatsApp steps. Call these APIs after LogDropFlutter.init() has completed.

11.1. Set or Update Attributes

Call setCustomAttributes with string keys and values, for example when the user's plan or language changes.

await LogDrop.setCustomAttributes({
  'plan_type': 'premium',
  'country': 'TR',
  'preferred_language': 'tr',
});

The update is an additive upsert. New keys are added and existing keys receive the new value, while attributes omitted from the call remain unchanged. Valid changes are persisted by the native SDK and synchronized with LogDrop automatically.

11.2. Remove an Attribute

Remove an attribute when it no longer applies, for example after a plan ends.

await LogDrop.removeCustomAttribute('plan_type');

Removing a key also synchronizes the deletion with LogDrop, so the previous value is no longer available for future segment targeting.

11.3. Limits and Validation

The native SDK checks every update against these rules. An update that breaks a rule is rejected, and the device keeps its previous attributes.

  • Attributes must be provided as a Map<String, String>.
  • A device can have up to 30 custom attributes in total.
  • Keys must contain only letters, numbers, underscores (_), or hyphens (-).
  • Keys can contain up to 64 characters.
  • Values must be non-blank strings containing up to 256 characters.
  • If one entry in a call is invalid, the native SDK rejects the complete update.
  • If the merged result would exceed 30 keys, the previous attribute set remains unchanged.

Custom user attributes are different from LogFlow.customAttributes. User attributes describe a device for audience targeting, while flow attributes add context only to the logs recorded with that LogFlow.

11.4. Use Attributes in the Panel

A segment sends a push only to the devices whose attributes match your filter, for example every device with plan_type set to premium.

After the device synchronizes, open Push Notification → Send Push, select Segment under Recipients, and build a filter with the attribute key. See Segment Targeting with Custom Attributes.


12. Screen Tracking

From SDK 3.1.0, LogDrop records the screen the user is looking at. Each screen change is a screen_view event with the screen name, the previous screen and how the screen was detected. App Health uses the screen names to break performance metrics down by screen.

App Health metrics

The native SDKs also send app start time, slow and frozen frames, freezes, memory, CPU, battery, network and HTTP timing metrics with each session for the panel's App Health page. They need no code.

12.1. Navigator Routes

A Flutter app runs in a single native screen, so Flutter screens are named from Dart. Add LogDropNavigatorObserver to your navigator. It tracks every named page route when it becomes visible (push, pop back to it, replace) and skips unnamed routes, dialogs and bottom sheets.

import 'package:logdrop_flutter_sdk/logdropsdk.dart';

MaterialApp(
  navigatorObservers: [LogDropNavigatorObserver()],
  routes: {
    '/': (_) => const HomePage(),
    '/product': (_) => const ProductPage(),
  },
);

Routes pushed with MaterialPageRoute need a name to be tracked: MaterialPageRoute(settings: const RouteSettings(name: '/product'), builder: ...). If your router puts IDs in route names, map them to a stable name with nameExtractor; return null to skip a route.

LogDropNavigatorObserver(
  nameExtractor: (settings) => settings.name?.split('?').first,
);

12.2. Manual Screens

For screens that are not routes, such as tabs or custom UIs, call trackScreen. A screen_view is recorded when the name differs from the current screen.

await LogDrop.trackScreen('ProductDetail');
  • Keep screen names stable and free of user data: ProductDetail, not the product's name.

  • Names longer than 100 characters are cut; blank names are ignored.

    12.3. Native Automatic Tracking

    The native SDKs can track Activities and view controllers automatically, but in a Flutter app they would only see the Flutter host screen. LogDropFlutter.initLogDrop (Android) and LogDropFlutter.initialize (iOS) therefore turn it off by default. If your app also shows its own native Activities or view controllers, turn it on:

LogDropFlutter.initLogDrop(
    logcatEnabled = BuildConfig.LOGDROP_LOGCAT_ENABLED,
    appId = BuildConfig.LOGDROP_APP_ID,
    baseUrl = BuildConfig.LOGDROP_BASE_URL,
    context = this.applicationContext,
    automaticScreenTracking = true
)
LogDropFlutter.initialize(
  appId: appId,
  baseUrl: baseUrl,
  loggingEnabled: loggingEnabled,
  automaticScreenTracking: true
)

If you build the native LogDropConfig yourself instead, call .automaticScreenTracking(false) (Android) or .setAutomaticScreenTracking(false) (iOS) and track Flutter screens as shown above.


13. Troubleshooting

Check these points when data does not reach LogDrop, custom events or attributes are missing, or pushes do not arrive.

  • Verify that the native iOS and Android SDK configurations are correctly set up.
  • Ensure LogDropFlutter.init(...) is called early in app startup.
  • Check that the logdrop_flutter_sdk package version matches the native SDK versions if you override them.
  • Confirm that custom event names do not match LogDrop default event names.
  • Check native SDK logs when a custom event is missing; invalid names, properties, or oversized payloads are rejected locally.
  • Check native SDK logs when custom user attributes are missing; invalid updates and updates exceeding 30 keys are rejected locally.
  • For FCM integration:
    • Confirm that Firebase is initialized before using FirebaseMessaging.
    • Make sure background handlers are registered as top-level functions.
    • Verify that isLogDropPush, onNewFcmPushToken, and onRemoteMessageReceived are being called.

On this page